PDA

View Full Version : mouse over problem (UI)



largo_winch
25-02-2013, 16:28
I have a problem with mouse over function. in any elder example this function worked (dialog show modeless) but not here:


' Basic Template for custom dialog

' Start Date 02-25-2013
' Created by

Uses "UI"


Type RECT
nLeft As Long
nTop As Long
nRight As Long
nBottom As Long
End Type


Type POINTAPI
x As Long
y As Long
End Type


Declare Function PtInRect Lib "USER32.DLL" Alias "PtInRect" (lpRect As RECT, ByVal ptx As Long, ByVal pty As Long) As Long
Declare Function SetCapture Lib "USER32.DLL" Alias "SetCapture" (ByVal hWnd As DWord) As Long
Declare Function ReleaseCapture Lib "USER32.DLL" Alias "ReleaseCapture" () As Long
Declare Function GetCursorPos Lib "USER32.DLL" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
Declare Function GetWindowRect Lib "USER32.DLL" Alias "GetWindowRect" (ByVal hWnd As DWord, lpRect As RECT) As Long



' -- ID numbers of controls
Begin ControlID
%bClose
%btn_OK
%txt_Result


End ControlID


Begin Const
%MAIN_WIDTH = 320
%MAIN_HEIGHT = 240
End Const


' -- Create dialog here
Function TBMain()
Local hDlg As DWord
Dim hBtn_OK As DWord
Dim pt As POINTAPI
Dim rc As RECT
Dim counts As Long

Dialog New Pixels, 0, "<Enter title here>",-1,-1, %MAIN_WIDTH, %MAIN_HEIGHT, _
%WS_POPUP Or %WS_VISIBLE Or %WS_CAPTION Or %WS_SYSMENU Or %WS_MINIMIZEBOX To hDlg

' -- Place controls here
Control Add Button, hDlg, %bClose, "Click to close", %MAIN_WIDTH-105, %MAIN_HEIGHT-30, 100, 25, Call cbCloseButton

Control Add Textbox , hDlg, %txt_Result , "" , 10, 10, 80, 18, %WS_TABSTOP
Control Add Button , hDlg, %btn_OK , "OK" , 25, 80, 50, 24, %WS_TABSTOP


Control Handle hDlg, %btn_OK To hBtn_OK


Dialog Show Modal hDlg, Call cbDialog
Do
Dialog DoEvents To Counts
Loop Until Counts = 0

End Function




CallBack Function cbDialog2() As Long


Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %ButtonClose Then Dialog End CBHNDL


Case %WM_DESTROY
'MsgBox 0, "Window is to be destroyed."
End Select
End Function


' -- Callback for dialog
CallBack Function cbDialog()
Local hDlg As DWord,hBtn_OK As Long
Local pt As POINTAPI
Local rc As RECT

' -- Test for messages
Select Case CBMSG


Case %WM_INITDIALOG
' -- Put code to be executed after dialog creation here


Case %WM_MOUSEMOVE
SetCapture hDlg 'cbhndl

GetCursorPos pt
GetWindowRect hBtn_OK, rc '%btn_OK


'If ptInRect(rc,Str$(pt.x),Str$(pt.y)) Then
If ptInRect(rc,pt.x,pt.y) Then
Control Set Text hDlg, %txt_Result, "Bingo"
Else
Control Set Text hDlg, %txt_Result, ""
End If

ReleaseCapture


Case %WM_COMMAND
' -- You can handle controls here
If CBWPARAM = %btn_OK Then
MsgBox 0,"hello!"
End If
'SELECT CASE CBCTL
'
' CASE ...
' IF CBCTLMSG = ... THEN
'
' END IF
'
'END SELECT




Case %WM_CLOSE
' -- Put code to be executed before dialog end here


End Select


End Function

' -- Callback for close button
CallBack Function cbCloseButton()


If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %BN_CLICKED Then
' -- Closes the dialog
Dialog End CBHNDL
End If
End If


End Function



do you can help?

this example works with antique ui mode:

http://www.thinbasic.com/community/showthread.php?8506-mouse-over

bye, largo

Petr Schreiber
26-02-2013, 16:17
Hi Largo,

the problem was simple - you used two hDlg and hBtn_OK variables in each routine, but both were local.
So even if you filled them correctly in TBMain(), they did not transfer their values to cbDialog.

This could be solved by making the variables global (boooo, nastyyyy), setting them to dialog user variables (hmm, now that is ellegant) or just by using CBHNDL as is normal in callbacks and retrieving the handle of the control using CONTROL HANDLE command.

So if you change your MouseMove handling to the following, it should work again for you:


Case %WM_MOUSEMOVE

SetCapture(CBHNDL)

Control Handle CBHNDL, %txt_Result To hBtn_OK
GetCursorPos(pt)
GetWindowRect(hBtn_OK, rc)

If ptInRect(rc,pt.x,pt.y) Then
Control Set Text CBHNDL, %txt_Result, "Bingo"
Else
Control Set Text CBHNDL, %txt_Result, ""
End If

ReleaseCapture()



Petr

largo_winch
27-02-2013, 12:39
many thanks for "control handle" tipp, that's what I missed urgently. I've tried four different ways for this exmple and thought the problem caused by wrong declare function for pointinrectangle. and the "modeless" thing I added for it an


Dialog Show Modeless hDlg, Call cbDialog

Do
Dialog DoEvents To Counts
Loop Until Counts = 0


for tbmain() part and much more.

thanks! my new example works. I hope it will do same result if I am using an "add new canvas" an my font animation example. there is an idea I am following and I will check what's the result at the end if that could be a little game after all procedere. more infos about that topic will follow in some days! ;)

bye, largo