Announcement

Collapse
No announcement yet.

How to drag a dialog around the window?

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

  • How to drag a dialog around the window?

    Anyone have a quick example of how to drag a dialog that has no bar at the top?

    I am assuming any place on the dialog not covered by a control could be the grab point?

  • #2
    Hi David!

    Code:
    #Compile EXE
    #Dim All
    %Unicode=1
    #Include "Win32API.inc"
    Global hDlg As Dword
    
    Function PBMain() As Long
       Dialog New Pixels, 0, "Ruler",300,300,100,100, %WS_Popup To hDlg
       Dialog Show Modal hDlg Call DlgProc
    End Function
    
    CallBack Function DlgProc() As Long
       Select Case Cb.Msg
          Case %WM_ContextMenu
             Dialog End hDlg
          Case %WM_LButtonDown
             If Cb.WParam = %MK_LBUTTON Then SendMessage hDlg, %WM_NCLButtonDown, %HTCaption, ByVal %Null  ' force drag
       End Select
    End Function

    Comment


    • #3
      Gary!! AMAZING!! I would have never figured this out.

      I figured I would have to get the location then set the location. I don't even understand what SendMessage you are sending?? %HTCaption?? What is that.

      Comment


      • #4
        When left mouse button is down in the client area,
        you simulate a left mouse button down in the non client area via WM_NCLBUTTONDOWN.
        You pretend that the mouse is in the title bar via HTCAPTION.

        Code:
        #COMPILE EXE '#Win#
        #DIM ALL
        #REGISTER NONE
        #INCLUDE "Win32Api.inc"
        #RESOURCE MANIFEST, 1, "XPTheme.xml" 'Rem if not needed
        '#RESOURCE ".pbr"
        
        GLOBAL hDlg AS DWORD
        
        '______________________________________________________________________________
        
        FUNCTION HitArea$(BYVAL Hit AS LONG) AS STRING
        
         SELECT CASE Hit
           CASE %HTERROR        : FUNCTION = "Error - HTERROR (-2)"
           CASE %HTTRANSPARENT  : FUNCTION = "HTTRANSPARENT - Transparent - HTTRANSPARENT (-1)"
           CASE %HTNOWHERE      : FUNCTION = "HTNOWHERE - Nowhere - HTNOWHERE (0)"
           CASE %HTCLIENT       : FUNCTION = "HTCLIENT - Client Area (1)"
           CASE %HTCAPTION      : FUNCTION = "HTCAPTION - Caption (2)"
           CASE %HTSYSMENU      : FUNCTION = "HTSYSMENU - SysMenu (3)"
           CASE %HTGROWBOX      : FUNCTION = "HTGROWBOX - Grow box - size (4)"
           CASE %HTMENU         : FUNCTION = "HTMENU - Menu (5)"
           CASE %HTHSCROLL      : FUNCTION = "HTHSCROLL - H scroll (6)"
           CASE %HTVSCROLL      : FUNCTION = "HTVSCROLL - V scroll (7)"
           CASE %HTMINBUTTON    : FUNCTION = "HTMINBUTTON - Minimize button (8)"
           CASE %HTMAXBUTTON    : FUNCTION = "HTMAXBUTTON - Maximize button (9)"
           CASE %HTLEFT         : FUNCTION = "HTLEFT - Left edge (10)"
           CASE %HTRIGHT        : FUNCTION = "HTRIGHT - Right edge (11)"
           CASE %HTTOP          : FUNCTION = "HTTOP - Top edge (12)"
           CASE %HTTOPLEFT      : FUNCTION = "HTTOPLEFT - Top-left edge (13)"
           CASE %HTTOPRIGHT     : FUNCTION = "HTTOPRIGHT - Top right edge (14)"
           CASE %HTBOTTOM       : FUNCTION = "HTBOTTOM - Bottom edge (15)"
           CASE %HTBOTTOMLEFT   : FUNCTION = "HTBOTTOMLEFT - Bottom-left edge (16)"
           CASE %HTBOTTOMRIGHT  : FUNCTION = "HTBOTTOMRIGHT - Bottom-right edge (17)"
           CASE %HTBORDER       : FUNCTION = "HTBORDER - Border (18)"
           CASE %HTOBJECT       : FUNCTION = "HTOBJECT - Object (`9)"
           CASE %HTCLOSE        : FUNCTION = "HTCLOSE - Close button (20)"
           CASE %HTHELP         : FUNCTION = "HTHELP - Help button (21)"
           CASE ELSE            : FUNCTION = "Hit unknown(0x" & HEX$(Hit) & ")"
         END SELECT
        
        END FUNCTION
        '______________________________________________________________________________
        
        CALLBACK FUNCTION DlgProc
         STATIC sPrefix AS STRING
        
         SELECT CASE CBMSG
        
           CASE %WM_LBUTTONDOWN
             IF CBWPARAM = %MK_LBUTTON THEN
               sPrefix = "Simulate "
               SendMessage(hDlg, %WM_NCLBUTTONDOWN, %HTCAPTION, BYVAL %NULL) 'Simulate click down on caption
               sPrefix = "Real "
             END IF
        
           CASE %WM_NCLBUTTONDOWN
             SetWindowText(hDlg, sPrefix & HitArea$(CBWPARAM) & " at " & TIME$)
        
           CASE %WM_CAPTURECHANGED
             IF (GetAsyncKeyState(%VK_LBUTTON) AND &H8000) = 0 THEN 'Left mouse buttom up
               SetWindowText(hDlg, "Click in client and non-client and drag")
             END IF
        
          END SELECT
        
        END FUNCTION
        '______________________________________________________________________________
        
        FUNCTION PBMAIN()
         LOCAL hIcon AS DWORD
        
         DIALOG FONT "Segoe UI", 9
         DIALOG NEW %HWND_DESKTOP, "Click in client and non-client and drag", , , 350, 200, _
         %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU OR %WS_THICKFRAME, 0 TO hDlg
        
         hIcon = ExtractIcon(GetModuleHandle(""), "Shell32.dll", 294)
         SetClassLong(hDlg, %GCL_HICON, hIcon)
         SendMessage(hDlg, %WM_SETICON, %ICON_SMALL, hIcon)
        
         DIALOG SHOW MODAL hDlg CALL DlgProc
        
         DestroyIcon(hIcon)
        
        END FUNCTION
        '______________________________________________________________________________
        '

        Comment


        • #5
          Thanks Pierre!

          Comment

          Working...
          X