在C++ Windows API中如何在运行时调整窗口大小?

4
当单击按钮时,如何在运行时调整全局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
 }



}

}
2个回答

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

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


8

MoveWindowSetWindowPos(尽管后者更实用,如果您想要做更多的事情而不仅仅是调整大小)。

在这两种情况下,您不仅可以指定左上角的位置,还可以指定右下角的位置,因此,如果您将左上角保持不变,并移动右下角,则可以调整窗口大小而无需“移动”它。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接