wolf9228 Posted May 22, 2010 Share Posted May 22, 2010 ButtonHover.zip Static_ButtonHover.au3 expandcollapse popup#Include <WinAPI.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <Constants.au3> Global $CtrlhWnd_Array[1][6] , $TEST_WM_MOUSEFIRST = 0 , $HoverProcPtr = 0 , $HoverRegister = "" Global $HOVER_HWND = 0 , $hHook_HOVER , $TEST_WM_LBUTTONDOWN = 0 OnAutoItExitRegister("Cleanup") Func CreateButtonHover($Text,$L,$T,$W,$H,$NORMAL_hBMP,$PRESS_hBMP,$OVER_hBMP,$TEXTCOLOOR = 0) Local $STM_SETIMAGE_HOVER = 0x0172 , $SS_BITMAP_HOVER = 0x0000000E _ , $SS_REALSIZECONTROL_HOVER = 0x00000040 , $iPID_HOVER = 0 , $hmod = _WinAPI_GetModuleHandle(0) $controlID1 = GUICtrlCreateLabel("",$L,$T,$W,$H,$SS_REALSIZECONTROL_HOVER + $SS_BITMAP_HOVER) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) $hWnd1 = GUICtrlGetHandle($controlID1) $CtrlhWnd_Array[UBound($CtrlhWnd_Array) - 1][0] = $hWnd1 $user = GUICtrlCreateDummy() $controlID2 = GUICtrlCreateLabel($Text,$L,$T,$W,$H, $SS_CENTERIMAGE + $SS_NOTIFY + $SS_CENTER) if ($TEXTCOLOOR) Then GUICtrlSetColor(-1,$TEXTCOLOOR) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) $hWnd2 = GUICtrlGetHandle($controlID2) $CtrlhWnd_Array[UBound($CtrlhWnd_Array) - 1][1] = $hWnd2 $CtrlhWnd_Array[UBound($CtrlhWnd_Array) - 1][2] = $user if Not ($HoverProcPtr) Then $HoverRegister = DllCallbackRegister("ButtonHoverProc", "long", "int;wparam;lparam") $HoverProcPtr = DllCallbackGetPtr($HoverRegister) $hHook_HOVER = _WinAPI_SetWindowsHookEx($WH_MOUSE ,$HoverProcPtr, $hmod , _ _WinAPI_GetWindowThreadProcessId(_WinAPI_GetParent($hWnd1),$iPID_HOVER)) EndIf _SendMessage($hWnd1,$STM_SETIMAGE_HOVER,0,$NORMAL_hBMP) $CtrlhWnd_Array[UBound($CtrlhWnd_Array) - 1][3] = $NORMAL_hBMP $CtrlhWnd_Array[UBound($CtrlhWnd_Array) - 1][4] = $PRESS_hBMP $CtrlhWnd_Array[UBound($CtrlhWnd_Array) - 1][5] = $OVER_hBMP ReDim $CtrlhWnd_Array[UBound($CtrlhWnd_Array) + 1][6] Return SetError (0, $controlID2,$user) EndFunc Func ArraySearch($hWnd) For $Element = 0 To UBound($CtrlhWnd_Array) - 1 if $CtrlhWnd_Array[$Element][0] == $hWnd Then Return $Element Next Return -1 EndFunc Func ButtonHoverDelete($controlID) Local $Temp_Array[1][6] , $Test = False For $Element = 0 To UBound($CtrlhWnd_Array) - 1 if $CtrlhWnd_Array[$Element][2] == $controlID Then GUICtrlDelete(_WinAPI_GetDlgCtrlID($CtrlhWnd_Array[$Element][0])) GUICtrlDelete(_WinAPI_GetDlgCtrlID($CtrlhWnd_Array[$Element][1])) GUICtrlDelete($CtrlhWnd_Array[$Element][2]) $Test = True Else $Temp_Array[UBound($Temp_Array) - 1][0] = $CtrlhWnd_Array[$Element][0] $Temp_Array[UBound($Temp_Array) - 1][1] = $CtrlhWnd_Array[$Element][1] $Temp_Array[UBound($Temp_Array) - 1][2] = $CtrlhWnd_Array[$Element][2] $Temp_Array[UBound($Temp_Array) - 1][3] = $CtrlhWnd_Array[$Element][3] $Temp_Array[UBound($Temp_Array) - 1][4] = $CtrlhWnd_Array[$Element][4] $Temp_Array[UBound($Temp_Array) - 1][5] = $CtrlhWnd_Array[$Element][5] ReDim $Temp_Array[UBound($Temp_Array) + 1][6] EndIf Next ReDim $Temp_Array[UBound($Temp_Array) - 1][6] $CtrlhWnd_Array = $Temp_Array Return $Test EndFunc Func ButtonHoverProc($nCode, $wParam, $lParam) If $nCode < 0 Then _ Return _WinAPI_CallNextHookEx($hHook_HOVER, $nCode, $wParam, $lParam) Local _ $WM_MOUSEFIRST_HOVER = 0x0200 , _ $WM_LBUTTONDOWN_HOVER = 0x0201 , _ $WM_LBUTTONUP_HOVER = 0x0202 , _ $STM_SETIMAGE_HOVER = 0x0172 , _ $Tag_struct ="LONG x;LONG y;HWND hwnd;UINT wHitTestCode;ULONG_PTR dwExtraInfo" $MOUSEHOOKSTRUCT = DllStructCreate($Tag_struct,$lParam) $hWnd = DllStructGetData($MOUSEHOOKSTRUCT,3) $uiMsg = $wParam $Element = ArraySearch($hWnd) If $Element <> -1 Then $hWnd1 = $CtrlhWnd_Array[$Element][0] $hWnd2 = $CtrlhWnd_Array[$Element][1] If $uiMsg = $WM_MOUSEFIRST_HOVER And $TEST_WM_MOUSEFIRST = 0 Then $HOVER_HWND = $hWnd1 _SendMessage($hWnd1,$STM_SETIMAGE_HOVER,0,$CtrlhWnd_Array[$Element][5]) _WinAPI_RedrawWindow($hWnd2,0,0, $RDW_INVALIDATE ) $TEST_WM_MOUSEFIRST = 1 Else If $HOVER_HWND = $hWnd1 Then Select Case $uiMsg = $WM_LBUTTONDOWN_HOVER And $TEST_WM_LBUTTONDOWN = 0 _SendMessage($hWnd1,$STM_SETIMAGE_HOVER,0,$CtrlhWnd_Array[$Element][4]) _WinAPI_RedrawWindow($hWnd2,0,0, $RDW_INVALIDATE ) $TEST_WM_LBUTTONDOWN = 1 Case $uiMsg = $WM_LBUTTONUP_HOVER And $TEST_WM_LBUTTONDOWN = 1 _SendMessage($hWnd1,$STM_SETIMAGE_HOVER,0,$CtrlhWnd_Array[$Element][5]) _WinAPI_RedrawWindow($hWnd2,0,0, $RDW_INVALIDATE ) GUICtrlSendToDummy($CtrlhWnd_Array[$Element][2]) $TEST_WM_LBUTTONDOWN = 0 EndSelect Else If $uiMsg = $WM_LBUTTONUP_HOVER And $TEST_WM_LBUTTONDOWN = 1 Then $Element = ArraySearch($HOVER_HWND) $hWnd1 = $CtrlhWnd_Array[$Element][0] $hWnd2 = $CtrlhWnd_Array[$Element][1] _SendMessage($hWnd1,$STM_SETIMAGE_HOVER,0,$CtrlhWnd_Array[$Element][3]) _WinAPI_RedrawWindow($hWnd2,0,0, $RDW_INVALIDATE ) $TEST_WM_LBUTTONDOWN = 0 $Element = ArraySearch($hWnd) $hWnd1 = $CtrlhWnd_Array[$Element][0] $hWnd2 = $CtrlhWnd_Array[$Element][1] $HOVER_HWND = $hWnd1 _SendMessage($hWnd1,$STM_SETIMAGE_HOVER,0,$CtrlhWnd_Array[$Element][5]) _WinAPI_RedrawWindow($hWnd2,0,0, $RDW_INVALIDATE ) $TEST_WM_MOUSEFIRST = 1 EndIf EndIf EndIf Else If $TEST_WM_LBUTTONDOWN = 1 Then If $uiMsg = $WM_LBUTTONUP_HOVER Then $Element = ArraySearch($HOVER_HWND) $hWnd1 = $CtrlhWnd_Array[$Element][0] $hWnd2 = $CtrlhWnd_Array[$Element][1] _SendMessage($hWnd1,$STM_SETIMAGE_HOVER,0,$CtrlhWnd_Array[$Element][3]) _WinAPI_RedrawWindow($hWnd2,0,0, $RDW_INVALIDATE ) $TEST_WM_LBUTTONDOWN = 0 EndIf Else If $TEST_WM_MOUSEFIRST = 1 Then $Element = ArraySearch($HOVER_HWND) $hWnd1 = $CtrlhWnd_Array[$Element][0] $hWnd2 = $CtrlhWnd_Array[$Element][1] _SendMessage($hWnd1,$STM_SETIMAGE_HOVER,0,$CtrlhWnd_Array[$Element][3]) _WinAPI_RedrawWindow($hWnd2,0,0, $RDW_INVALIDATE ) $TEST_WM_MOUSEFIRST = 0 EndIf EndIf EndIf Return _WinAPI_CallNextHookEx($hHook_HOVER, $nCode, $wParam, $lParam) EndFunc Func LoadBitmap_FromFile($sFileName) Return _WinAPI_LoadImage(_WinAPI_GetModuleHandle(0),$sFileName,0 ,0,0,0x0010) EndFunc Func LoadBitmap_FromResources($resource_Name) Return _WinAPI_LoadBitmap(_WinAPI_GetModuleHandle(0), $resource_Name) EndFunc Func GetBmpWidth($hBMP) $tagBITMAPINFO_HOVER = "DWORD biSize;LONG biWidth;LONG biHeight;USHORT biPlanes;" & _ "USHORT biBitCount;DWORD biCompression;DWORD biSizeImage;LONG biXPelsPerMeter;" & _ "LONG biYPelsPerMeter;DWORD biClrUsed;DWORD biClrImportant;BYTE rgbBlueElement1;" & _ "BYTE rgbGreenElement1;BYTE rgbRedElement1;BYTE rgbReservedElement1" $BITMAPINFO = DllStructCreate($tagBITMAPINFO_HOVER) DllStructSetData($BITMAPINFO,"biSize",DllStructGetSize($BITMAPINFO)) $hDC = _WinAPI_CreateCompatibleDC(0) _WinAPI_GetDIBits($hDC,$hBmp,0,0,0,DllStructGetPtr($BITMAPINFO),0) Return DllStructGetData($BITMAPINFO,"biWidth") EndFunc Func GetBmpHeight($hBMP) $tagBITMAPINFO_HOVER = "DWORD biSize;LONG biWidth;LONG biHeight;USHORT biPlanes;" & _ "USHORT biBitCount;DWORD biCompression;DWORD biSizeImage;LONG biXPelsPerMeter;" & _ "LONG biYPelsPerMeter;DWORD biClrUsed;DWORD biClrImportant;BYTE rgbBlueElement1;" & _ "BYTE rgbGreenElement1;BYTE rgbRedElement1;BYTE rgbReservedElement1" $BITMAPINFO = DllStructCreate($tagBITMAPINFO_HOVER) DllStructSetData($BITMAPINFO,"biSize",DllStructGetSize($BITMAPINFO)) $hDC = _WinAPI_CreateCompatibleDC(0) _WinAPI_GetDIBits($hDC,$hBmp,0,0,0,DllStructGetPtr($BITMAPINFO),0) Return DllStructGetData($BITMAPINFO,"biHeight") EndFunc Func Cleanup() _WinAPI_UnhookWindowsHookEx($hHook_HOVER) DllCallbackFree($HoverRegister) EndFunc Static_Example.au3 #include <Static_ButtonHover.au3> $NORMAL_hBMP = LoadBitmap_FromFile("NORMAL1.bmp") $PRESS_hBMP = LoadBitmap_FromFile("PRESS1.bmp") $OVER_hBMP = LoadBitmap_FromFile("OVER1.bmp") $TEXTCOLOOR = 0xFFFFFF $GUI = GUICreate("Static_ButtonHover") $Button_SM = CreateButtonHover ("Small", 180, 80, 70, 15,$NORMAL_hBMP,$PRESS_hBMP,$OVER_hBMP,$TEXTCOLOOR) GUICtrlSetFont(@extended, 8, 800, 0, "Arial") ; @extended oR -1 $Button_ME = CreateButtonHover ("Medium", 180, 120, 90, 30,$NORMAL_hBMP,$PRESS_hBMP,$OVER_hBMP,$TEXTCOLOOR) GUICtrlSetFont(-1, 12, 800, 0, "Arial") ; @extended oR -1 $Button_LO = CreateButtonHover ("Long", 180, 180, 190, 30,$NORMAL_hBMP,$PRESS_hBMP,$OVER_hBMP,$TEXTCOLOOR) GUICtrlSetFont(@extended, 16, 800, 0, "Arial") ; @extended oR -1 $Button_LA = CreateButtonHover ("Large", 180, 240, 190, 60, $NORMAL_hBMP,$PRESS_hBMP,$OVER_hBMP,$TEXTCOLOOR) GUICtrlSetFont(-1, 20, 800, 0, "Arial") ; @extended oR -1 GUISetState(@SW_SHOW) While 1 $MSG = GUIGetMsg() Switch $MSG Case $GUI_EVENT_CLOSE Exit Case $Button_SM MsgBox(0,"MSG","Small Button") Case $Button_ME MsgBox(0,"MSG","Medium Button") Case $Button_LO MsgBox(0,"MSG","Long Button") Case $Button_LA MsgBox(0,"MSG","Large Button") EndSwitch WEnd Button_ButtonHover.au3 expandcollapse popup#Include <WinAPI.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <Constants.au3> Global $CtrlhWnd_Array[1][4] , $HoverProcPtr = 0 , $HoverRegister = "" , $hHook_HOVER OnAutoItExitRegister("Cleanup") Func CreateButtonHover($L,$T,$W,$H,$NORMAL_hBMP,$PRESS_hBMP,$OVER_hBMP,$style = 0,$exStyle = 0) Local $BM_SETIMAGE_HOVER = 0x00F7 , $BS_BITMAP_HOVER = 0x00000080, $BS_ICON_HOVER = 0x00000040 , _ $iPID_HOVER = 0 , $hmod = _WinAPI_GetModuleHandle(0) $controlID = GUICtrlCreateButton("",$L,$T,$W,$H,$style,$exStyle) $hWnd = GUICtrlGetHandle($controlID) $CtrlhWnd_Array[UBound($CtrlhWnd_Array) - 1][0] = $hWnd if Not ($HoverProcPtr) Then $HoverRegister = DllCallbackRegister("ButtonHoverProc", "long", "int;wparam;lparam") $HoverProcPtr = DllCallbackGetPtr($HoverRegister) $hHook_HOVER = _WinAPI_SetWindowsHookEx($WH_GETMESSAGE ,$HoverProcPtr, $hmod , _ _WinAPI_GetWindowThreadProcessId(_WinAPI_GetParent($hWnd),$iPID_HOVER)) EndIf if Not BitAND(_WinAPI_GetWindowLong($hWnd, $GWL_STYLE), $BS_BITMAP_HOVER ) = $BS_BITMAP_HOVER Then _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, _WinAPI_GetWindowLong($hWnd, $GWL_STYLE) + $BS_BITMAP_HOVER ) ElseIf BitAND(_WinAPI_GetWindowLong($hWnd, $GWL_STYLE), $BS_ICON_HOVER ) = $BS_ICON_HOVER Then _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, _WinAPI_GetWindowLong($hWnd, $GWL_STYLE) - $BS_ICON_HOVER ) EndIf _SendMessage($hWnd,$BM_SETIMAGE_HOVER,0,$NORMAL_hBMP) $CtrlhWnd_Array[UBound($CtrlhWnd_Array) - 1][1] = $NORMAL_hBMP $CtrlhWnd_Array[UBound($CtrlhWnd_Array) - 1][2] = $PRESS_hBMP $CtrlhWnd_Array[UBound($CtrlhWnd_Array) - 1][3] = $OVER_hBMP ReDim $CtrlhWnd_Array[UBound($CtrlhWnd_Array) + 1][4] Return $controlID EndFunc Func ArraySearch($hWnd) For $Element = 0 To UBound($CtrlhWnd_Array) - 1 if $CtrlhWnd_Array[$Element][0] == $hWnd Then Return $Element Next Return -1 EndFunc Func ButtonHoverDelete($controlID) Local $Temp_Array[1][4] , $Test = False For $Element = 0 To UBound($CtrlhWnd_Array) - 1 if $CtrlhWnd_Array[$Element][0] == GUICtrlGetHandle($controlID) Then GUICtrlDelete($controlID) $Test = True Else $Temp_Array[UBound($Temp_Array) - 1][0] = $CtrlhWnd_Array[$Element][0] $Temp_Array[UBound($Temp_Array) - 1][1] = $CtrlhWnd_Array[$Element][1] $Temp_Array[UBound($Temp_Array) - 1][2] = $CtrlhWnd_Array[$Element][2] $Temp_Array[UBound($Temp_Array) - 1][3] = $CtrlhWnd_Array[$Element][3] ReDim $Temp_Array[UBound($Temp_Array) + 1][4] EndIf Next ReDim $Temp_Array[UBound($Temp_Array) - 1][4] $CtrlhWnd_Array = $Temp_Array Return $Test EndFunc Func ButtonHoverProc($nCode, $wParam, $lParam) If $nCode < 0 Then _ Return _WinAPI_CallNextHookEx($hHook_HOVER, $nCode, $wParam, $lParam) Local _ $WM_MOUSEFIRST_HOVER = 0x0200 , _ $WM_MOUSELEAVE_HOVER = 0x02A3 , _ $WM_LBUTTONDOWN_HOVER = 0x0201 , _ $WM_LBUTTONUP_HOVER = 0x0202 , _ $BM_SETIMAGE_HOVER = 0x00F7 $Tag_struct ="HWND hwnd;UINT message;WPARAM wParam;LPARAM lParam;" & _ "DWORD time;LONG y;LONG x" $MSG = DllStructCreate($Tag_struct,$lParam) $hWnd = DllStructGetData($MSG,1) $uiMsg = DllStructGetData($MSG,2) $Element = ArraySearch($hWnd) if $Element <> -1 Then Select Case $uiMsg = $WM_MOUSEFIRST_HOVER _SendMessage($hWnd,$BM_SETIMAGE_HOVER,0,$CtrlhWnd_Array[$Element][3]) Case $uiMsg = $WM_MOUSELEAVE_HOVER _SendMessage($hWnd,$BM_SETIMAGE_HOVER,0,$CtrlhWnd_Array[$Element][1]) Case $uiMsg = $WM_LBUTTONDOWN_HOVER _SendMessage($hWnd,$BM_SETIMAGE_HOVER,0,$CtrlhWnd_Array[$Element][2]) Case $uiMsg = $WM_LBUTTONUP_HOVER _SendMessage($hWnd,$BM_SETIMAGE_HOVER,0,$CtrlhWnd_Array[$Element][3]) EndSelect EndIf Return _WinAPI_CallNextHookEx($hHook_HOVER, $nCode, $wParam, $lParam) EndFunc Func LoadBitmap_FromFile($sFileName) Return _WinAPI_LoadImage(_WinAPI_GetModuleHandle(0),$sFileName,0 ,0,0,0x0010) EndFunc Func LoadBitmap_FromResources($resource_Name) Return _WinAPI_LoadBitmap(_WinAPI_GetModuleHandle(0), $resource_Name) EndFunc Func GetBmpWidth($hBMP) $tagBITMAPINFO_HOVER = "DWORD biSize;LONG biWidth;LONG biHeight;USHORT biPlanes;" & _ "USHORT biBitCount;DWORD biCompression;DWORD biSizeImage;LONG biXPelsPerMeter;" & _ "LONG biYPelsPerMeter;DWORD biClrUsed;DWORD biClrImportant;BYTE rgbBlueElement1;" & _ "BYTE rgbGreenElement1;BYTE rgbRedElement1;BYTE rgbReservedElement1" $BITMAPINFO = DllStructCreate($tagBITMAPINFO_HOVER) DllStructSetData($BITMAPINFO,"biSize",DllStructGetSize($BITMAPINFO)) $hDC = _WinAPI_CreateCompatibleDC(0) _WinAPI_GetDIBits($hDC,$hBmp,0,0,0,DllStructGetPtr($BITMAPINFO),0) Return DllStructGetData($BITMAPINFO,"biWidth") EndFunc Func GetBmpHeight($hBMP) $tagBITMAPINFO_HOVER = "DWORD biSize;LONG biWidth;LONG biHeight;USHORT biPlanes;" & _ "USHORT biBitCount;DWORD biCompression;DWORD biSizeImage;LONG biXPelsPerMeter;" & _ "LONG biYPelsPerMeter;DWORD biClrUsed;DWORD biClrImportant;BYTE rgbBlueElement1;" & _ "BYTE rgbGreenElement1;BYTE rgbRedElement1;BYTE rgbReservedElement1" $BITMAPINFO = DllStructCreate($tagBITMAPINFO_HOVER) DllStructSetData($BITMAPINFO,"biSize",DllStructGetSize($BITMAPINFO)) $hDC = _WinAPI_CreateCompatibleDC(0) _WinAPI_GetDIBits($hDC,$hBmp,0,0,0,DllStructGetPtr($BITMAPINFO),0) Return DllStructGetData($BITMAPINFO,"biHeight") EndFunc Func Cleanup() _WinAPI_UnhookWindowsHookEx($hHook_HOVER) DllCallbackFree($HoverRegister) EndFunc ButtonHover_Example.au3 expandcollapse popup#include <Button_ButtonHover.au3> $GUI = GUICreate("Button_ButtonHover") $NORMAL_hBMP = LoadBitmap_FromFile("NORMAL1.bmp") $PRESS_hBMP = LoadBitmap_FromFile("PRESS1.bmp") $OVER_hBMP = LoadBitmap_FromFile("OVER1.bmp") $Width = GetBmpWidth($NORMAL_hBMP) $Height = GetBmpHeight($NORMAL_hBMP) $Button1 = CreateButtonHover (160,50,$Width,$Height,$NORMAL_hBMP,$PRESS_hBMP,$OVER_hBMP) $NORMAL_hBMP = LoadBitmap_FromFile("NORMAL2.bmp") $PRESS_hBMP = LoadBitmap_FromFile("PRESS2.bmp") $OVER_hBMP = LoadBitmap_FromFile("OVER2.bmp") $Width = GetBmpWidth($NORMAL_hBMP) $Height = GetBmpHeight($NORMAL_hBMP) $Button2 = CreateButtonHover (160,120,$Width,$Height,$NORMAL_hBMP,$PRESS_hBMP,$OVER_hBMP) $NORMAL_hBMP = LoadBitmap_FromFile("NORMAL3.bmp") $PRESS_hBMP = LoadBitmap_FromFile("PRESS3.bmp") $OVER_hBMP = LoadBitmap_FromFile("OVER3.bmp") $Width = GetBmpWidth($NORMAL_hBMP) $Height = GetBmpHeight($NORMAL_hBMP) $Button3 = CreateButtonHover (160,180,$Width,$Height,$NORMAL_hBMP,$PRESS_hBMP,$OVER_hBMP) $NORMAL_hBMP = LoadBitmap_FromFile("NORMAL4.bmp") $PRESS_hBMP = LoadBitmap_FromFile("PRESS4.bmp") $OVER_hBMP = LoadBitmap_FromFile("OVER4.bmp") $Width = GetBmpWidth($NORMAL_hBMP) $Height = GetBmpHeight($NORMAL_hBMP) $Button4 = CreateButtonHover (160,240,$Width,$Height,$NORMAL_hBMP,$PRESS_hBMP,$OVER_hBMP) GUISetState(@SW_SHOW) While 1 $MSG = GUIGetMsg() Switch $MSG Case $GUI_EVENT_CLOSE Exit Case $Button1 MsgBox(0,"MSG","Button1") Case $Button2 MsgBox(0,"MSG","Button2") Case $Button3 MsgBox(0,"MSG","Button3") Case $Button4 MsgBox(0,"MSG","Button4") EndSwitch WEnd ØµØ±Ø Ø§Ù„Ø³Ù…Ø§Ø¡ كان هنا  Link to comment Share on other sites More sharing options...
MrCreatoR Posted May 22, 2010 Share Posted May 22, 2010 (edited) ButtonHover_Example.au3Nice, but here is the same example using my GUICtrlOnHover.au3: expandcollapse popup#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include "GUICtrlOnHover.au3" $GUI = GUICreate("Button_ButtonHover") $Button1 = GUICtrlCreateButton("", 160, 50, 77, 30, BitOR($GUI_SS_DEFAULT_BUTTON, $BS_BITMAP)) $Button2 = GUICtrlCreateButton("", 160, 120, 76, 30, BitOR($GUI_SS_DEFAULT_BUTTON, $BS_BITMAP)) $Button3 = GUICtrlCreateButton("", 160, 180, 76, 30, BitOR($GUI_SS_DEFAULT_BUTTON, $BS_BITMAP)) $Button4 = GUICtrlCreateButton("", 160, 240, 77, 31, BitOR($GUI_SS_DEFAULT_BUTTON, $BS_BITMAP)) GUICtrlSetImage($Button1, "NORMAL1.bmp") GUICtrlSetImage($Button2, "NORMAL2.bmp") GUICtrlSetImage($Button3, "NORMAL3.bmp") GUICtrlSetImage($Button4, "NORMAL4.bmp") _GUICtrl_OnHoverRegister($Button1, "_Button_Hover", "_Button_Hover", "_Button_Click", "_Button_Click") _GUICtrl_OnHoverRegister($Button2, "_Button_Hover", "_Button_Hover", "_Button_Click", "_Button_Click") _GUICtrl_OnHoverRegister($Button3, "_Button_Hover", "_Button_Hover", "_Button_Click", "_Button_Click") _GUICtrl_OnHoverRegister($Button4, "_Button_Hover", "_Button_Hover", "_Button_Click", "_Button_Click") GUISetState(@SW_SHOW) While 1 $MSG = GUIGetMsg() Switch $MSG Case $GUI_EVENT_CLOSE Exit Case $Button1 MsgBox(0, "MSG", "Button1") Case $Button2 MsgBox(0, "MSG", "Button2") Case $Button3 MsgBox(0, "MSG", "Button3") Case $Button4 MsgBox(0, "MSG", "Button4") EndSwitch WEnd Func _Button_Hover($iCtrlID, $iHoverMode) Local $sImageName = "OVER" Local $sImageIndex = "1" Switch $iHoverMode Case 1 ;Hover $sImageName = "OVER" Case 2 ;Leave hover $sImageName = "NORMAL" EndSwitch Switch $iCtrlID Case $Button1 $sImageIndex = "1" Case $Button2 $sImageIndex = "2" Case $Button3 $sImageIndex = "3" Case $Button4 $sImageIndex = "4" EndSwitch GUICtrlSetImage($iCtrlID, $sImageName & $sImageIndex & ".bmp") EndFunc Func _Button_Click($iCtrlID, $iClickMode) Local $sImageName = "PRESS" Local $sImageIndex = "1" Switch $iClickMode Case 1 ;Hover $sImageName = "PRESS" Case 2 ;Leave hover $sImageName = "OVER" EndSwitch Switch $iCtrlID Case $Button1 $sImageIndex = "1" Case $Button2 $sImageIndex = "2" Case $Button3 $sImageIndex = "3" Case $Button4 $sImageIndex = "4" EndSwitch GUICtrlSetImage($iCtrlID, $sImageName & $sImageIndex & ".bmp") EndFunc Edited May 22, 2010 by MrCreatoR  Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1  AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ==================================================    AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
Yashied Posted May 22, 2010 Share Posted May 22, 2010 Using the hook seems to me redundant. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
wolf9228 Posted May 23, 2010 Author Share Posted May 23, 2010 (edited) Nice, but here is the same example using my GUICtrlOnHover.au3: expandcollapse popup#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include "GUICtrlOnHover.au3" $GUI = GUICreate("Button_ButtonHover") $Button1 = GUICtrlCreateButton("", 160, 50, 77, 30, BitOR($GUI_SS_DEFAULT_BUTTON, $BS_BITMAP)) $Button2 = GUICtrlCreateButton("", 160, 120, 76, 30, BitOR($GUI_SS_DEFAULT_BUTTON, $BS_BITMAP)) $Button3 = GUICtrlCreateButton("", 160, 180, 76, 30, BitOR($GUI_SS_DEFAULT_BUTTON, $BS_BITMAP)) $Button4 = GUICtrlCreateButton("", 160, 240, 77, 31, BitOR($GUI_SS_DEFAULT_BUTTON, $BS_BITMAP)) GUICtrlSetImage($Button1, "NORMAL1.bmp") GUICtrlSetImage($Button2, "NORMAL2.bmp") GUICtrlSetImage($Button3, "NORMAL3.bmp") GUICtrlSetImage($Button4, "NORMAL4.bmp") _GUICtrl_OnHoverRegister($Button1, "_Button_Hover", "_Button_Hover", "_Button_Click", "_Button_Click") _GUICtrl_OnHoverRegister($Button2, "_Button_Hover", "_Button_Hover", "_Button_Click", "_Button_Click") _GUICtrl_OnHoverRegister($Button3, "_Button_Hover", "_Button_Hover", "_Button_Click", "_Button_Click") _GUICtrl_OnHoverRegister($Button4, "_Button_Hover", "_Button_Hover", "_Button_Click", "_Button_Click") GUISetState(@SW_SHOW) While 1 $MSG = GUIGetMsg() Switch $MSG Case $GUI_EVENT_CLOSE Exit Case $Button1 MsgBox(0, "MSG", "Button1") Case $Button2 MsgBox(0, "MSG", "Button2") Case $Button3 MsgBox(0, "MSG", "Button3") Case $Button4 MsgBox(0, "MSG", "Button4") EndSwitch WEnd Func _Button_Hover($iCtrlID, $iHoverMode) Local $sImageName = "OVER" Local $sImageIndex = "1" Switch $iHoverMode Case 1 ;Hover $sImageName = "OVER" Case 2 ;Leave hover $sImageName = "NORMAL" EndSwitch Switch $iCtrlID Case $Button1 $sImageIndex = "1" Case $Button2 $sImageIndex = "2" Case $Button3 $sImageIndex = "3" Case $Button4 $sImageIndex = "4" EndSwitch GUICtrlSetImage($iCtrlID, $sImageName & $sImageIndex & ".bmp") EndFunc Func _Button_Click($iCtrlID, $iClickMode) Local $sImageName = "PRESS" Local $sImageIndex = "1" Switch $iClickMode Case 1 ;Hover $sImageName = "PRESS" Case 2 ;Leave hover $sImageName = "OVER" EndSwitch Switch $iCtrlID Case $Button1 $sImageIndex = "1" Case $Button2 $sImageIndex = "2" Case $Button3 $sImageIndex = "3" Case $Button4 $sImageIndex = "4" EndSwitch GUICtrlSetImage($iCtrlID, $sImageName & $sImageIndex & ".bmp") EndFunc Thank you SetWindowsHookEx Function http://msdn.microsoft.com/en-us/library/ms644990(VS.85).aspx SetTimer Function http://msdn.microsoft.com/en-us/library/ms644906(VS.85).aspx Edited May 23, 2010 by wolf9228 ØµØ±Ø Ø§Ù„Ø³Ù…Ø§Ø¡ كان هنا  Link to comment Share on other sites More sharing options...
wolf9228 Posted May 23, 2010 Author Share Posted May 23, 2010 (edited) Using the hook seems to me redundant.Thank you Edited May 23, 2010 by wolf9228 ØµØ±Ø Ø§Ù„Ø³Ù…Ø§Ø¡ كان هنا  Link to comment Share on other sites More sharing options...
wolf9228 Posted May 23, 2010 Author Share Posted May 23, 2010 (edited) This MrCreatoR code expandcollapse popup#include-once ;_GUICtrl_SetOnHover Global Variables Global $aHOVER_CONTROLS_ARRAY[1][1] Global $aLAST_HOVERED_ELEMENT[2] = [-1, -1] Global $aLAST_HOVERED_ELEMENT_MARK = -1 Global $hLAST_CLICKED_ELEMENT_MARK = -1 Global $pTimerProc = 0 Global $uiTimer = 0 #Region =================== UDF Info =================== ; UDF Name: _GUICtrl_SetOnHover ; Forum link: http://www.autoitscript.com/forum/index.php?s=&showtopic=55120 ; Author: G.Sandler a.k.a MrCreatoR (CreatoR's Lab, http://creator-lab.ucoz.ru) ; ; ; {Version History}: ; [v1.5] ; + Added AutoIt 3.2.10.0+ support, but 3.2.8.1 or less is dropped :( (due to lack of native CallBack functions). ; + Added Primary Down and Primary Up support. Helping to handle with the buttons pressing. ; + Added new arguments to calling function... ; The OnHover function now can recieve two more arguments: ; $iHoverMode - Defines the hover mode (1 - Hover, 2 - Leaves Hovering) ; $hWnd_Hovered - Control Handle where the mouse is moved to (after hovering). ; ; * Almost all code of this UDF was rewritted. ; * Now the main function name is _GUICtrl_SetOnHover(), ; but for backwards compatibility reasons, other (old) function names are still supported. ; * Fixed bug with hovering controls in other apps. ; * Improvements in generaly, the UDF working more stable now. ; ; [v1.?] ; * Beta changes, see "Forum link" for more details. ; ; [v1.0] ; * First release. #EndRegion =================== UDF Info =================== ; ;=============================================================================== ; ; Function Name: _GUICtrl_SetOnHover() ; Description: Set function(s) to call when hovering/leave hovering GUI elements. ; ; Parameter(s): $iCtrlID - The Ctrl ID to set hovering for (can be a -1 as indication to the last item created). ; ; $sHover_FuncName - [Optional] Function to call when the mouse is hovering the control. ; If this parameter passed as empty string (""), ; then the specified CtrlID is UnSet from Hovering Handler list. ; ; $sLeaveHover_FuncName - [Optional] Function to call when the mouse is leaving hovering the control ; (-1 no function used). ; * For both parameters, $sHover_FuncName and $sLeaveHover_FuncName, ; the specified function called with maximum 3 parameters: ; $iCtrlID - CtrlID of hovered control. ; $iHoverMode - Defines the hover mode (1 - Hover, 2 - Leaves Hovering) ; $hWnd_Hovered - Control Handle where the mouse is moved to (after hovering). ; ; $sPrimDwnFuncName - [Optional] Function to call when Primary mouse button is *clicked* on the control. ; (-1 -> function is not called). ; ; $sPrimUpFuncName - [Optional] Function to call when Primary mouse button is *released* the control. ; (-1 -> function is not called). ; ; $iKeepCallFnc - [Optional] If this parameter < 1, ; then the $sPrimDwnFuncName function will *Not* be called constantly untill ; the primary mouse button is released (default behaviour, $iKeepCallFunc = 1). ; ; Return Value(s): Always returns 1 regardless of success. ; ; Requirement(s): AutoIt 3.2.10.0 + ; ; Note(s): 1) TreeView/ListView Items can not be set :(. ; 2) When the window is not active, the hover/leave hover functions will still called, ; but not when the window is disabled. ; 3) The hover/leave hover functions will be called even if the script is paused by such functions as MsgBox(). ; 4) It is not recommended to block the HoverFunc by calling functions like Sleep() or MsgBox(). ; ; Author(s): G.Sandler (a.k.a CreatoR). ; ;=============================================================================== Func _GUICtrl_SetOnHover($iCtrlID,$sHover_Func="",$sLeaveHover_Func=-1,$sPrimaryDownFunc=-1,$sPrimaryUpFunc=-1,$iKeepCallFunc=1) Local $hCtrlID = GUICtrlGetHandle($iCtrlID) If $pTimerProc = 0 Then $pTimerProc = DllCallbackRegister("__MAIN_CALLBACK_ONHOVER_PROC", "none", "hwnd;int;int;dword") $uiTimer = DllCall("user32.dll", "int", "SetTimer", "hwnd", 0, _ "int", TimerInit(), "int", 10, "ptr", DllCallbackGetPtr($pTimerProc)) If IsArray($uiTimer) Then $uiTimer = $uiTimer[0] EndIf ;UnSet Hovering for specified control (remove control id from hovering checking process) If $sHover_Func = "" Then Local $aHOVER_CONTROLS_Tmp[1][1] For $i = 1 To $aHOVER_CONTROLS_ARRAY[0][0] If $hCtrlID <> $aHOVER_CONTROLS_ARRAY[$i][0] Then $aHOVER_CONTROLS_Tmp[0][0] += 1 ReDim $aHOVER_CONTROLS_Tmp[$aHOVER_CONTROLS_Tmp[0][0]+1][6] $aHOVER_CONTROLS_Tmp[$aHOVER_CONTROLS_Tmp[0][0]][0] = $aHOVER_CONTROLS_ARRAY[$i][0] $aHOVER_CONTROLS_Tmp[$aHOVER_CONTROLS_Tmp[0][0]][1] = $aHOVER_CONTROLS_ARRAY[$i][1] $aHOVER_CONTROLS_Tmp[$aHOVER_CONTROLS_Tmp[0][0]][2] = $aHOVER_CONTROLS_ARRAY[$i][2] $aHOVER_CONTROLS_Tmp[$aHOVER_CONTROLS_Tmp[0][0]][3] = $aHOVER_CONTROLS_ARRAY[$i][3] $aHOVER_CONTROLS_Tmp[$aHOVER_CONTROLS_Tmp[0][0]][4] = $aHOVER_CONTROLS_ARRAY[$i][4] $aHOVER_CONTROLS_Tmp[$aHOVER_CONTROLS_Tmp[0][0]][5] = $aHOVER_CONTROLS_ARRAY[$i][5] EndIf Next If $aHOVER_CONTROLS_Tmp[0][0] < 1 Then OnAutoItExit() ;Release the callbacks Else $aHOVER_CONTROLS_ARRAY = $aHOVER_CONTROLS_Tmp EndIf Return 1 EndIf ;Check if the hovering process already handle the passed CtrlID, if so, just assign new values (functions) For $i = 1 To $aHOVER_CONTROLS_ARRAY[0][0] If $hCtrlID = $aHOVER_CONTROLS_ARRAY[$i][0] Then $aHOVER_CONTROLS_ARRAY[$i][0] = $hCtrlID $aHOVER_CONTROLS_ARRAY[$i][1] = $sHover_Func $aHOVER_CONTROLS_ARRAY[$i][2] = $sLeaveHover_Func $aHOVER_CONTROLS_ARRAY[$i][3] = $sPrimaryDownFunc $aHOVER_CONTROLS_ARRAY[$i][4] = $sPrimaryUpFunc $aHOVER_CONTROLS_ARRAY[$i][5] = $iKeepCallFunc Return 1 EndIf Next $aHOVER_CONTROLS_ARRAY[0][0] += 1 ReDim $aHOVER_CONTROLS_ARRAY[$aHOVER_CONTROLS_ARRAY[0][0]+1][6] $aHOVER_CONTROLS_ARRAY[$aHOVER_CONTROLS_ARRAY[0][0]][0] = $hCtrlID $aHOVER_CONTROLS_ARRAY[$aHOVER_CONTROLS_ARRAY[0][0]][1] = $sHover_Func $aHOVER_CONTROLS_ARRAY[$aHOVER_CONTROLS_ARRAY[0][0]][2] = $sLeaveHover_Func $aHOVER_CONTROLS_ARRAY[$aHOVER_CONTROLS_ARRAY[0][0]][3] = $sPrimaryDownFunc $aHOVER_CONTROLS_ARRAY[$aHOVER_CONTROLS_ARRAY[0][0]][4] = $sPrimaryUpFunc $aHOVER_CONTROLS_ARRAY[$aHOVER_CONTROLS_ARRAY[0][0]][5] = $iKeepCallFunc Return 1 EndFunc ;CallBack function to handle the hovering process Func __MAIN_CALLBACK_ONHOVER_PROC($hWnd, $uiMsg, $idEvent, $dwTime) If $aHOVER_CONTROLS_ARRAY[0][0] < 1 Then Return Local $iControl_Hovered = _ControlGetHovered() Local $sCheck_LHE = $aLAST_HOVERED_ELEMENT[1] Local $iCheck_LCEM = $hLAST_CLICKED_ELEMENT_MARK Local $iCtrlID ;Leave Hovering Process and reset variables If Not $iControl_Hovered Or ($sCheck_LHE <> -1 And $iControl_Hovered <> $sCheck_LHE) Then If $aLAST_HOVERED_ELEMENT_MARK = -1 Then Return If $aLAST_HOVERED_ELEMENT[0] <> -1 Then $iCtrlID = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $aLAST_HOVERED_ELEMENT[1]) If IsArray($iCtrlID) Then $iCtrlID = $iCtrlID[0] Call($aLAST_HOVERED_ELEMENT[0], $iCtrlID, 2, $iControl_Hovered) ;2 is the indicator of OnLeavHover process If @error Then Call($aLAST_HOVERED_ELEMENT[0], $iCtrlID, 2) If @error Then Call($aLAST_HOVERED_ELEMENT[0], $iCtrlID) If @error Then Call($aLAST_HOVERED_ELEMENT[0]) EndIf $aLAST_HOVERED_ELEMENT[0] = -1 $aLAST_HOVERED_ELEMENT[1] = -1 $aLAST_HOVERED_ELEMENT_MARK = -1 $hLAST_CLICKED_ELEMENT_MARK = -1 Else ;Hovering Process, Primary Down/Up handler, and set LAST_HOVERED_ELEMENT For $i = 1 To $aHOVER_CONTROLS_ARRAY[0][0] If $aHOVER_CONTROLS_ARRAY[$i][0] = $iControl_Hovered Then $iCtrlID = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $iControl_Hovered) If IsArray($iCtrlID) Then $iCtrlID = $iCtrlID[0] ;Primary Down/Up handler If ($aHOVER_CONTROLS_ARRAY[$i][3] <> "" Or $aHOVER_CONTROLS_ARRAY[$i][4] <> "") And _ ($iCheck_LCEM = -1 Or $iCheck_LCEM = $iControl_Hovered) Then Local $aCursorInfo = GUIGetCursorInfo() If IsArray($aCursorInfo) Then ;Primary Down. Last condition is to Prevent/Allow multiple function call. If $aCursorInfo[2] = 1 And $aHOVER_CONTROLS_ARRAY[$i][3] <> -1 And _ (($aHOVER_CONTROLS_ARRAY[$i][5] < 1 And $iCheck_LCEM <> $iControl_Hovered) Or _ $aHOVER_CONTROLS_ARRAY[$i][5] > 0) Then Call($aHOVER_CONTROLS_ARRAY[$i][3], $iCtrlID) If @error Then Call($aHOVER_CONTROLS_ARRAY[$i][3]) $hLAST_CLICKED_ELEMENT_MARK = $iControl_Hovered ElseIf $aCursorInfo[2] = 0 And $aHOVER_CONTROLS_ARRAY[$i][4] <> -1 And _ ;Primary Up $iCheck_LCEM = $iControl_Hovered Then Call($aHOVER_CONTROLS_ARRAY[$i][4], $iCtrlID) If @error Then Call($aHOVER_CONTROLS_ARRAY[$i][4]) $hLAST_CLICKED_ELEMENT_MARK = -1 EndIf EndIf EndIf If $aLAST_HOVERED_ELEMENT_MARK = $aHOVER_CONTROLS_ARRAY[$i][0] Then ExitLoop $aLAST_HOVERED_ELEMENT_MARK = $aHOVER_CONTROLS_ARRAY[$i][0] Call($aHOVER_CONTROLS_ARRAY[$i][1], $iCtrlID, 1, 0) ;1 is the indicator of OnHover process If @error Then Call($aHOVER_CONTROLS_ARRAY[$i][1], $iCtrlID, 1) If @error Then Call($aHOVER_CONTROLS_ARRAY[$i][1], $iCtrlID) If @error Then Call($aHOVER_CONTROLS_ARRAY[$i][1]) If $aHOVER_CONTROLS_ARRAY[$i][2] <> -1 Then $aLAST_HOVERED_ELEMENT[0] = $aHOVER_CONTROLS_ARRAY[$i][2] $aLAST_HOVERED_ELEMENT[1] = $iControl_Hovered EndIf ExitLoop EndIf Next EndIf EndFunc ;Backwards compatibility function #1 Func GUICtrl_SetOnHover($iCtrlID, $sHover_Func="", $sLeaveHover_Func=-1, $sPrimaryDownFunc=-1, $sPrimaryUpFunc=-1, $iKeepCallFunc=1) _GUICtrl_SetOnHover($iCtrlID, $sHover_Func, $sLeaveHover_Func, $sPrimaryDownFunc, $sPrimaryUpFunc, $iKeepCallFunc) EndFunc ;Backwards compatibility function #2 Func GUICtrlSetOnHover($iCtrlID, $sHover_Func="", $sLeaveHover_Func=-1, $sPrimaryDownFunc=-1, $sPrimaryUpFunc=-1, $iKeepCallFunc=1) _GUICtrl_SetOnHover($iCtrlID, $sHover_Func, $sLeaveHover_Func, $sPrimaryDownFunc, $sPrimaryUpFunc, $iKeepCallFunc) EndFunc ;Backwards compatibility function #3 Func _GUICtrlSetOnHover($iCtrlID, $sHover_Func="", $sLeaveHover_Func=-1, $sPrimaryDownFunc=-1, $sPrimaryUpFunc=-1, $iKeepCallFunc=1) _GUICtrl_SetOnHover($iCtrlID, $sHover_Func, $sLeaveHover_Func, $sPrimaryDownFunc, $sPrimaryUpFunc, $iKeepCallFunc) EndFunc ;Thanks to amel27 for that one!!! Func _ControlGetHovered() Local $Old_Opt_MCM = Opt("MouseCoordMode", 1) Local $aRet = DllCall("User32.dll", "int", "WindowFromPoint", _ "long", MouseGetPos(0), _ "long", MouseGetPos(1)) ;$aRet = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $aRet[0]) Opt("MouseCoordMode", $Old_Opt_MCM) Return $aRet[0] EndFunc ;Release the CallBack resources Func OnAutoItExit() If $pTimerProc > 0 Then DllCallbackFree($pTimerProc) If $uiTimer > 0 Then DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "int", $uiTimer) $pTimerProc = 0 $uiTimer = 0 EndFunc And this is my code expandcollapse popup#Include <WinAPI.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <Constants.au3> Global $CtrlhWnd_Array[1][4] , $HoverProcPtr = 0 , $HoverRegister = "" , $hHook_HOVER OnAutoItExitRegister("Cleanup") Func CreateButtonHover($L,$T,$W,$H,$NORMAL_hBMP,$PRESS_hBMP,$OVER_hBMP,$style = 0,$exStyle = 0) Local $BM_SETIMAGE_HOVER = 0x00F7 , $BS_BITMAP_HOVER = 0x00000080, $BS_ICON_HOVER = 0x00000040 , _ $iPID_HOVER = 0 , $hmod = _WinAPI_GetModuleHandle(0) $controlID = GUICtrlCreateButton("",$L,$T,$W,$H,$style,$exStyle) $hWnd = GUICtrlGetHandle($controlID) $CtrlhWnd_Array[UBound($CtrlhWnd_Array) - 1][0] = $hWnd if Not ($HoverProcPtr) Then $HoverRegister = DllCallbackRegister("ButtonHoverProc", "long", "int;wparam;lparam") $HoverProcPtr = DllCallbackGetPtr($HoverRegister) $hHook_HOVER = _WinAPI_SetWindowsHookEx($WH_GETMESSAGE ,$HoverProcPtr, $hmod , _ _WinAPI_GetWindowThreadProcessId(_WinAPI_GetParent($hWnd),$iPID_HOVER)) EndIf if Not BitAND(_WinAPI_GetWindowLong($hWnd, $GWL_STYLE), $BS_BITMAP_HOVER ) = $BS_BITMAP_HOVER Then _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, _WinAPI_GetWindowLong($hWnd, $GWL_STYLE) + $BS_BITMAP_HOVER ) ElseIf BitAND(_WinAPI_GetWindowLong($hWnd, $GWL_STYLE), $BS_ICON_HOVER ) = $BS_ICON_HOVER Then _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, _WinAPI_GetWindowLong($hWnd, $GWL_STYLE) - $BS_ICON_HOVER ) EndIf _SendMessage($hWnd,$BM_SETIMAGE_HOVER,0,$NORMAL_hBMP) $CtrlhWnd_Array[UBound($CtrlhWnd_Array) - 1][1] = $NORMAL_hBMP $CtrlhWnd_Array[UBound($CtrlhWnd_Array) - 1][2] = $PRESS_hBMP $CtrlhWnd_Array[UBound($CtrlhWnd_Array) - 1][3] = $OVER_hBMP ReDim $CtrlhWnd_Array[UBound($CtrlhWnd_Array) + 1][4] Return $controlID EndFunc Func ArraySearch($hWnd) For $Element = 0 To UBound($CtrlhWnd_Array) - 1 if $CtrlhWnd_Array[$Element][0] == $hWnd Then Return $Element Next Return -1 EndFunc Func ButtonHoverDelete($controlID) Local $Temp_Array[1][4] , $Test = False For $Element = 0 To UBound($CtrlhWnd_Array) - 1 if $CtrlhWnd_Array[$Element][0] == GUICtrlGetHandle($controlID) Then GUICtrlDelete($controlID) $Test = True Else $Temp_Array[UBound($Temp_Array) - 1][0] = $CtrlhWnd_Array[$Element][0] $Temp_Array[UBound($Temp_Array) - 1][1] = $CtrlhWnd_Array[$Element][1] $Temp_Array[UBound($Temp_Array) - 1][2] = $CtrlhWnd_Array[$Element][2] $Temp_Array[UBound($Temp_Array) - 1][3] = $CtrlhWnd_Array[$Element][3] ReDim $Temp_Array[UBound($Temp_Array) + 1][4] EndIf Next ReDim $Temp_Array[UBound($Temp_Array) - 1][4] $CtrlhWnd_Array = $Temp_Array Return $Test EndFunc Func ButtonHoverProc($nCode, $wParam, $lParam) If $nCode < 0 Then _ Return _WinAPI_CallNextHookEx($hHook_HOVER, $nCode, $wParam, $lParam) Local _ $WM_MOUSEFIRST_HOVER = 0x0200 , _ $WM_MOUSELEAVE_HOVER = 0x02A3 , _ $WM_LBUTTONDOWN_HOVER = 0x0201 , _ $WM_LBUTTONUP_HOVER = 0x0202 , _ $BM_SETIMAGE_HOVER = 0x00F7 $Tag_struct ="HWND hwnd;UINT message;WPARAM wParam;LPARAM lParam;" & _ "DWORD time;LONG y;LONG x" $MSG = DllStructCreate($Tag_struct,$lParam) $hWnd = DllStructGetData($MSG,1) $uiMsg = DllStructGetData($MSG,2) $Element = ArraySearch($hWnd) if $Element <> -1 Then Select Case $uiMsg = $WM_MOUSEFIRST_HOVER _SendMessage($hWnd,$BM_SETIMAGE_HOVER,0,$CtrlhWnd_Array[$Element][3]) Case $uiMsg = $WM_MOUSELEAVE_HOVER _SendMessage($hWnd,$BM_SETIMAGE_HOVER,0,$CtrlhWnd_Array[$Element][1]) Case $uiMsg = $WM_LBUTTONDOWN_HOVER _SendMessage($hWnd,$BM_SETIMAGE_HOVER,0,$CtrlhWnd_Array[$Element][2]) Case $uiMsg = $WM_LBUTTONUP_HOVER _SendMessage($hWnd,$BM_SETIMAGE_HOVER,0,$CtrlhWnd_Array[$Element][3]) EndSelect EndIf Return _WinAPI_CallNextHookEx($hHook_HOVER, $nCode, $wParam, $lParam) EndFunc Func LoadBitmap_FromFile($sFileName) Return _WinAPI_LoadImage(_WinAPI_GetModuleHandle(0),$sFileName,0 ,0,0,0x0010) EndFunc Func LoadBitmap_FromResources($resource_Name) Return _WinAPI_LoadBitmap(_WinAPI_GetModuleHandle(0), $resource_Name) EndFunc Func GetBmpWidth($hBMP) $tagBITMAPINFO_HOVER = "DWORD biSize;LONG biWidth;LONG biHeight;USHORT biPlanes;" & _ "USHORT biBitCount;DWORD biCompression;DWORD biSizeImage;LONG biXPelsPerMeter;" & _ "LONG biYPelsPerMeter;DWORD biClrUsed;DWORD biClrImportant;BYTE rgbBlueElement1;" & _ "BYTE rgbGreenElement1;BYTE rgbRedElement1;BYTE rgbReservedElement1" $BITMAPINFO = DllStructCreate($tagBITMAPINFO_HOVER) DllStructSetData($BITMAPINFO,"biSize",DllStructGetSize($BITMAPINFO)) $hDC = _WinAPI_CreateCompatibleDC(0) _WinAPI_GetDIBits($hDC,$hBmp,0,0,0,DllStructGetPtr($BITMAPINFO),0) Return DllStructGetData($BITMAPINFO,"biWidth") EndFunc Func GetBmpHeight($hBMP) $tagBITMAPINFO_HOVER = "DWORD biSize;LONG biWidth;LONG biHeight;USHORT biPlanes;" & _ "USHORT biBitCount;DWORD biCompression;DWORD biSizeImage;LONG biXPelsPerMeter;" & _ "LONG biYPelsPerMeter;DWORD biClrUsed;DWORD biClrImportant;BYTE rgbBlueElement1;" & _ "BYTE rgbGreenElement1;BYTE rgbRedElement1;BYTE rgbReservedElement1" $BITMAPINFO = DllStructCreate($tagBITMAPINFO_HOVER) DllStructSetData($BITMAPINFO,"biSize",DllStructGetSize($BITMAPINFO)) $hDC = _WinAPI_CreateCompatibleDC(0) _WinAPI_GetDIBits($hDC,$hBmp,0,0,0,DllStructGetPtr($BITMAPINFO),0) Return DllStructGetData($BITMAPINFO,"biHeight") EndFunc Func Cleanup() _WinAPI_UnhookWindowsHookEx($hHook_HOVER) DllCallbackFree($HoverRegister) EndFunc expandcollapse popup#Include <WinAPI.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <Constants.au3> Global $CtrlhWnd_Array[1][6] , $TEST_WM_MOUSEFIRST = 0 , $HoverProcPtr = 0 , $HoverRegister = "" Global $HOVER_HWND = 0 , $hHook_HOVER , $TEST_WM_LBUTTONDOWN = 0 OnAutoItExitRegister("Cleanup") Func CreateButtonHover($Text,$L,$T,$W,$H,$NORMAL_hBMP,$PRESS_hBMP,$OVER_hBMP,$TEXTCOLOOR = 0) Local $STM_SETIMAGE_HOVER = 0x0172 , $SS_BITMAP_HOVER = 0x0000000E _ , $SS_REALSIZECONTROL_HOVER = 0x00000040 , $iPID_HOVER = 0 , $hmod = _WinAPI_GetModuleHandle(0) $controlID1 = GUICtrlCreateLabel("",$L,$T,$W,$H,$SS_REALSIZECONTROL_HOVER + $SS_BITMAP_HOVER) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) $hWnd1 = GUICtrlGetHandle($controlID1) $CtrlhWnd_Array[UBound($CtrlhWnd_Array) - 1][0] = $hWnd1 $user = GUICtrlCreateDummy() $controlID2 = GUICtrlCreateLabel($Text,$L,$T,$W,$H, $SS_CENTERIMAGE + $SS_NOTIFY + $SS_CENTER) if ($TEXTCOLOOR) Then GUICtrlSetColor(-1,$TEXTCOLOOR) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) $hWnd2 = GUICtrlGetHandle($controlID2) $CtrlhWnd_Array[UBound($CtrlhWnd_Array) - 1][1] = $hWnd2 $CtrlhWnd_Array[UBound($CtrlhWnd_Array) - 1][2] = $user if Not ($HoverProcPtr) Then $HoverRegister = DllCallbackRegister("ButtonHoverProc", "long", "int;wparam;lparam") $HoverProcPtr = DllCallbackGetPtr($HoverRegister) $hHook_HOVER = _WinAPI_SetWindowsHookEx($WH_MOUSE ,$HoverProcPtr, $hmod , _ _WinAPI_GetWindowThreadProcessId(_WinAPI_GetParent($hWnd1),$iPID_HOVER)) EndIf _SendMessage($hWnd1,$STM_SETIMAGE_HOVER,0,$NORMAL_hBMP) $CtrlhWnd_Array[UBound($CtrlhWnd_Array) - 1][3] = $NORMAL_hBMP $CtrlhWnd_Array[UBound($CtrlhWnd_Array) - 1][4] = $PRESS_hBMP $CtrlhWnd_Array[UBound($CtrlhWnd_Array) - 1][5] = $OVER_hBMP ReDim $CtrlhWnd_Array[UBound($CtrlhWnd_Array) + 1][6] Return SetError (0, $controlID2,$user) EndFunc Func ArraySearch($hWnd) For $Element = 0 To UBound($CtrlhWnd_Array) - 1 if $CtrlhWnd_Array[$Element][0] == $hWnd Then Return $Element Next Return -1 EndFunc Func ButtonHoverDelete($controlID) Local $Temp_Array[1][6] , $Test = False For $Element = 0 To UBound($CtrlhWnd_Array) - 1 if $CtrlhWnd_Array[$Element][2] == $controlID Then GUICtrlDelete(_WinAPI_GetDlgCtrlID($CtrlhWnd_Array[$Element][0])) GUICtrlDelete(_WinAPI_GetDlgCtrlID($CtrlhWnd_Array[$Element][1])) GUICtrlDelete($CtrlhWnd_Array[$Element][2]) $Test = True Else $Temp_Array[UBound($Temp_Array) - 1][0] = $CtrlhWnd_Array[$Element][0] $Temp_Array[UBound($Temp_Array) - 1][1] = $CtrlhWnd_Array[$Element][1] $Temp_Array[UBound($Temp_Array) - 1][2] = $CtrlhWnd_Array[$Element][2] $Temp_Array[UBound($Temp_Array) - 1][3] = $CtrlhWnd_Array[$Element][3] $Temp_Array[UBound($Temp_Array) - 1][4] = $CtrlhWnd_Array[$Element][4] $Temp_Array[UBound($Temp_Array) - 1][5] = $CtrlhWnd_Array[$Element][5] ReDim $Temp_Array[UBound($Temp_Array) + 1][6] EndIf Next ReDim $Temp_Array[UBound($Temp_Array) - 1][6] $CtrlhWnd_Array = $Temp_Array Return $Test EndFunc Func ButtonHoverProc($nCode, $wParam, $lParam) If $nCode < 0 Then _ Return _WinAPI_CallNextHookEx($hHook_HOVER, $nCode, $wParam, $lParam) Local _ $WM_MOUSEFIRST_HOVER = 0x0200 , _ $WM_LBUTTONDOWN_HOVER = 0x0201 , _ $WM_LBUTTONUP_HOVER = 0x0202 , _ $STM_SETIMAGE_HOVER = 0x0172 , _ $Tag_struct ="LONG x;LONG y;HWND hwnd;UINT wHitTestCode;ULONG_PTR dwExtraInfo" $MOUSEHOOKSTRUCT = DllStructCreate($Tag_struct,$lParam) $hWnd = DllStructGetData($MOUSEHOOKSTRUCT,3) $uiMsg = $wParam $Element = ArraySearch($hWnd) If $Element <> -1 Then $hWnd1 = $CtrlhWnd_Array[$Element][0] $hWnd2 = $CtrlhWnd_Array[$Element][1] If $uiMsg = $WM_MOUSEFIRST_HOVER And $TEST_WM_MOUSEFIRST = 0 Then $HOVER_HWND = $hWnd1 _SendMessage($hWnd1,$STM_SETIMAGE_HOVER,0,$CtrlhWnd_Array[$Element][5]) _WinAPI_RedrawWindow($hWnd2,0,0, $RDW_INVALIDATE ) $TEST_WM_MOUSEFIRST = 1 Else If $HOVER_HWND = $hWnd1 Then Select Case $uiMsg = $WM_LBUTTONDOWN_HOVER And $TEST_WM_LBUTTONDOWN = 0 _SendMessage($hWnd1,$STM_SETIMAGE_HOVER,0,$CtrlhWnd_Array[$Element][4]) _WinAPI_RedrawWindow($hWnd2,0,0, $RDW_INVALIDATE ) $TEST_WM_LBUTTONDOWN = 1 Case $uiMsg = $WM_LBUTTONUP_HOVER And $TEST_WM_LBUTTONDOWN = 1 _SendMessage($hWnd1,$STM_SETIMAGE_HOVER,0,$CtrlhWnd_Array[$Element][5]) _WinAPI_RedrawWindow($hWnd2,0,0, $RDW_INVALIDATE ) GUICtrlSendToDummy($CtrlhWnd_Array[$Element][2]) $TEST_WM_LBUTTONDOWN = 0 EndSelect Else If $uiMsg = $WM_LBUTTONUP_HOVER And $TEST_WM_LBUTTONDOWN = 1 Then $Element = ArraySearch($HOVER_HWND) $hWnd1 = $CtrlhWnd_Array[$Element][0] $hWnd2 = $CtrlhWnd_Array[$Element][1] _SendMessage($hWnd1,$STM_SETIMAGE_HOVER,0,$CtrlhWnd_Array[$Element][3]) _WinAPI_RedrawWindow($hWnd2,0,0, $RDW_INVALIDATE ) $TEST_WM_LBUTTONDOWN = 0 $Element = ArraySearch($hWnd) $hWnd1 = $CtrlhWnd_Array[$Element][0] $hWnd2 = $CtrlhWnd_Array[$Element][1] $HOVER_HWND = $hWnd1 _SendMessage($hWnd1,$STM_SETIMAGE_HOVER,0,$CtrlhWnd_Array[$Element][5]) _WinAPI_RedrawWindow($hWnd2,0,0, $RDW_INVALIDATE ) $TEST_WM_MOUSEFIRST = 1 EndIf EndIf EndIf Else If $TEST_WM_LBUTTONDOWN = 1 Then If $uiMsg = $WM_LBUTTONUP_HOVER Then $Element = ArraySearch($HOVER_HWND) $hWnd1 = $CtrlhWnd_Array[$Element][0] $hWnd2 = $CtrlhWnd_Array[$Element][1] _SendMessage($hWnd1,$STM_SETIMAGE_HOVER,0,$CtrlhWnd_Array[$Element][3]) _WinAPI_RedrawWindow($hWnd2,0,0, $RDW_INVALIDATE ) $TEST_WM_LBUTTONDOWN = 0 EndIf Else If $TEST_WM_MOUSEFIRST = 1 Then $Element = ArraySearch($HOVER_HWND) $hWnd1 = $CtrlhWnd_Array[$Element][0] $hWnd2 = $CtrlhWnd_Array[$Element][1] _SendMessage($hWnd1,$STM_SETIMAGE_HOVER,0,$CtrlhWnd_Array[$Element][3]) _WinAPI_RedrawWindow($hWnd2,0,0, $RDW_INVALIDATE ) $TEST_WM_MOUSEFIRST = 0 EndIf EndIf EndIf Return _WinAPI_CallNextHookEx($hHook_HOVER, $nCode, $wParam, $lParam) EndFunc Func LoadBitmap_FromFile($sFileName) Return _WinAPI_LoadImage(_WinAPI_GetModuleHandle(0),$sFileName,0 ,0,0,0x0010) EndFunc Func LoadBitmap_FromResources($resource_Name) Return _WinAPI_LoadBitmap(_WinAPI_GetModuleHandle(0), $resource_Name) EndFunc Func GetBmpWidth($hBMP) $tagBITMAPINFO_HOVER = "DWORD biSize;LONG biWidth;LONG biHeight;USHORT biPlanes;" & _ "USHORT biBitCount;DWORD biCompression;DWORD biSizeImage;LONG biXPelsPerMeter;" & _ "LONG biYPelsPerMeter;DWORD biClrUsed;DWORD biClrImportant;BYTE rgbBlueElement1;" & _ "BYTE rgbGreenElement1;BYTE rgbRedElement1;BYTE rgbReservedElement1" $BITMAPINFO = DllStructCreate($tagBITMAPINFO_HOVER) DllStructSetData($BITMAPINFO,"biSize",DllStructGetSize($BITMAPINFO)) $hDC = _WinAPI_CreateCompatibleDC(0) _WinAPI_GetDIBits($hDC,$hBmp,0,0,0,DllStructGetPtr($BITMAPINFO),0) Return DllStructGetData($BITMAPINFO,"biWidth") EndFunc Func GetBmpHeight($hBMP) $tagBITMAPINFO_HOVER = "DWORD biSize;LONG biWidth;LONG biHeight;USHORT biPlanes;" & _ "USHORT biBitCount;DWORD biCompression;DWORD biSizeImage;LONG biXPelsPerMeter;" & _ "LONG biYPelsPerMeter;DWORD biClrUsed;DWORD biClrImportant;BYTE rgbBlueElement1;" & _ "BYTE rgbGreenElement1;BYTE rgbRedElement1;BYTE rgbReservedElement1" $BITMAPINFO = DllStructCreate($tagBITMAPINFO_HOVER) DllStructSetData($BITMAPINFO,"biSize",DllStructGetSize($BITMAPINFO)) $hDC = _WinAPI_CreateCompatibleDC(0) _WinAPI_GetDIBits($hDC,$hBmp,0,0,0,DllStructGetPtr($BITMAPINFO),0) Return DllStructGetData($BITMAPINFO,"biHeight") EndFunc Func Cleanup() _WinAPI_UnhookWindowsHookEx($hHook_HOVER) DllCallbackFree($HoverRegister) EndFunc Which is better, my code Or MrCreatoR Code ... I think there is a big difference in these two Code Edited May 23, 2010 by wolf9228 ØµØ±Ø Ø§Ù„Ø³Ù…Ø§Ø¡ كان هنا  Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now