Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Hover button

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hover button

    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).]
    Regards,
    Peter

  • #2
    I've got an error at:
    Code:
      Result = ChildWindowFromPoint (hDlg, BYVAL Pt)
    Change to:
    Code:
      Result = ChildWindowFromPoint (hDlg, BYVAL Pt.x, BYVAL Pt.y)
    Thanks for the code.

    ------------------
    mailto:[email protected][email protected]</A>
    www.thinbasic.com
    "If PowerBasic doesn't have the solution, then you've got the wrong problem."
    thinBasic programming language
    Win10 64bit - 8GB Ram - i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

    Comment


    • #3
      i just posted an alternate hover example in the discussion at:
      http://www.powerbasic.com/support/pb...ad.php?t=21301

      ------------------
      if you aim at nothing...you will hit it.
      sigpic
      Mobile Solutions
      Sys Analyst and Development

      Comment


      • #4
        If you replace
        Code:
            Result = ChildWindowFromPoint (hDlg, Pt)
        with
        Code:
            Result = ChildWindowFromPoint (hDlg, Pt.x, pt.y)
        it compiles.


        Thanks Peter!

        Comment

        Working...
        X