在C ++ Windows API调整大小窗口在运行时? [英] In c++ Windows API resize window during runtime?

查看:188
本文介绍了在C ++ Windows API调整大小窗口在运行时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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
 }



}

}

推荐答案

MoveWindowSetWindowPos(尽管如果要做的事情不仅仅是调整大小,后者更有用).

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.

这篇关于在C ++ Windows API调整大小窗口在运行时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆