dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: [RESOLVED] Draggable dialog without Title Bar (without MFC)

  1. #1
    Join Date
    Dec 2007
    Posts
    14

    [RESOLVED] Draggable dialog without Title Bar (without MFC)

    Hello folks;

    I have a dialog with no title bar, i want to drag/move the dialog by clicking anywhere on it but without using MFC...How can i do that?


    Any help would be appreciated, Thanks.

  2. #2
    Join Date
    Jun 2005
    Posts
    1,255

    Smile Re: Draggable dialog without Title Bar (without MFC)

    I have solved this problem by using a WS_EX_TOOLWINDOW window, e.g.
    Code:
    HWND window_child_create(HWND hwnd, int x, int y)
    {
       HWND new_hwnd;
       char window_title[500];
       int child_window_w, child_window_h;
       WNDCLASS wc;
    
       wc.hInstance     = (HINSTANCE) 0;
       wc.lpfnWndProc   = (WNDPROC) child_window_proc;
       wc.cbClsExtra    = 0;
       wc.cbWndExtra    = 0;
       wc.lpszClassName = "child win 1";
       wc.hIcon         = NULL;
       wc.lpszMenuName  = NULL;
       wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
       wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);;
       wc.style         = CS_HREDRAW | CS_VREDRAW;
       RegisterClass(&wc);
    
       child_window_w = 430; child_window_h = 200;
       strcpy(window_title, "child window");
       new_hwnd = CreateWindowEx(WS_EX_TOOLWINDOW,
                                 wc.lpszClassName,
                                 (LPCTSTR) window_title,
                                 WS_VISIBLE | WS_SYSMENU,
                                 x, y, child_window_w, child_window_h,
                                 hwnd, (HMENU) (NULL), 0, NULL);
    
       ShowWindow(new_hwnd, SW_SHOW);
       return new_hwnd;
    }
    And I create my controls on the fly in this child window, e.g.:
    Code:
       y = 10; h = 20;
       x = 10; w = 35;
       hwnd_st_foo = CreateWindow("static", "ST_FOO",
                                  WS_CHILD | WS_VISIBLE | WS_TABSTOP,
                                  x, y, w, h,
                                  hwnd, (HMENU)(501),
                                  (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
       SetWindowText(hwnd_st_x0, "Foo:");
    
       x += w; w = 50;
       hwnd_ed_foo = CreateWindow("edit", "",
                                  WS_CHILD | WS_VISIBLE | WS_TABSTOP
                                  | ES_LEFT | WS_BORDER,
                                  x, y, w, h,
                                  hwnd, (HMENU)(502),
                                  (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
       sprintf(buf, "%0.2f", foo_double);
       SetWindowText(hwnd_ed_foo, buf);
    There is a thin title bar which is used for moving the window. It is also possible to call SetWindowPos() when you treat the WM_MOUSEMOVE message.

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,602

    Re: Draggable dialog without Title Bar (without MFC)

    Here the sample goes.
    Attached Files Attached Files
    Best regards,
    Igor

  4. #4
    Join Date
    Dec 2007
    Posts
    14

    Re: Draggable dialog without Title Bar (without MFC)

    Thank you so much olivthill and Igor Vartanov ..That helped me a lot.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)