Win32 c ++在运行时调整createwindow的大小

时间:2013-03-24 20:49:31

标签: c++ button window runtime

我用win32 api c ++编写,并使用mingw。 我希望在运行时调整主窗口大小时调整按钮的大小。 这是我的代码:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
 // BLA BLA BLA
    hwnd = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        szClassName,
        "Main Window",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        800,        // width
        1000,       // height
        HWND_DESKTOP,
        NULL,
        hInstance,
        NULL
    );
  // BLA BLA BLA
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
    switch(Message)
    {
        case WM_CREATE:
        {
         RECT  rect;
        GetClientRect(hwnd, &rect);
        int width = rect.right - rect.left;
        width = width-20;

        HWND button = CreateWindowEx(BS_PUSHBUTTON, "BUTTON", "grafikon",
                           WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                           10, 10, width, 25,
                           hwnd,
                           (HMENU)ID_BUTTON,
                           GetModuleHandle(NULL),
                           0);
      // BLA BLA BLA
}   

所以我想在运行时调整BUTTON的大小。我怎样才能做到这一点? 感谢

1 个答案:

答案 0 :(得分:1)