Jump to content

WM_PAINT called by which control


Recommended Posts

Herez the code which I want to bring to notice

Func WM_COMMAND($hWnd,$iMsg,$wParam,$lParam)
Local $nNotifyCode = BitShift($wParam, 16)
Local  $nID= BitAND($wParam, 0xFFFF)
Switch $nNotifyCode
  Case 0x100
   GUICtrlSetBKColor($nID,0xFFFFFF)
   If IsDeclared($nID) Then Return
   Assign($nID,True,2)
   GUICtrlSetData($nID,'')
   GUICtrlSetColor(-1,0)
  Case 0x200
   GUICtrlSetBKColor($nID,0xD8D8D8  )
EndSwitch
Return 'GUI_RUNDEFMSG'
EndFunc
Func WM_PAINT($hWnd,$iMsg,$wParam,$lParam)
_WinAPI_RedrawWindow($hGui, 0, 0, $RDW_UPDATENOW)
_DrawLine($hGui,10, $gHeight-25,90,$gHeight-25)
_DrawLine($hGui,10, $gHeight-15,70, $gHeight-15)
_DrawLine($hGui,15, 10,15, $gHeight-10,'800174DF')
_DrawLine($hGui,$gWidth-(($hMargin/2)+$__ExitMargin), 10,$gWidth-(($hMargin/2)+90), 10)
_DrawLine($hGui,$gWidth-(($hMargin/2)+$__ExitMargin), 20,290, 20)
_DrawLine($hGui,$gWidth-(($hMargin/2)+5+$__ExitMargin), 7,$gWidth-(($hMargin/2)+5+$__ExitMargin), $gHeight-10,'800174DF')
_WinAPI_RedrawWindow($hGui, 0, 0, $RDW_VALIDATE)
Return 'GUI_RUNDEFMSG'
EndFunc

When the Edit Receives Focus(found using WM_COMMAND) the Bkcolor of the edit is changed by GuiCtrlSetBkColor (which Triggers WM_PAINT)

Problem : I already have many alpha Lines which are painted in the GUI, so the WM_PAINT upon changing the Edit BkColor also repaints the lines which dont need to be painted again

So is it possible to get the Control which Triggered the WM_PAINT message so that i could exclude the Drawing Line Part at that Time

Herez the full code :

#include <GDIPlus.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Local $GUI[3]=['_GetInput || Phoenix XL',0x80000000,BITOR(0x00000080,0x00000008)]
Local $Input_Text[3][5]=[['Your Password','Password','This Field is Blank',20,0x2000], _
       ['********','New Password','This Field is Blank',20,0x0020], _
       ['********','Confirm New Password','This Field is Blank',20,0x0020]]
Local $sButton[2][2]=[['Blah'], _
       ['Cancel']]
$sArray=_InputBoxEx($GUI,$Input_Text,$sButton)
If Not @extended Then
If Not(GUICtrlRead($sArray[2])==GUICtrlRead($sArray[3])) Then
  GUICtrlSetTip($sArray[3],"Passwords Don't Match",'Error',2,1)
  GUICtrlSetState($sArray[3],256)
  MsgBox(0,"","")
Else
  ConsoleWrite('Password:'&GUICtrlRead($sArray[1])&@CRLF&'New Password:'&GUICtrlRead($sArray[2])&@CRLF&'New Passwordx:'&GUICtrlRead($sArray[3])&@CRLF)
EndIf
EndIf
For $I = 207 To 0 Step -0.02
WinSetTrans($sArray[0], "", $I)
Next
GUIDelete($sArray[0])
;;ConsoleWrite('GUI:'&$sGui&@CRLF)
Func _InputBoxEx($GUI=-1,$sInput_Text=-1,$sButton=-1)
If $sButton=-1 Then
  Local $sx[2][2]=[  ['Okay'], _
        ['Cancel']  ]
  $sButton=$sx
EndIf
If $sInput_Text=-1 Then
  Local $sx[1][5]=[  ['Your Password', _
        'Password', _
        'Please Enter The Password', _
        20, _
        0x0020]   ]
  $sInput_Text=$sx
EndIf
If $GUI=-1 Then
  Local $sx[3]=['InputBoxEx || Phoenix XL',0x80000000,BITOR(0x00000080,0x00000008)]
  $GUI=$sx
EndIf

Global $Notify=0,$__NotifyDone[1]=[0],$__ExitMargin=10,$__Paint=0
Local $sPrevious=Opt('GUIOnEventMode',0),$sReturn[UBound($sInput_Text)+1]
Local $vMargin=20,$__Loop=0
Local $sSpacing=28,$sButton_Height=15,$tRectF
Local $hOffset=0,$sButton_Width=50
For $n=0 To UBound($Input_Text,1)-1
  $hOffset+=$Input_Text[$n][3]
Next
;;ConsoleWrite('Offset:'&$hOffset&@CRLF)
Global $gHeight=$hOffset+((UBound($sInput_Text)-1)*$sSpacing)+(2*$vMargin)+(UBound($sInput_Text)*15)+($sButton_Height),$gWidth=350,$hMargin=30
$hOffset=0
;;ConsoleWrite('Height:'&$gHeight&@CRLF)
Global $hGui= GUICreate($GUI[0], $gWidth, $gHeight, -1, -1  , $GUI[1], $GUI[2]) ;0x80000000 ;BITOR(0x00000080,0x00000008)
Local $sGui=GUISwitch($hGui)

GUISetBkColor(0)

Local $s_Button[UBound($sButton,1)]
For $n=0 To UBound($sButton,1)-1
  ;$s_Button[$n]=_GUICtrlCreateLabel($hGui,$sButton[$n][0],150+$hOffset,$gHeight-30,$sButton_Width,15)
  ;ConsoleWrite($sButton[$n][1]&@CRLF)
  $s_Button[$n]=GUICtrlCreateButton($sButton[$n][0],150+$hOffset,$gHeight-($sButton_Height+$vMargin),$sButton_Width,$sButton_Height,0x0001)
  GUICtrlSetBkColor(-1,0)
  GUICtrlSetColor(-1,0xFFD700)
  $hOffset+=$sButton_Width+10
Next
Local $sInput[UBound($sInput_Text,1)]
Local $sLabel[UBound($sInput_Text,1)]
;For $n=0 To UBound($sInput_Text,1)-1
  ;;ConsoleWrite('n:'&$n&$sInput_Text[0][0]&@CRLF)
  ;$sInput[$n]=GUICtrlCreateEdit($sInput_Text[$n][0],20,30,260,$sInput_Text[$n][2],$sInput_Text[$n][1]);$ES_WANTRETURN+$ES_MULTILINE+$WS_VSCROLL+$WS_HSCROLL
  ;$sLabel[$n]=_GUICtrlCreateLabel($hGui,$sInput_Text[$n][3],20,10,-1,15)
;Next
$hOffset=0
For $n=0 To UBound($sInput_Text,1)-1
  $sLabel[$n]=_GUICtrlCreateLabel($hGui,$sInput_Text[$n][1],$hMargin,$vMargin+$hOffset,-1,15,2)
  $sInput[$n]=GUICtrlCreateEdit($sInput_Text[$n][0],$hMargin,$vMargin+$hOffset+17,$gWidth-((2*$hMargin)+$__ExitMargin),$sInput_Text[$n][3],$sInput_Text[$n][4])
  GUICtrlSetBkColor(-1,0xE8E8E8)
  GUICtrlSetColor(-1,0x484848  )
  $hOffset+=$sInput_Text[$n][3]+$sSpacing
Next
Local $fExit=_GUICtrlCreateLabel($hGui,'X',$gWidth-15,9,15,15,0,0xFA8258)
;;ConsoleWrite('X:'&$sPos[0]&@TAB&'Y:'&$sPos[1]&@TAB&'Width:'&$sPos[2]&@TAB&'Height:'&$sPos[3]&@CRLF)
;_ScrollBar_Create($hGui,$sInput)
WinSetTrans($hGui, "", 0)
GUISetBkColor(0)
GUIRegisterMsg(0x0111,'WM_COMMAND')
GUIRegisterMsg(0x0100,'WM_KEYDOWN')
GUIRegisterMsg(0x000F,'WM_PAINT')
GUISetState(@SW_SHOW, $hGui)
GUISetState(@SW_MINIMIZE,$hGui)
GUICtrlCreatePic('',0,0,350,$gHeight,-1,0x00100000)
For $I = 0 To 207 Step 0.02
  WinSetTrans($hGui, "", $I)
Next
Local $sMsg
While $sMsg<>-3
  $sMsg=GUIGetMsg()
   Switch $sMsg
    Case $s_Button[0]
     For $n=0 To UBound($sInput)-1
      Switch GUICtrlRead($sInput[$n])
       Case '',$sInput_Text[$n][2],$sInput_Text[$n][0]
        Local $asSize = CalcRectangle($sInput_Text[$n][2])
        ;ConsoleWrite($asSize[0]&'-'& $asSize[1]&@CRLF)
        ControlMove($hGui, "", $sLabel[$n], Default, Default, $asSize[0], $asSize[1])
        GUICtrlSetData($sLabel[$n],$sInput_Text[$n][2])
        GUICtrlSetData($sInput[$n],'')
        GUICtrlSetState($sLabel[$n],256)
        ExitLoop
       Case Else
        If $n==UBound($sInput)-1 Then
         For $i=0 To UBound($sInput)-1
          $sReturn[$i+1]=$sInput[$i]
         Next
         ExitLoop 2
        EndIf
      EndSwitch
     Next
    Case $s_Button[1],$fExit
     $sReturn[0]=$hGui
     SetExtended(1)
     ExitLoop
   EndSwitch
  If $Notify<>0 Then
   For $_=1 To $__NotifyDone[0]
    If $__NotifyDone[$_]<>$Notify Then ContinueLoop
    GUICtrlSetData($Notify,'')
    GUICtrlSetState($Notify,256)
    $__NotifyDone[0]+=1
    ReDim $__NotifyDone[$__NotifyDone[0]+1]
    $__NotifyDone[$__NotifyDone[0]]=$Notify
   Next
  EndIf
WEnd
;For $I = 207 To 0 Step -0.02
; WinSetTrans($hGui, "", $I)
;Next
;ConsoleWrite('GUI:'&$hGui&@CRLF)
Opt('GUIOnEventMode',$sPrevious)
GUISwitch($sGui)
If IsArray($sReturn) Then $sReturn[0]=$hGui
Return SetError(0,@extended,$sReturn)
EndFunc
Func WM_COMMAND($hWnd,$iMsg,$wParam,$lParam)
Local $nNotifyCode = BitShift($wParam, 16)
Local  $nID= BitAND($wParam, 0xFFFF)
Switch $nNotifyCode
  Case 0x100
   GUICtrlSetBKColor($nID,0xFFFFFF)
   If IsDeclared($nID) Then Return
   Assign($nID,True,2)
   GUICtrlSetData($nID,'')
   GUICtrlSetColor(-1,0)
  Case 0x200
   GUICtrlSetBKColor($nID,0xD8D8D8  )
EndSwitch
Return 'GUI_RUNDEFMSG'
EndFunc
Func WM_PAINT($hWnd,$iMsg,$wParam,$lParam)
_WinAPI_RedrawWindow($hGui, 0, 0, $RDW_UPDATENOW)
_DrawLine($hGui,10, $gHeight-25,90,$gHeight-25)
_DrawLine($hGui,10, $gHeight-15,70, $gHeight-15)
_DrawLine($hGui,15, 10,15, $gHeight-10,'800174DF')
_DrawLine($hGui,$gWidth-(($hMargin/2)+$__ExitMargin), 10,$gWidth-(($hMargin/2)+90), 10)
_DrawLine($hGui,$gWidth-(($hMargin/2)+$__ExitMargin), 20,290, 20)
_DrawLine($hGui,$gWidth-(($hMargin/2)+5+$__ExitMargin), 7,$gWidth-(($hMargin/2)+5+$__ExitMargin), $gHeight-10,'800174DF')
_WinAPI_RedrawWindow($hGui, 0, 0, $RDW_VALIDATE)
Return 'GUI_RUNDEFMSG'
EndFunc
Func WM_KEYDOWN($hWnd,$iMsg,$wParam,$lParam)
Switch $wParam
  Case 0x0D
   Assign('Enter_Pressed',True,2)
EndSwitch
Return 'GUI_RUNDEFMSG'
EndFunc
Func _GuiCtrlCreateLabel($sHwnd,$sText,$sLeft,$sTop,$sWidth,$sHeight,$sCursor=0,$sColor=0xFFD700,$sBkColor=-2,$sStyle=-1,$sExStyle=-1)
Local $sPrevious=GUISwitch($sHwnd)
Local $sLabel=GUICtrlCreateLabel($sText,$sLeft,$sTop,$sWidth,$sHeight,$sStyle,$sExStyle)
GUICtrlSetBkColor(-1,$sBkColor)
GUICtrlSetColor(-1,$sColor)
GUICtrlSetCursor(-1,$sCursor)
GUISwitch($sPrevious)
Return $sLabel
EndFunc
Func CalcRectangle($sString, $sFont='Arial',$fFontsize=8.5)
_GDIPlus_Startup()
    Local $aResult, $hFont, $i=0 ,$iLen = StringLen($sString),$tLayout
    Local $hGfx = _GDIPlus_GraphicsCreateFromHWND(WinGetHandle(AutoItWinGetTitle()))
    Local $tRectF = DllStructCreate($tagGDIPRECTF)
    Local $hFormat = _GDIPlus_StringFormatCreate()
    Local $hFont = _GDIPlus_FontCreate( _GDIPlus_FontFamilyCreate($sFont), $fFontsize, 0)
    Do
  $tLayout = _GDIPlus_RectFCreate(0, 0, $i, 0)
        $aResult = DllCall($ghGDIPDll, "int", "GdipMeasureString", _
            "handle", $hGfx, _
            "wstr", $sString, _
            "int", $iLen, _
            "handle", $hFont, _
            "struct*", $tLayout, _
            "handle", $hFormat, _
            "struct*", $tRectF, _
            "int*", 0, _
            "int*", 0)
  If $aResult[8] >=  $iLen Then ExitLoop
        $i += 1
    Until False
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_GraphicsDispose($hGfx)
    $tLayout  = 0
Local $sReturn[2]=[DllStructGetData($aResult[7],'Width'),DllStructGetData($aResult[7],'Height')]
_GDIPlus_Shutdown()
    Return $sReturn
EndFunc
Func _DrawLine($Gui,$x1,$y1,$x2,$y2,$sChannel='80FFD700')
Local  $hGraphic, $hPen
; Draw line
_GDIPlus_Startup ()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($Gui)
$hPen = _GDIPlus_PenCreate ('0x'&$sChannel)
If Not _GDIPlus_GraphicsDrawLine ($hGraphic, $x1,$y1,$x2,$y2, $hPen) Then ConsoleWrite('Error from GDI+:'&@error&@CRLF)
; Clean up resources
_GDIPlus_PenDispose ($hPen)
_GDIPlus_GraphicsDispose ($hGraphic)
_GDIPlus_ShutDown ()
;Done.....
EndFunc   ;==>_Main
Func _MakeLong($iLo, $iHi)
Return BitOR(BitShift($iHi, -16), BitAND($iLo, 0xFFFF))
EndFunc   ;==>_WinAPI_MakeLong

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...