Announcement

Collapse
No announcement yet.

Moveable Dialog without a Caption bar?

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

    Moveable Dialog without a Caption bar?

    I need to make a floating toolbar (actually a dialog with buttons) as small as possible, yet moveable. Can anyone suggest a way to make it moveable *without* the Caption bar?

    Many TIA

    William Fletcher

    #2
    William;


    Process the

    WM_NCHITTEST

    message yourself

    When the mouse is clicked this message is sent to the window to find out "where" the mouse was clicked. You can fool Windows by returning the


    HTCAPTION value

    when the mouse is clicked on the client area. This will tell windows that the mouse clicked on the Caption bar (which it didn't) and it will allow the window to be dragged by the client area.

    Read the API docs about WM_NCHITTEST


    Chris Boss
    Computer Workshop
    Developer of "EZGUI"
    http://cwsof.com
    http://twitter.com/EZGUIProGuy

    Comment


      #3
      there is a toolbar "demo" in the source code forum which (if i remember)uses a conventional toolbar window approach (ws_ex_toolwindow).
      http://www.powerbasic.com/support/pb...ad.php?t=25000

      if you wish to move a dialog that has no caption bar, then respond to %wm_nchittest messages, and return the value %htcaption. this tricks windows into moving the window as it thinks the caption is being dragged.

      -------------
      lance
      powerbasic support
      mailto:[email protected][email protected]</a>
      Lance
      mailto:[email protected]

      Comment


        #4
        The following also seems to work fine:

        Code:
        CASE %WM_LBUTTONDOWN
          ReleaseCapture
          CALL  SendMessage(hWnd, %WM_SYSCOMMAND, %SC_MOVE, 0)

        Comment


          #5
          Help! - for the WM_NCHITTEST message, how do I "return" the HTCAPTION value?

          Here's my setup:
          Code:
          GLOBAL ghDlg AS LONG
          '----------------------------------------------------
          CALLBACK FUNCTION DlgProc () AS LONG
            SELECT CASE CBMSG
          '    CASE %WM_NCHITTEST
          '     FUNCTION = %HTCAPTION
          '       ---> no effect at all
          '     CALL  SendMessage(ghDlg, %WM_SYSCOMMAND, %SC_MOVE, 0)
          '       ---> constant "Move" cursor
          '     CALL  SendMessage(ghDlg, %WM_SYSCOMMAND, %HTCAPTION, 0)
          '       ---> no effect, it seems
          '     CASE %WM_LBUTTONDOWN
          '       ReleaseCapture
          '       CALL  SendMessage(ghDlg, %WM_SYSCOMMAND, %SC_MOVE, 0)
          '       ---> "Move" cursor appears but Dialog doesn't move
          
                CASE %WM_LBUTTONDOWN
                  SendMessage ghDlg, %WM_NCLBUTTONDOWN, %HTCAPTION, BYVAL %NULL
          '       ---> THIS WORKS!  (...thanks Chris)
          
            END SELECT       
          END FUNCTION  'DlgProc
          '----------------------------------------------------
          FUNCTION PBMAIN () AS LONG
            LOCAL Style AS LONG
            Style = %WS_POPUP OR _
                    %DS_SETFONT OR _
                    %DS_NOFAILCREATE OR _
                    %DS_MODALFRAME OR _
                    %DS_3DLOOK
            DIALOG NEW 0,"",,,160,50,Style TO ghDlg
            DIALOG SHOW MODAL ghDlg, CALL DlgProc
          END FUNCTION  'PBMAIN                   
          '----------------------------------------------------
          Thanks everyone for all the advice!

          William Fletcher



          [This message has been edited by William Fletcher (edited January 24, 2000).]

          Comment


            #6
            William;

            Use the following code in your Dialog procedure:

            Code:
                CASE %WM_LBUTTONDOWN        
                    SendMessage hWnd, %WM_NCLBUTTONDOWN, %HTCAPTION, byval %NULL
            In your sample code you had a ' in front the of the FUNCTION=%HTCAPTION line of code, so it was only a remark.


            Chris Boss
            Computer Workshop
            Developer of "EZGUI"
            http://cwsof.com
            http://twitter.com/EZGUIProGuy

            Comment


              #7
              Thanks Chris - that worked! BTW the ' in front of any code above is to include my failures as a demo in case there were any syntax errors someone else might catch.

              I've updated the code (above) with your suggestion.

              Thanks!

              William Fletcher

              Comment


                #8
                Why are you guys using SendMessage?
                To return a value just do the following

                Code:
                  SELECT CASE lMsg
                    CASE %WM_CREATE
                
                    CASE %WM_NCHITTEST
                
                      FUNCTION = %HTCAPTION 
                      EXIT FUNCTION          <-- This is required so that execution does
                  END SELECT                     not fall through to the default window procedure
                Dominic Mitchell
                Phoenix Visual Designer
                http://www.phnxthunder.com

                Comment


                  #9
                  While it normally doesn't matter which method you use, there is an advantage of using SendMessage. This would allow you to click on a control (ie. Static Label, Bitmap) and then drag the window. You could simulate your own "smaller" Caption bar.

                  By using SendMessage, windows won't care "where" you clicked.
                  Chris Boss
                  Computer Workshop
                  Developer of "EZGUI"
                  http://cwsof.com
                  http://twitter.com/EZGUIProGuy

                  Comment


                    #10
                    Chris;
                    This would allow you to click on a control (ie. Static Label, Bitmap) and then drag
                    the window. You could simulate your own "smaller" Caption bar.
                    You can accomplish all that and much more without using SendMessage.
                    The forms designer part of the package I am writing is as sophisticated as the one
                    in Visual Basic but it does not use SendMessage anywhere. It all depends on hit
                    testing code and a couple of the mouse messages.
                    SendMessage has a major drawback in that you need to have a valid window handle. How
                    would you implement lightweight control such as lines, ellipses, bezier curves and polygons
                    using SendMessage?
                    Dominic Mitchell
                    Phoenix Visual Designer
                    http://www.phnxthunder.com

                    Comment


                      #11
                      william, here is a nice example of putting together a window with
                      a tiny caption bar for your floating toolbar application. you can
                      extract/modify what you need and adjust the caption height to your
                      specifications.

                      http://www.powerbasic.com/support/pb...ad.php?t=22550

                      regards, jules


                      Comment


                        #12
                        Dominic: when I use the following code (inserted above) in PBdll6 the dialog still cannot be moved -
                        Code:
                        CALLBACK FUNCTION DlgProc () AS LONG
                        
                          SELECT CASE CBCTL
                            CASE %ID_OK_BUTTON
                              DIALOG END ghDlg, 1
                          END SELECT
                          
                          SELECT CASE CBMSG
                            CASE %WM_CREATE
                        
                            CASE %WM_NCHITTEST
                              FUNCTION = %HTCAPTION
                              EXIT FUNCTION
                          END SELECT
                        
                        END FUNCTION  'DlgProc
                        Am I doing something wrong?

                        William Fletcher

                        Comment


                          #13
                          Maybe it is a DDT thing !

                          WM_NCHITTEST should work the way you use it if it was in a normal Dialog Procedure (SDK style). You may need to ask someone who knows DDT well, if DDT does any other processing of the message .
                          Chris Boss
                          Computer Workshop
                          Developer of "EZGUI"
                          http://cwsof.com
                          http://twitter.com/EZGUIProGuy

                          Comment


                            #14
                            DDT does withhold %WM_NCHITTEST messages from your dialog callback... the easy solution is to subclass the DDT dialog... with DDT this is really easy as we can use a CALLBACK function for the subclass procedure.

                            Try this example:
                            Code:
                            #COMPILE EXE
                            #INCLUDE "win32api.INC"
                             
                            GLOBAL oldproc AS LONG
                             
                            CALLBACK FUNCTION DlgProc
                              IF CBMSG = %WM_COMMAND AND CBCTL = %IDOK THEN DIALOG END CBHNDL
                              IF CBMSG = %WM_DESTROY THEN SetWindowLong CBHNDL, %GWL_WNDPROC, oldproc
                            END FUNCTION
                             
                            CALLBACK FUNCTION subclass
                              IF CBMSG = %WM_NCHITTEST THEN
                                  FUNCTION = %HTCAPTION
                              ELSE
                                  FUNCTION = CallWindowProc(oldproc, CBHNDL, CBMSG, CBWPARAM, CBLPARAM)
                              END IF
                            END FUNCTION
                             
                            FUNCTION PBMAIN
                                DIALOG NEW 0, "HTCAPTION test", , , 100, 200, %WS_BORDER TO hDlg&
                                CONTROL ADD BUTTON, hDlg&, %IDOK, "&Quit", 30, 90, 40, 14
                                OldProc = SetWindowLong(hDlg&, %GWL_WNDPROC, CODEPTR(subclass))
                                DIALOG SHOW MODAL hDlg&, CALL DlgProc
                            END FUNCTION
                            -------------
                            Lance
                            PowerBASIC Support
                            mailto:[email protected][email protected]</A>
                            Lance
                            mailto:[email protected]

                            Comment


                              #15
                              Thanks Lance! Your code, of course, works. It seems easier to me, however to use:
                              Code:
                                SELECT CASE CBMSG
                                   CASE %WM_LBUTTONDOWN
                                     SendMessage ghDlg, %WM_NCLBUTTONDOWN, %HTCAPTION, BYVAL %NULL
                                END SELECT
                              which also works. Is there anything that makes (your) subclassing method 'better', 'safer', etc. ?

                              Thanks!

                              William Fletcher

                              Comment

                              Working...
                              X
                              😀
                              🥰
                              🤢
                              😎
                              😡
                              👍
                              👎