【问题标题】:In c++ Windows API resize window during runtime?在运行时在 c++ Windows API 中调整窗口大小?
【发布时间】:2011-08-02 08:13:06
【问题描述】:

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



}

}

【问题讨论】:

    标签: winapi resize window height


    【解决方案1】:

    MoveWindowSetWindowPos(如果您想做的不仅仅是调整大小,后者更有用)。

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

    【讨论】:

      【解决方案2】:
      SetWindowPos(yourhwnd,0,0,0,newWidth,newHeight,SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE);
      

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

      【讨论】:

        猜你喜欢
        • 2017-03-08
        • 1970-01-01
        • 2016-01-19
        • 2011-01-22
        • 2012-08-02
        • 1970-01-01
        • 2019-03-25
        • 2013-04-22
        • 2011-10-31
        相关资源
        最近更新 更多