在运行时的c ++ Windows API调整大小窗口?

Geo*_*Shg 4 height winapi resize window

如何在单击按钮时在运行时调整全局hwnd变量的大小?

或者只是在运行时调整窗口大小的任何方法.即

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
 }



}

}
Run Code Online (Sandbox Code Playgroud)

Jer*_*fin 8

MoveWindow或者SetWindowPos(如果你想做的不仅仅是调整大小,后者更有用).

在这两种情况下,您不仅可以指定左上角的位置,还可以指定右下角的位置,因此如果您保持左上角的原样,并向右下方移动,则调整窗口大小而不"移动"它.


And*_*ers 8

SetWindowPos(yourhwnd,0,0,0,newWidth,newHeight,SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE);
Run Code Online (Sandbox Code Playgroud)

或者,如果要移动和调整大小,可以使用旧的MoveWindow函数