How to update the current state for window after showing/hiding controls?
我是一个初学者,今天是学习创建Windows应用程序的第一天。
我有两个按钮。
1 2 3 4 5 6 | #define BUTTON_SW 1 #define BUTTON_SW2 2 HWND Button1; HWND Button2; Button1 = CreateWindow("button","Enter", WS_VISIBLE | WS_CHILD, 215, 10, 40, 25, hwnd, HMENU(BUTTON_SW), NULL, NULL); Button2 = CreateWindow("button","You'll be gone", WS_VISIBLE | WS_CHILD, 260, 10, 95, 25, hwnd, HMENU(BUTTON_SW2), NULL, NULL); |
单击
1 2 3 | LONG style = GetWindowLong(Button2,GWL_STYLE); style = style | WS_VISIBLE; // style = style & ~WS_VISIBLE SetWindowLong(Button2,GWL_STYLE,style); |
这很好。但是,一旦分配了
反之亦然,当我删除
该如何解决?尝试了许多我在网上找到的东西,但无法解决。另外,请不要建议我买一本像样的书,因为我暂时没有钱。
(PS:
1 | ShowWindow(GetDlgItem(Button2, 2), SW_HIDE); |
@Edit: I've noticed that when I minimize the app and maximize it
again, the state of button updates. But how will it automatically
update the state?
这应该工作
1 | ShowWindow(Button2, SW_HIDE); |
或
1 | ShowWindow(GetDlgItem(DialogHWND, BUTTON_SW2), SW_HIDE); |
为了在窗口中反映更改,您必须要求操作系统执行该操作。
了解
请注意,某些操作(例如调整大小或从最小化还原)会自动使操作系统使区域无效并重新绘制区域。
使用:
1 | RedrawWindow(Button2,NULL,NULL,RDW_INVALIDATE | RDW_INTERNALPAINT); |