Announcement

Collapse
No announcement yet.

Mousewheel and PB10

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

  • Mousewheel and PB10

    I couldn't locate a similar problem with extensive searches and thus am stumped.

    am not able to get a mousewheel message to consistently return with PBWIN10. The following is the packaged sine.bas program. I added the mousewheel display. It works when compiled in PB9 but not PB10.


    Code:
    '====================================================================
    '
    '  SINE.BAS for PowerBASIC Compiler for Windows
    '  Copyright (c) 2005 - 2008 PowerBASIC, Inc.
    '  All Rights Reserved.
    '
    '  Scale a GRAPHIC control to pixel-based coordinates
    '  and draw a sine wave.
    '
    '====================================================================
    
    #COMPILER PBWIN 10
    #COMPILE EXE
    #DIM ALL
    
    
    %IDC_GRAPHIC1 = 110
    
    
    
    ' Draw a sine wave for 360 degrees
    '
    SUB DrawSineWave (BYVAL hDlg AS DWORD, BYVAL ID AS LONG)
    
        LOCAL x, y, mp, wh AS LONG, hzRadDeg, Pi AS DOUBLE
    
        CONTROL GET CLIENT hDlg, ID TO x, y    ' Client size
        DIALOG UNITS hDlg, x, y TO PIXELS x, y ' Convert to pixels
        mp     = y / 2                         ' Midpoint
        wh     = mp - 2                        ' Wave height
        Pi     = 4 * ATN(1)                    ' Calculate Pi
        hzRadDeg = Pi / 180                    ' Degrees to Radians
    
        GRAPHIC ATTACH hDlg, ID, REDRAW        ' Use faster, buffered draw
        GRAPHIC COLOR %BLUE, %WHITE            ' Blue line, white background
        GRAPHIC CLEAR                          ' Paint the white background
        GRAPHIC LINE (0, mp) - (x, mp), %GRAY  ' Draw midline
    
        y = SIN(hzRadDeg) * mp                 ' Calculate start point
        GRAPHIC SET POS (0, mp)                ' Set start position
    
        FOR x = 0 TO 360                       ' Run a full circle loop
            y = SIN(hzRadDeg * x) * wh         ' y-pos for each degree
            GRAPHIC LINE STEP - (x, mp + y)    ' Draw line
        NEXT
        GRAPHIC REDRAW                         ' Show it all
    
        ' Finally, tell what is drawn in dialog caption.
        DIALOG SET TEXT hDlg, "Sine wave"
    
    END SUB
    
    
    
    ' Main dialog callback procedure
    '
    CALLBACK FUNCTION DlgProc () AS LONG
    
        SELECT CASE CB.MSG
    
        CASE %WM_INITDIALOG   ' <- Sent right before the dialog is shown
    
        CASE %WM_COMMAND      ' <- A control is calling
            SELECT CASE CB.CTL  ' <- Look at control's id
    
            CASE %IDCANCEL
                IF CB.CTLMSG = %BN_CLICKED THEN ' Exit on Esc
                    DIALOG END CB.HNDL
                END IF
    
            END SELECT
    
    
          #IF -1
          CASE %WM_MOUSEWHEEL
    
             DIM i_CALL  AS STATIC LONG
    
             '  Process dynamic zoom using the mousewheel
             SELECT CASE CB.WPARAM
                CASE < 00   '  Roll back
    
                   i_CALL  -= 10
    
                CASE > 00   '  Roll fore
    
                   i_CALL  += 10
    
             END SELECT
    
             DIALOG SET TEXT   CB.HNDL  , "Mouse wheel " + STR$(i_CALL)
          #ENDIF
    
    
        END SELECT
    
    END FUNCTION
    
    
    
    ' Program entry point
    '
    FUNCTION PBMAIN () AS LONG
    
        LOCAL hDlg AS DWORD, w, h AS LONG
    
        DIALOG NEW 0, "Sine wave",,, 180, 100, %WS_CAPTION OR %WS_SYSMENU, _
                   0 TO hDlg
    
        CONTROL ADD GRAPHIC, hDlg, %IDC_GRAPHIC1, "", 0, 0, 180, 100
    
        ' Set up a pixel-based coordinate system in the Graphic control
        CONTROL GET CLIENT hDlg, %IDC_GRAPHIC1 TO w, h  ' Get client size
        DIALOG UNITS hDlg, w, h TO PIXELS w, h          ' Convert to pixels
        GRAPHIC ATTACH hDlg, %IDC_GRAPHIC1
        GRAPHIC SCALE (0, 0) - (w, h)   ' Scale to pixel coordinate system
    
        DrawSineWave hDlg, %IDC_GRAPHIC1
    
        DIALOG SHOW MODAL hDlg, CALL DlgProc
    
    END FUNCTION
    much appreciated if you can rectify.

    thanks, Dean

  • #2
    Hey Dean!
    I compiled here in PBWin10 and it seems to work fine. At least, the caption changes when I scroll the wheel. What problem are you seeing?

    Comment


    • #3
      Gary

      thanks for looking at this. Nothing displays in the dialog name. It does in PB9 but not 10. I have version 10.02 which I think has been revised to a higher revision.

      Comment


      • #4
        here is the screen shot for the same compiled with Version 9.0 Click image for larger version

Name:	mousewheel.png
Views:	1
Size:	4.8 KB
ID:	759937

        Comment


        • #5
          Tested with PBWIN 10.03 in Windows 7 and see same problem - %WM_MOUSEWHEEL is not there in DlgProc, but is there when compiled with PBWIN 9. Could this be a minor version issue? Gary - what version of PBWIN10 are you using?

          Comment


          • #6
            thank you for confirming

            Comment


            • #7
              Solution can be to subclass the graphic window and trap %WM_MOUSEWHEEL there.

              Comment


              • #8
                Ok, also tried to subclass dialog, but didn't work either - dialog procedure somehow eats WM_MOUSEWHEEL when compiled with v10.03. Subclassing graphic control works fine with all versions - here's adjusted test code:
                Code:
                '====================================================================
                '
                '  SINE.BAS for PowerBASIC Compiler for Windows
                '  Copyright (c) 2005 - 2008 PowerBASIC, Inc.
                '  All Rights Reserved.
                '
                '  Scale a GRAPHIC control to pixel-based coordinates
                '  and draw a sine wave.
                '
                '====================================================================
                '#COMPILER PBWIN 10
                #COMPILE EXE
                #DIM ALL
                #INCLUDE "Win32API.INC"
                
                %IDC_GRAPHIC1 = 110
                GLOBAL gOldProc AS DWORD
                
                ' Draw a sine wave for 360 degrees
                '
                SUB DrawSineWave (BYVAL hDlg AS DWORD, BYVAL ID AS LONG)
                
                    LOCAL x, y, mp, wh AS LONG, hzRadDeg, Pi AS DOUBLE
                
                    CONTROL GET CLIENT hDlg, ID TO x, y    ' Client size
                    DIALOG UNITS hDlg, x, y TO PIXELS x, y ' Convert to pixels
                    mp     = y / 2                         ' Midpoint
                    wh     = mp - 2                        ' Wave height
                    Pi     = 4 * ATN(1)                    ' Calculate Pi
                    hzRadDeg = Pi / 180                    ' Degrees to Radians
                
                    GRAPHIC ATTACH hDlg, ID, REDRAW        ' Use faster, buffered draw
                    GRAPHIC COLOR %BLUE, %WHITE            ' Blue line, white background
                    GRAPHIC CLEAR                          ' Paint the white background
                    GRAPHIC LINE (0, mp) - (x, mp), %GRAY  ' Draw midline
                
                    y = SIN(hzRadDeg) * mp                 ' Calculate start point
                    GRAPHIC SET POS (0, mp)                ' Set start position
                
                    FOR x = 0 TO 360                       ' Run a full circle loop
                        y = SIN(hzRadDeg * x) * wh         ' y-pos for each degree
                        GRAPHIC LINE STEP - (x, mp + y)    ' Draw line
                    NEXT
                    GRAPHIC REDRAW                         ' Show it all
                
                    ' Finally, tell what is drawn in dialog caption.
                    DIALOG SET TEXT hDlg, "Sine wave"
                
                END SUB
                
                
                
                ' Main dialog callback procedure
                '
                CALLBACK FUNCTION DlgProc () AS LONG
                
                    SELECT CASE CB.MSG
                    CASE %WM_INITDIALOG     ' <- Sent right before the dialog is shown
                      gOldProc = SetWindowLong(GetDlgItem(CB.HNDL, %IDC_GRAPHIC1), _
                                               %GWL_WNDPROC, CODEPTR(gwProc))
                
                    CASE %WM_COMMAND        ' <- A control is calling
                        SELECT CASE CB.CTL  ' <- Look at control's id
                        CASE %IDCANCEL
                            IF CB.CTLMSG = %BN_CLICKED THEN ' Exit on Esc
                                DIALOG END CB.HNDL
                            END IF
                
                        END SELECT
                
                  CASE %WM_DESTROY          ' clean up to avoid mem leaks
                      IF gOldProc THEN
                          SetWindowLong(GetDlgItem(CB.HNDL, %IDC_GRAPHIC1), %GWL_WNDPROC, gOldProc)
                      END IF
                
                    END SELECT
                
                END FUNCTION
                
                
                
                ' Program entry point
                '
                FUNCTION PBMAIN () AS LONG
                
                    LOCAL hDlg AS DWORD, w, h AS LONG
                
                    DIALOG NEW 0, "Sine wave",,, 180, 100, %WS_CAPTION OR %WS_SYSMENU, _
                               0 TO hDlg
                
                    CONTROL ADD GRAPHIC, hDlg, %IDC_GRAPHIC1, "", 0, 0, 180, 100
                
                    ' Set up a pixel-based coordinate system in the Graphic control
                    CONTROL GET CLIENT hDlg, %IDC_GRAPHIC1 TO w, h  ' Get client size
                    DIALOG UNITS hDlg, w, h TO PIXELS w, h          ' Convert to pixels
                    GRAPHIC ATTACH hDlg, %IDC_GRAPHIC1
                    GRAPHIC SCALE (0, 0) - (w, h)   ' Scale to pixel coordinate system
                
                    DrawSineWave hDlg, %IDC_GRAPHIC1
                
                    DIALOG SHOW MODAL hDlg, CALL DlgProc
                
                END FUNCTION
                
                
                '====================================================================
                ' Subclass procedure
                '--------------------------------------------------------------------
                FUNCTION gwProc(BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, _
                                BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
                
                  SELECT CASE wMsg
                  CASE %WM_MOUSEWHEEL '  Process dynamic zoom using the mousewheel
                      DIM i_CALL AS STATIC LONG
                
                      SELECT CASE HI(INTEGER, wParam)
                      CASE < 00   '  Roll back
                         i_CALL  -= 10
                
                      CASE > 00   '  Roll fore
                         i_CALL  += 10
                      END SELECT
                      DIALOG SET TEXT GetParent(hWnd), "Mouse wheel " + STR$(i_CALL)
                  END SELECT
                
                  FUNCTION = CallWindowProc(gOldProc, hWnd, wMsg, wParam, lParam)
                
                END FUNCTION

                Comment


                • #9
                  Using PBWIN 10.04 on Windows 7 I get no response to the mousewheel.
                  Borje's code works though.
                  Last edited by Rodney Hicks; 6 Apr 2017, 03:27 PM. Reason: cross posting
                  Rod
                  "To every unsung hero in the universe
                  To those who roam the skies and those who roam the earth
                  To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

                  Comment


                  • #10
                    Originally posted by Borje Hagsten View Post
                    Solution can be to subclass the graphic window and trap %WM_MOUSEWHEEL there.
                    This issue was known quite awhile ago, as I remember it being discussed on the forum. I have usually just subclassed the graphic control, as Borje points out. HOWEVER, I recently discovered this little quirk, while updating some older code;

                    If the graphic control is NOT the first and/or ONLY control added to the dialog, you WILL get WM_MOUSEWHEEL messages. (PBWin 10.04)

                    I suppose there could be other combinations, but I have a more elaborate dialog with many controls, and that also proves true.

                    I modified the code slightly, so this can be seen clearly in the PBMAIN function.

                    Code:
                    '====================================================================
                    '
                    '  SINE.BAS for PowerBASIC Compiler for Windows
                    '  Copyright (c) 2005 - 2008 PowerBASIC, Inc.
                    '  All Rights Reserved.
                    '
                    '  Scale a GRAPHIC control to pixel-based coordinates
                    '  and draw a sine wave.
                    '
                    '====================================================================
                    
                    #COMPILER PBWIN 10
                    #COMPILE EXE
                    #DIM ALL
                    
                    
                    %IDC_GRAPHIC1 = 110
                    
                    
                    
                    ' Draw a sine wave for 360 degrees
                    '
                    SUB DrawSineWave (BYVAL hDlg AS DWORD, BYVAL ID AS LONG)
                    
                        LOCAL x, y, mp, wh AS LONG, hzRadDeg, Pi AS DOUBLE
                    
                        CONTROL GET CLIENT hDlg, ID TO x, y    ' Client size
                        DIALOG UNITS hDlg, x, y TO PIXELS x, y ' Convert to pixels
                        mp     = y / 2                         ' Midpoint
                        wh     = mp - 2                        ' Wave height
                        Pi     = 4 * ATN(1)                    ' Calculate Pi
                        hzRadDeg = Pi / 180                    ' Degrees to Radians
                    
                        GRAPHIC ATTACH hDlg, ID, REDRAW        ' Use faster, buffered draw
                        GRAPHIC COLOR %BLUE, %WHITE            ' Blue line, white background
                        GRAPHIC CLEAR                          ' Paint the white background
                        GRAPHIC LINE (0, mp) - (x, mp), %GRAY  ' Draw midline
                    
                        y = SIN(hzRadDeg) * mp                 ' Calculate start point
                        GRAPHIC SET POS (0, mp)                ' Set start position
                    
                        FOR x = 0 TO 360                       ' Run a full circle loop
                            y = SIN(hzRadDeg * x) * wh         ' y-pos for each degree
                            GRAPHIC LINE STEP - (x, mp + y)    ' Draw line
                        NEXT
                        GRAPHIC REDRAW                         ' Show it all
                    
                        ' Finally, tell what is drawn in dialog caption.
                        DIALOG SET TEXT hDlg, "Sine wave"
                    
                    END SUB
                    
                    
                    
                    ' Main dialog callback procedure
                    '
                    CALLBACK FUNCTION DlgProc () AS LONG
                        LOCAL w, h AS LONG
                        SELECT CASE CB.MSG
                    
                        CASE %WM_INITDIALOG   ' <- Sent right before the dialog is shown
                          DIALOG  GET CLIENT CB.HNDL TO w, h  ' Get client size
                          DIALOG UNITS CB.HNDL, w, h TO PIXELS w, h
                          GRAPHIC ATTACH CB.HNDL, %IDC_GRAPHIC1
                          GRAPHIC SCALE (0, 0) - (w, h)   ' Scale to pixel coordinate system
                    
                        DrawSineWave CB.HNDL, %IDC_GRAPHIC1
                        CASE %WM_COMMAND      ' <- A control is calling
                            SELECT CASE CB.CTL  ' <- Look at control's id
                    
                            CASE %IDCANCEL
                                IF CB.CTLMSG = %BN_CLICKED THEN ' Exit on Esc
                                    DIALOG END CB.HNDL
                                END IF
                    
                            END SELECT
                    
                    
                          #IF -1
                          CASE %WM_MOUSEWHEEL
                    
                             DIM i_CALL  AS STATIC LONG
                    
                             '  Process dynamic zoom using the mousewheel
                             SELECT CASE CB.WPARAM
                                CASE < 00   '  Roll back
                    
                                   i_CALL  -= 10
                    
                                CASE > 00   '  Roll fore
                    
                                   i_CALL  += 10
                    
                             END SELECT
                    
                             DIALOG SET TEXT   CB.HNDL  , "Mouse wheel " + STR$(i_CALL)
                          #ENDIF
                    
                    
                        END SELECT
                    
                    END FUNCTION
                    
                    
                    
                    ' Program entry point
                    '
                    FUNCTION PBMAIN () AS LONG
                    
                        LOCAL hDlg AS DWORD
                    
                        DIALOG NEW 0, "Sine wave",,, 180, 100, %WS_OVERLAPPED OR %WS_BORDER OR %WS_CLIPCHILDREN OR %WS_VISIBLE OR %DS_MODALFRAME OR _
                            %WS_CAPTION OR %WS_SYSMENU OR %WS_MAXIMIZEBOX OR %WS_THICKFRAME, _
                            %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
                    
                        CONTROL ADD TOOLBAR,   hDlg, 1000, "", 1, 1, 1, 1 '<--if you rem this out, WM_MOUSEWHEEL messages stop.
                    
                        CONTROL ADD GRAPHIC, hDlg, %IDC_GRAPHIC1, "", 0, 0, 180, 100, %WS_CHILD OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %WS_BORDER OR %SS_SUNKEN
                    
                        'CONTROL ADD TOOLBAR,   hDlg, 2000, "", 1, 1, 1, 1 '<--doesn't matter either way if rem'd out
                    
                        DIALOG SHOW MODAL hDlg, CALL DlgProc
                    
                    END FUNCTION
                    "Show me a young Conservative and I'll show you someone with no heart. Show me an old Liberal and I'll show you someone with no brains." ― Winston Churchill
                    "Socialism is the philosophy of failure, the creed of ignorance and the gospel of envy." ― Winston Churchill

                    Comment


                    • #11
                      Interesting, Doug. Even changing toolbar to Label in your example makes it work. Funny "feature" there..

                      Comment


                      • #12
                        Thanks for the information and support. The example works as shown but my code is still not triggering with the method. I need to study further.

                        Comment


                        • #13
                          Hi Dean,

                          This problem has been raised before, eg in this posting by Gary.
                          Unexpected things can happen when the Graphic Control has input focus.

                          PB Help Says:
                          The "tab-order" of controls (also known as the "z-order") is determined by the order that DDT controls are created at run-time.
                          That is, the first control added to a dialog is the first control in the z-order, the second control added is second, and so forth.
                          When a dialog is initially displayed, keyboard focus is automatically given to the first control in the z-order that has the %WS_TABSTOP
                          style.
                          The Graphic control in your example is the only control on the Dialog.
                          It is created with a default style that includes %WS_TABSTOP (though not shown in PBHelp).

                          Just adding another control ahead of the Graphic control in your example will not help unless it also has %WS_TABSTOP

                          A Graphic Control will normally 'eat' some keys - eg. the Tab, Esc and Enter keys, when it has Input focus.
                          The effect is that if input focus is given to the Graphic Control (eg by Tabbing), it will stay there until another Control is clicked with the mouse.
                          (Neither %IDOK or %IDCANCEL Dialog messages are sent to the Dialog Proc when the Enter Or Esc keys are pressed if the Graphic control has focus).

                          The Graphic control also grabs %WM_MOUSEWHEEL messages when it has focus input.

                          Normally a WM_MOUSEWHEEL message is sent to the focus control when the mouse wheel is rotated. It seems that PB Graphic controls do not allow the message to drop through to DefWindowProc where it would be "propagated up the parent chain until it finds a window that processes it".
                          (See MSDN https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx)

                          If you don't need keyboard input to the Graphic control you can avoid these unwanted effects by making sure it's not at the top of the z-order and by modifying it's style to avoid %WS_TABSTOP.
                          eg
                          Code:
                          CONTROL ADD GRAPHIC, hDlg, %IDC_GRAPHIC1, "", 0, 0, 180, 100, %WS_VISIBLE
                          (Avoid using %SS_Notify too).

                          If you do need user input to the graphic control, these behaviours can modified by SubClassing the Graphic control instead.
                          Rgds, Dave

                          Comment


                          • #14
                            I stumbled upon a mousewheel instruction ( %WM_Mousewheel ) not responding in a dialog ( dialog with graphic control and a button ) not responding as it should behave .
                            In the callback function the "CASE %WM_Mousewheel" is used and also "%WM_COMMAND AND CB.CTLMSG = %BN_CLICKED ". The funny thing is that the Mousewheel doesn't seem to react if no button was pressed before . No idea why this happens . I'll post the code .

                            Comment


                            • #15
                              Not clear to me what you are doing to cause a problem. WM_Mousewheel on dialog works for me.
                              Code:
                              #compile exe
                              #dim all
                              %ID_ExitBtn        = 1001
                              %ID_DistanceTxtBx  = 1101
                              %ID_KeyButtonTxtBx = 1102
                              %ID_PosX_TxtBx     = 1103
                              %ID_PosY_TxtBx     = 1104
                              %ID_DistanceLbl    = 1105
                              %ID_KeyButtonLbl   = 1106
                              %ID_PosX_Lbl       = 1107
                              %ID_PosY_Lbl       = 1108
                              callback function DlgCB() as long
                                select case as long cb.msg
                                  case %wm_mousewheel
                                    control set text cb.hndl, %ID_DistanceTxtBx, hex$(hi(word, cb.wparam), 4)
                                    control set text cb.hndl, %ID_KeyButtonTxtBx, hex$(lo(word, cb.wparam), 4)
                                    control set text cb.hndl, %ID_PosX_TxtBx,    hex$(lo(word, cb.lparam), 4)
                                    control set text cb.hndl, %ID_PosY_TxtBx,    hex$(hi(word, cb.lparam), 4)
                                  case %wm_command
                                    if cb.ctl = %ID_ExitBtn and cb.ctlmsg = %bn_clicked then
                                      dialog end cb.hndl
                                    end if
                                end select
                              end function
                              function pbmain () as long
                                local hDlg as dword
                                dialog default font "MS Sans Serif", 10, 0, 1
                                dialog new 0, "WM_MouseWheel", , , 110, 100 to hDlg
                                control add label, hDlg,   %ID_DistanceLbl, "Distance",          2, 2, 30, 12
                                control add textbox, hDlg, %ID_DistanceTxtBx, "",                2,14, 30, 12
                                control add label, hDlg,   %ID_KeyButtonLbl, "Key/Button Code", 35, 2, 100, 12
                                control add textbox, hDlg, %ID_KeyButtonTxtBx, "",              35,14, 30, 12
                                control add label,  hDlg,  %ID_PosX_Lbl,     "Pos X",            2,28, 30, 12
                                control add textbox, hDlg, %ID_PosX_TxtBx,   "",                 2,40, 30, 12
                                control add label, hDlg,   %ID_PosY_Lbl,     "Pos Y",           35,28, 30, 12
                                control add textbox, hDlg, %ID_PosY_TxtBx,   "",                35,40, 30, 12
                                control add button, hDlg, %ID_ExitBtn, "Exit",                  15,54, 30, 15
                                dialog show modal hDlg call DlgCB
                              end function
                              For ref: https://docs.microsoft.com/en-us/win.../wm-mousewheel

                              Cheers,
                              Dale

                              Comment


                              • #16
                                Indeed Dale ,
                                your code works , I've tried .
                                My code doesn't behave as I expect .

                                Code hereby is the skeleton of a simulation . Actions in the subroutines are removed .

                                IN this simulation : one should SET a dynamical system , then START the system ( pressing the buttons )
                                Once the system has started one can change the speed of the simulation using the mousewheel .
                                Problem is the mousewheel action doesn't start after the start button has been pushed
                                ( One can see the action of the wheel looking at the label ....) .

                                However : the mousewheel starts under 2 conditions ( I don't understand why ) ;

                                1. When we quote out the disabling of the start button after the start button has been pressed . ( See note in the code )
                                2. When we push another button ( such as "save" ) , then the mousewheel comes to live .

                                I do not want to activate the mousewheel asking the user to push a special button , and do not understand why the mousewheel queue reacts the way it does.

                                I tried to subclass the graphic as in the code above , but without succes .

                                Someone any idea what's wrong ?


                                Code:
                                '
                                
                                #COMPILE EXE     'code should compile under PBWin10 and 9 ' For PBWin9 unquote the font statement and the unicode statement
                                #DIM ALL
                                #DEBUG ERROR ON
                                
                                '%Unicode=1
                                #INCLUDE "Win32API.inc"
                                
                                GLOBAL hDlg ,hfont       AS DWORD                            'screen and picture
                                GLOBAL scrW&,scrH&,sxBeg&,syBeg&,scrSq&,midx&,midy&          'screen data
                                GLOBAL fontname$
                                GLOBAL scrscale,time,dt,dt2                     AS SINGLE
                                GLOBAL solving%
                                GLOBAL dimension,velsim                         AS SINGLE
                                
                                '-----------------------------------------------------------------------------------------
                                %ID_OutputScreen = 500
                                %ID_Start=110
                                %ID_Stop=115
                                %ID_Set=120
                                %ID_Exit=150
                                %ID_Label=160
                                %ID_Timer=600
                                %ID_LabelTime=200
                                %ID_Help=300
                                %ID_Infobar=310
                                %ID_Activ=320
                                
                                '-----------------------------------------------------------------------------------------
                                FUNCTION PBMAIN() AS LONG
                                   FONT NEW fontname$ ,11, 0, 0, 0, 0 TO hfont
                                
                                   scrW& = GetSystemMetrics (%SM_CXSCREEN)/3*3          'get users screen settings , no resize
                                   scrH& = GetSystemMetrics (%SM_CYSCREEN)/3*3          'get users screen settings , no resize
                                   sxBeg&=100:syBeg&=120                                'define the output window
                                
                                   LOCAL dsx&:dsx&=80                           'parameters for positioning of controls
                                   LOCAL lc&,tc&,dsy&,llc&,dhc&                 'parameters for positioning of controls
                                   LOCAL lc2&,lc3&                              'parameters for positioning of controls
                                    lc&=10 : tc&=35:dsy&=25:llc&=90:dhc&=25
                                    lc2&=110 : lc3&=300
                                
                                   DIALOG DEFAULT FONT fontname$
                                   DIALOG NEW PIXELS, 0, "fk Peendulum Simulation   ",0,0,scrW&,scrH&,%WS_BORDER OR %WS_CAPTION OR %WS_SYSMENU OR %WS_MINIMIZEBOX, 0 TO hDlg
                                        DIALOG SET COLOR hDlg, %WHITE,%GRAY
                                
                                        CONTROL ADD BUTTON, hDlg, %ID_Start, "Start",               lc3&+1*dsx&,  35,     70,20,%WS_DISABLED
                                        CONTROL ADD BUTTON, hDlg, %ID_Stop , "Stop",                lc3&+2*dsx&,  35,     70,20,%WS_DISABLED
                                        CONTROL ADD BUTTON, hDlg, %ID_Set, "Set",               lc3&+0*dsx&,  35,     70,20
                                        CONTROL ADD BUTTON, hDlg, %ID_Exit,  "Exit",                lc3&+3*dsx&,  35,     70,20
                                        CONTROL ADD BUTTON, hDlg, %ID_Help,  "Help",                lc3&+2*dsx&,  60,     70,20,%WS_BORDER
                                        CONTROL ADD LABEL, hDlg, %ID_LabelTime,  "Time",            lc3&+0*dsx&,  85,     70,20 ,%SS_CENTER
                                        CONTROL ADD LABEL, hDlg, %ID_Infobar,"  Please Press set  ",       lc3&+2*dsx&,  85,     300,20 ,%SS_CENTER
                                        CONTROL ADD BUTTON, hDlg, %ID_Activ   ,  "..wheel..",         lc3&+1*dsx&,  85,     70,20
                                        CONTROL ADD GRAPHIC, hDlg, %ID_OutputScreen, "", sxBeg,syBeg,scrW&-sxBeg&,scrH&-syBeg&, %WS_VISIBLE   'screen to represent
                                        GRAPHIC SET FONT hfont
                                        GRAPHIC ATTACH hdlg, %ID_OutputScreen,REDRAW
                                        GRAPHIC CLEAR %GRAY
                                   DIALOG SHOW MODAL hDlg CALL DlgOutputScreen
                                
                                END FUNCTION
                                '-----------------------------------------------------------------------------------------
                                CALLBACK FUNCTION DlgOutputScreen() AS LONG
                                   LOCAL  started%
                                   LOCAL hHelpMe AS LONG
                                   LOCAL tempres AS LONG
                                   LOCAL w_ThumbTrack     AS LONG
                                   SELECT CASE CB.MSG
                                       CASE %WM_INITDIALOG 'Just a timer
                                          SetTimer(CB.HNDL, %ID_Timer, 1, BYVAL %NULL)   'uses callback messages
                                       '--------------------------
                                       CASE %WM_TIMER
                                          IF solving%=0 AND started%=0 THEN
                                            Resetting    ' in order to show initial state
                                          END IF
                                
                                          IF solving%=1 THEN
                                            Solve
                                          END IF
                                
                                          GRAPHIC REDRAW
                                       '--------------------------
                                       CASE %WM_MOUSEWHEEL
                                            SELECT CASE HI(INTEGER,CB.WPARAM)
                                                CASE > 0  : velsim =velsim*1.05
                                                CASE < 0  : velsim =velsim*0.95
                                            END SELECT
                                       '--------------------------
                                       CASE %WM_COMMAND AND CB.CTLMSG = %BN_CLICKED     'Here is the control with the buttons
                                           SELECT CASE CB.CTL
                                                CASE %ID_Set
                                                     CONTROL SET TEXT hDlg,%ID_Infobar, "Setting  "
                                                     Solving%=0: started%=0
                                                     Resetting
                                                     CONTROL ENABLE hDlg, %ID_Start
                                
                                                CASE %ID_start
                                                     CONTROL SET TEXT hDlg,%ID_Infobar, "Solving Now "
                                                     Solving%=1:started%=1
                                                     Solve
                                                     CONTROL ENABLE hDlg, %ID_Stop
                                                     CONTROL DISABLE hDlg, %ID_Start   ' IF WE QUOTE OUT THE MOUSEWHEEL RESPONDS!!!!
                                
                                                CASE %ID_Stop
                                                     CONTROL SET TEXT hDlg,%ID_Infobar, " Stopped  "
                                                     Solving%=0:started%=0
                                                     CONTROL DISABLE hDlg, %ID_Stop
                                                     CONTROL ENABLE hDlg, %ID_Start
                                
                                                CASE %ID_Help
                                                     THREAD CREATE HelpMe(0) TO hHelpMe
                                                     THREAD CLOSE hHelpMe TO hHelpMe
                                
                                                CASE %ID_Exit
                                                    DIALOG END hdlg
                                
                                            END SELECT
                                    '--------------------------
                                    END SELECT
                                END FUNCTION
                                
                                '-----------------------------------------------------------------------------------------
                                SUB Resetting
                                    velsim = 1
                                    Plotpendulum
                                    GRAPHIC REDRAW
                                END SUB
                                '-----------------------------------------------------------------------------------------
                                SUB Solve
                                    LOCAL dt           AS SINGLE
                                    dt=0.01*velsim
                                    time=time+dt
                                
                                    CONTROL SET TEXT  hdlg, %ID_Infobar, STR$(velsim)
                                    Plotpendulum
                                END SUB
                                
                                '-----------------------------------------------------------------------------------------
                                SUB Plotpendulum
                                    CONTROL SET TEXT hDlg,%ID_LabelTime, FORMAT$(Time,"##.#")+" s"
                                    GRAPHIC REDRAW
                                END SUB
                                
                                '-----------------------------------------------------------------------------------------
                                'Helpfunction
                                THREAD FUNCTION HelpMe(BYVAL dummy AS LONG) AS LONG
                                    GRAPHIC REDRAW
                                END FUNCTION

                                Comment


                                • #17
                                  I was trying to figure out why clicking on button %ID_Activ (with text "..wheel..") allowed wheel to work when it is not in the callback. It is because clicking on it moves focus from Start button which is made disabled in the callback. Added one line of code (see below) so WM_MouseWheel messages don't "disappear".
                                  Code:
                                                  case %ID_start
                                                       control set text hDlg,%ID_Infobar, "Solving Now "
                                                       Solving%=1:started%=1
                                                       Solve
                                                       control enable hDlg, %ID_Stop
                                                       control disable hDlg, %ID_Start   ' IF WE QUOTE OUT THE MOUSEWHEEL RESPONDS!!!!
                                                       control set focus hDlg, %ID_Stop '<<=== set focus other than disabled
                                  One more thing (for now); I think you should not do commands to controls created in one thread (main thread in this case) from another thread (see bottom of your code). Have thread DIALOG POST custom message (WM_USER + 500 or + 501, etc etc) Put GRAPHIC REDRAW in callback for that message. Repeat I think.

                                  Cheers,
                                  Dale

                                  Comment


                                  • #18
                                    Very gratefull for your help Dale ! The dialog now works ats it should . Didn't thought myself about the focus . Thanks .

                                    Comment


                                    • #19
                                      I'm surprised the "Control Set Focus ' does the trick redirecting the Mousewheel "attention" , now that I read in the help file that Control set Focus sets the focus for the keyboard . Not a word about the Mousewheel .
                                      Amazing this also works for the Mousewheel .

                                      Playing with it I also noticed :
                                      1. Control set Focus works also if focus is set to a LABEL ( doesn't has to be a Button ) .
                                      2. When the dialog has some TRACKBARS , which attract the attention of the mousewheel , also the Control set Focus gives the focus of the mousewheel back .

                                      Comment


                                      • #20
                                        With focus on a DISABLED, repeat disabled, control the messages mouse and keyboard are ignored/disappear. Moving focus to somewhere NOT DISABLED (on the dialog) allows intercept/sending of the messages.

                                        In Frank's code the Start button had the focus because it was just clicked to start a run. It is then disabled and Stop button is enabled, making Stop convenient. PB Help may not have mentioned mouse, but MSDN for WM_MOUSEWHEEL says the messages go to the window with the focus. Controls are child windows with specific properties. So yeah, it does not have to be a button, but it must not be disabled.

                                        Cheers,
                                        Dale

                                        Comment

                                        Working...
                                        X