In c++ Windows API resize window during runtime?

17,597

Solution 1

MoveWindow or SetWindowPos (though the latter is more useful if you want to do more than just resize it).

In both cases, you can specify not only the position of the top-left corner, but also the position of the bottom-right corner, so if you leave the top-left corner as-is, and move the bottom-right, you resize the window without "moving" it.

Solution 2

SetWindowPos(yourhwnd,0,0,0,newWidth,newHeight,SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE);

Or if you want to move and resize you can use the older MoveWindow function

Share:
17,597
Geore Shg
Author by

Geore Shg

Updated on June 04, 2022

Comments

  • Geore Shg
    Geore Shg almost 2 years

    How do you resize a global hwnd variable during runtime when a button is clicked?

    Or just any way to resize the window during runtime. i.e.

    HWND hwnd; //global
    int buttonid = 250; // an id for a button
    //also global
    
    
    int WINAPI wWinMain(/*blah blah blah */) {
    
    
    //blah blah blah
    
    hwnd = CreateWindowEx(
        0,
        L"WindowClass",
        L"Window",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT,
        300, 275,
        NULL,
        NULL,
        hInstance,
        NULL
        );
    
        HWND mybutton = CreateWindow(
        L"BUTTON",
        L"Button",
        WS_VISIBLE | WS_CHILD | WS_TABSTOP,
        14, 13,
        250, 200,
        hwnd,
        (HMENU)buttonid,
        hInstance,
        NULL
        );
    
    //blah blah blah
    
    }
    
    
    LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lparam) {
    
    switch(uMsg) {
    
     case WM_COMMAND:
     if(buttonid==wParam) {
     //this is where i want the code for resizing hwnd so when you click the
     //button it resizes the window
     }
    
    
    
    }
    
    }