下面的代码可以在创建窗口时改变窗口的背景色:
CWndClassInfo& wci = GetWndClassInfo();
if (wci.m_atom == 0)
{
m_hBr = CreateSolidBrush(0x006600);
wci.m_wc.hbrBackground = m_hBr;
}但,如果在一个程序中基于CWindow,创建多个窗口,则多个窗口将使用同样的背景色。原因是:static有没有其他的方法来改变窗口背景色呢?★ 要求可以做到:不同窗口,不同的初始背景色?注:通过看ATL源码,我想直接调用基类:
ATOM atom = GetWndClassInfo().Register(&m_pfnSuperWindowProc);
return CWindowImplBaseT<CWindow, CControlWinTraits>::Create(NULL, 0U, NULL,
WS_POPUP, WS_EX_TOOLWINDOW | WS_EX_TOPMOST, 0U, atom, 0);
但,失败,因为还是要乃至GetWndClassInfo()。而wci是static的...
晕,为了效率...
请教高人。
CWndClassInfo& wci = GetWndClassInfo();
if (wci.m_atom == 0)
{
m_hBr = CreateSolidBrush(0x006600);
wci.m_wc.hbrBackground = m_hBr;
}但,如果在一个程序中基于CWindow,创建多个窗口,则多个窗口将使用同样的背景色。原因是:static有没有其他的方法来改变窗口背景色呢?★ 要求可以做到:不同窗口,不同的初始背景色?注:通过看ATL源码,我想直接调用基类:
ATOM atom = GetWndClassInfo().Register(&m_pfnSuperWindowProc);
return CWindowImplBaseT<CWindow, CControlWinTraits>::Create(NULL, 0U, NULL,
WS_POPUP, WS_EX_TOOLWINDOW | WS_EX_TOPMOST, 0U, atom, 0);
但,失败,因为还是要乃至GetWndClassInfo()。而wci是static的...
晕,为了效率...
请教高人。
===========
确实是要按不同的背景色来注册窗口。对CreateWindow来说,这是可以做到的。注册之后再频繁的绘制,会占用更多的资源。
// 注册窗口类
WNDCLASSEX wcex;
m_hBr = CreateSolidBrush(0x006600); ★★★★★
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProcStatic;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInst;
wcex.hIcon = LoadIcon(m_hInst, MAKEINTRESOURCE(IDI_MAIN));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = m_hBr; ★★★★★
wcex.lpszMenuName = NULL;
wcex.lpszClassName = STR_ClassName;
wcex.hIconSm = LoadIcon(hInst, (PCTSTR)IDI_SMALL); if (!::RegisterClassEx(&wcex))
{
throw TEXT("RegisterClassEx failed!");
} // 创建窗口
m_hWnd = CreateWindowEx(