Code:
'=============================================================== ' How to simply make a Hover button from a label... ' Added: playes sound on mouse hover entering button area. ' Be sure to change ChildWindowFromPoint declare, or example ' won't compile. (replace Longs with POINTAPI) ' 'Declare Function ChildWindowFromPoint Lib "USER32.DLL" Alias "ChildWindowFromPoint" (ByVal hwndParent As Dword, ByVal x As Long, ByVal y As Long) As Dword 'Declare Function ChildWindowFromPointEx Lib "USER32.DLL" Alias "ChildWindowFromPointEx" (ByVal hWnd As Dword, ByVal x As Long, ByVal y As Long, ByVal uFlags As Dword) As Dword ' should be: 'Declare Function ChildWindowFromPoint Lib "USER32.DLL" Alias "ChildWindowFromPoint" (ByVal hwndParent As Dword, [b]ByVal Pt As POINTAPI[/b]) As Dword 'Declare Function ChildWindowFromPointEx Lib "USER32.DLL" Alias "ChildWindowFromPointEx" (ByVal hWnd As Dword, [b]ByVal Pt As POINTAPI[/b], ByVal uFlags As Dword) As Dword '--------------------------------------------------------------- #Compile Exe #Dim All #Include "win32api.inc" #Include "CommCtrl.inc" Global hButton As Dword, hDlg As Dword Function PaintButton(ByVal wMsg As Dword) As Long Local Pt As POINTAPI, Rc As RECT, Result As Dword, hDc As Dword Static OnButton As Dword, MouseDown As Dword GetCursorPos(Pt) ScreenToClient hDlg, Pt Result = ChildWindowFromPoint (hDlg, ByVal Pt) hDc = GetDc (hButton) GetClientRect(hButton,Rc) If (wMsg = %WM_LBUTTONDOWN) Or (wMsg = %WM_LBUTTONUP) Then OnButton = 0 If hButton = Result Then If OnButton = 0 Then OnButton = 1 If wMsg = %WM_LBUTTONDOWN Then DrawEdge(hdc, Rc, %BDR_SUNKENINNER Or %BDR_SUNKENOUTER, %BF_RECT) Beep Else DrawEdge(hdc, Rc, %BDR_RAISEDINNER Or %BDR_RAISEDOUTER, %BF_RECT) End If If wMsg = %WM_MOUSEMOVE Then sndPlaySound "start.wav",0 End If Else If OnButton = 1 Then OnButton = 0 : InValidateRect hButton, ByVal 0, ByVal 0 End If ReleaseDc hButton, hDc End Function CallBack Function CbMain () Select Case CbMsg Case %WM_LBUTTONDOWN, %WM_LBUTTONUP, %WM_MOUSEMOVE : PaintButton(CbMsg) End Select End Function Function PBMain As Long Dialog New 0,"Press to test...",200,200,105,80,%WS_SYSMENU To hDlg Control Add Label, hDlg, 1001, "Hover Button", 20,20,60,20, %SS_CENTER Or %SS_CENTERIMAGE Control Set Color hDlg, 1001, RGB(255,255,255), RGB(7,15,105) Dialog Set Color hDlg, RGB(255,255,255), RGB(7,15,105) hButton = GetDlgItem(hDlg, 1001) Dialog Show Modal hDlg Call CbMain End Function
Regards,
Peter
[This message has been edited by Peter Lameijn (edited March 17, 2005).]
Comment