Sign in to follow this  
Followers 0
sandin

Colored button problem

5 posts in this topic

The following script contains several buttons, all with hover function. Tooltip disappears after user move mouse pointer away from buttons, but it doesn't disappears after colored button. Why?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>
#include <ButtonConstants.au3>

Global $hGui, $cInput, $wProcOld, $btn, $btn2, $wProcHandle
Global Const $WM_LBUTTONDOWN = 0x0201
Global Const $WM_MOUSELEAVE = 0x02A3

$hGui = GUICreate("buttons script", 200, 600, -1, -1)
$y_coord = 5
dim $btn[21]
for $i = 1 to 20
    $btn[$i] = GUICtrlCreateButton("button", 10, $y_coord, 100, 23, $WS_CLIPSIBLINGS)
    if $i = 5 or $i = 6 or $i = 7 or $i = 10 then GUICtrlSetBkColor(-1, 0x00FF00)
    $y_coord += 25
Next
$y_coord = 30
$wProcHandle = DllCallbackRegister("_MyWindowProc", "ptr", "hwnd;uint;wparam;lparam")
for $i = 1 to 20
    $wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($btn[$i]), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))
Next
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            for $i = 1 to 20
                _WinAPI_SetWindowLong(GUICtrlGetHandle($btn[$i]), $GWL_WNDPROC, $wProcOld)
            Next
            DllCallbackFree($wProcHandle)
            Exit
    EndSwitch
WEnd

Func _MyWindowProc($hWnd, $uiMsg, $wParam, $lParam)
    Switch $uiMsg
        Case $WM_LBUTTONDOWN
            ToolTip("")
            TrayTip("Mouse", "DOWN", 4 ,1)
        Case $WM_LBUTTONUP
            ToolTip("")
            TrayTip("Mouse", "UP", 4 ,1)
        Case $WM_MOUSELEAVE
            ToolTip("")
            TrayTip("", "", 4 ,1)
        Case $WM_SETCURSOR
            ToolTip("hover" & @CRLF & "control handle: " & @CRLF & $hWnd)
        EndSwitch
    Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc   ;==>_MyWindowProc

Share this post


Link to post
Share on other sites



I think you don't receive $WM_MOUSELEAVE notification for colored buttons...

Here is my solution:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>
#include <ButtonConstants.au3>

Global $hGui, $cInput, $wProcOld, $btn, $btn2, $wProcHandle
Global Const $WM_LBUTTONDOWN = 0x0201
Global Const $WM_MOUSELEAVE = 0x02A3

$hGui = GUICreate("buttons script", 200, 600, -1, -1)
$y_coord = 5
dim $btn[21]
for $i = 1 to 20
    $btn[$i] = GUICtrlCreateButton("button", 10, $y_coord, 100, 23, $WS_CLIPSIBLINGS)
    if $i = 5 or $i = 6 or $i = 7 or $i = 10 then GUICtrlSetBkColor(-1, 0x00FF00)
    $y_coord += 25
Next
$y_coord = 30
$wProcHandle = DllCallbackRegister("_MyWindowProc", "ptr", "hwnd;uint;wparam;lparam")
for $i = 1 to 20
    $wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($btn[$i]), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))
Next
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            for $i = 1 to 20
                _WinAPI_SetWindowLong(GUICtrlGetHandle($btn[$i]), $GWL_WNDPROC, $wProcOld)
            Next
            DllCallbackFree($wProcHandle)
            Exit
    EndSwitch
WEnd

Func _MyWindowProc($hWnd, $uiMsg, $wParam, $lParam)
    Switch $uiMsg
        Case $WM_LBUTTONDOWN
            ToolTip("")
            TrayTip("Mouse", "DOWN", 4 ,1)
        Case $WM_LBUTTONUP
            ToolTip("")
            TrayTip("Mouse", "UP", 4 ,1)
        Case $WM_MOUSELEAVE
            ToolTip("")
            TrayTip("", "", 4 ,1)
        Case $WM_SETCURSOR
            ToolTip("hover" & @CRLF & "control handle: " & @CRLF & $hWnd)
            Switch $wParam
                Case GUICtrlGetHandle($btn[5]), GUICtrlGetHandle($btn[6]), GUICtrlGetHandle($btn[7]), GUICtrlGetHandle($btn[10])
                    AdlibEnable("adlib", 10)
            EndSwitch
        Case Else
            ConsoleWrite($uiMsg & @CRLF)
        EndSwitch
    Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc   ;==>_MyWindowProc

Func Adlib()
    Local $cmsg = GUIGetCursorInfo()
    If $cmsg[4] = 0 Then
        ToolTip("")
        TrayTip("", "", 4 ,1)
    EndIf
    AdlibDisable()
EndFunc

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Share this post


Link to post
Share on other sites

Yes, it appears that $WM_MOUSELEAVE is not received (properly?). Try like this (it's modification of n3nE's):

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>
#include <ButtonConstants.au3>

Global $hGui, $cInput, $wProcOld, $btn, $btn2, $wProcHandle
Global Const $WM_LBUTTONDOWN = 0x0201
Global Const $WM_MOUSELEAVE = 0x02A3

$hGui = GUICreate("buttons script", 200, 600, -1, -1)
$y_coord = 5
Dim $btn[21]
For $i = 1 To 20
    $btn[$i] = GUICtrlCreateButton("button", 10, $y_coord, 100, 23, $WS_CLIPSIBLINGS)
    If $i = 5 Or $i = 6 Or $i = 7 Or $i = 10 Then GUICtrlSetBkColor(-1, 0x00FF00)
    $y_coord += 25
Next
$y_coord = 30
$wProcHandle = DllCallbackRegister("_MyWindowProc", "ptr", "hwnd;uint;wparam;lparam")
For $i = 1 To 20
    $wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($btn[$i]), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))
Next
GUISetState(@SW_SHOW)
Global $cmsg
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            For $i = 1 To 20
                _WinAPI_SetWindowLong(GUICtrlGetHandle($btn[$i]), $GWL_WNDPROC, $wProcOld)
            Next
            DllCallbackFree($wProcHandle)
            Exit
    EndSwitch
    
    $cmsg = GUIGetCursorInfo($hGui)
    If Not $cmsg[4] Then
        ToolTip("")
        TrayTip("", "", 4 ,1)
    EndIf

WEnd

Func _MyWindowProc($hWnd, $uiMsg, $wParam, $lParam)
    Switch $uiMsg
        Case $WM_LBUTTONDOWN
            ToolTip("")
            TrayTip("Mouse", "DOWN", 4, 1)
        Case $WM_LBUTTONUP
            ToolTip("")
            TrayTip("Mouse", "UP", 4, 1)
        ;Case $WM_MOUSELEAVE
        ;   ToolTip("")
        ;   TrayTip("", "", 4 ,1)
        Case $WM_SETCURSOR
            ToolTip("hover" & @CRLF & "control handle: " & @CRLF & $hWnd)
    EndSwitch
    Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc  ;==>_MyWindowProc

♡♡♡

.

eMyvnE

Share this post


Link to post
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
Sign in to follow this  
Followers 0