Results 1 to 3 of 3

Thread: mouse over problem (UI)

  1. #1

    mouse over problem (UI)

    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/s...506-mouse-over

    bye, largo
    Last edited by largo_winch; 25-02-2013 at 16:34.

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    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
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    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
    Last edited by largo_winch; 27-02-2013 at 12:40.

Similar Threads

  1. Mouse Speed
    By cocoflop in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 10
    Last Post: 28-01-2008, 20:07
  2. mouse over
    By Michael Clease in forum thinBasic General
    Replies: 5
    Last Post: 17-11-2007, 19:08
  3. Labyrinth with mouse
    By ErosOlmi in forum TBGL Labyrinth
    Replies: 13
    Last Post: 20-02-2007, 00:57
  4. New tbgl Mouse example
    By kryton9 in forum TBGL General
    Replies: 7
    Last Post: 13-02-2007, 11:21
  5. handling the mouse
    By kryton9 in forum thinBasic General
    Replies: 1
    Last Post: 01-12-2006, 00:20

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •