CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2008
    Posts
    214

    c++ winapi - Dialog Resize in Main Window

    I have a dialog created at creation time:
    Code:
    //WM_CREATE
    CreateDialog(hInst, MAKEINTRESOURCE(id_Dialog), hwnd, reinterpret_cast<DLGPROC>(DlgProc));
    
    //.rc
    id_Dialog DIALOGEX 1, 1, 1, 1 
    STYLE WS_CHILD | WS_VISIBLE | WS_BORDER
    FONT 8, "MS Shell Dlg", 400, 0, 0x1
    BEGIN
        EDITTEXT        IDC_EDIT2,155,30,198,71,ES_AUTOHSCROLL
    END
    I would like to resize the dialog like everything else but without making it an HWND
    Code:
    							MoveWindow(progTreeview, 0, 30, 150, HIWORD(lParam)-50, TRUE);
    							MoveWindow(progToolbar, 0, 0, LOWORD(lParam), 20, TRUE);
    							MoveWindow(progStatus, 0, HIWORD(lParam)-20, LOWORD(lParam), 20, TRUE);
    							MoveWindow(progTab, 155, 30, LOWORD(lParam)-155, HIWORD(lParam)-50, TRUE);
                                //MoveWindow(progEdit, 2, 22, LOWORD(lParam)-159, HIWORD(lParam)-75, TRUE);
    and resize the EditBox in the dialog too.

    Any Ideas? Thanks.

  2. #2
    Join Date
    Dec 2003
    Location
    Syracuse, NY
    Posts
    400

    Re: c++ winapi - Dialog Resize in Main Window

    I don't understand what you mean by "without making it an HWND"

    It is a HWND.

    Resize the control in the dialogs procedure in the message WM_SIZE or WM_SIZING.
    "Windows programming is like going to the dentist: You know it's good for you, but no one likes doing it."
    - Andre LaMothe

    DLL For Beginners(UPDATED)
    Please use CODE tags
    Rate me if I've helped.

  3. #3
    Join Date
    Apr 2008
    Posts
    214

    Re: c++ winapi - Dialog Resize in Main Window

    The Main Window that contains the Dialog is HWND hwnd. I should also point out that the dialog is inside the hwnd, not a popup.

    In my program, I will be creating more than one dialog with the same code:

    Code:
    CreateDialog(hInst, MAKEINTRESOURCE(id_Dialog), hwnd, reinterpret_cast<DLGPROC>(DlgProc));
    to make the Dialog a HWND, I would put:

    Code:
    HWND progDialog = CreateDialog(hInst, MAKEINTRESOURCE(id_Dialog), hwnd, reinterpret_cast<DLGPROC>(DlgProc));
    So no, the dialog is not an HWND until I make it an HWND.

    So, if it was an HWND, I would not be asking how to resize it, and would be able to resize it here, along with everything else:

    Code:
    //WM_SIZE
    MoveWindow(progTreeview, 0, 30, 150, HIWORD(lParam)-50, TRUE);
    MoveWindow(progToolbar, 0, 0, LOWORD(lParam), 20, TRUE);
    MoveWindow(progStatus, 0, HIWORD(lParam)-20, LOWORD(lParam), 20, TRUE);
    MoveWindow(progTab, 155, 30, LOWORD(lParam)-155, HIWORD(lParam)-50, TRUE);
    //MoveWindow(progEdit, 2, 22, LOWORD(lParam)-159, HIWORD(lParam)-75, TRUE);
    Last edited by zaryk; December 8th, 2008 at 07:30 AM.

  4. #4
    Join Date
    Aug 2008
    Location
    Germany / NRW
    Posts
    37

    Re: c++ winapi - Dialog Resize in Main Window

    I'm really confused.
    Regardless if you assign the return value of CreateDialog, it returns a HWND.
    If you just do not assign this value to a variable you do not have a direct access to this window, unless you are searching for it with EnumChildWindows for instance.

    But why would you search for some handle that you create on your own?
    But I guess I just didn't understand what you are really looking for.

  5. #5
    Join Date
    Apr 2008
    Posts
    214

    Re: c++ winapi - Dialog Resize in Main Window

    Is there anyway to resize a dialog or any control at all based on the id of the dialog or control??

  6. #6
    Join Date
    Aug 2008
    Location
    Germany / NRW
    Posts
    37

    Re: c++ winapi - Dialog Resize in Main Window

    I will not ask why you don't just use the handle you already could have.
    So I'll try to give an answer to your question.

    If you don't know the dialogs or the controls handle, there are some api functions to receive it.

    I guess the easiest way to accomplish a resize a window (dialogs and controls are windows indeed) is to use SetWindowPos().
    So, this function needs a window handle (HWND) to identify the window it should operate on.

    So you refuse to use the handle you receive by creating a dialog/control. You have to use another
    function to get those handles. GetDlgItem() will return the window handle of a control in your dialog if you pass the owning handle plus the control ID.

    To get the handle of a dialog it depends if it's a child or top level window.
    If the dialog you want to resize is a top level window you can just use FindWindow() or FindWindowEx() if you know it's class name or window title. If the dialog is a child window you either need to use FindWindowEx() or EnumChildWindows() from the parent window.

    hope this helps,
    Andy

  7. #7
    Join Date
    Apr 2008
    Posts
    214

    Re: c++ winapi - Dialog Resize in Main Window

    Thanks.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured