我想在它自己的wndproc中处理所有ListBox消息,以获得与MainWindow中显示的图像混合的自己的透明项目。不幸的是现在只有WM_PAINT,WM_ERASEBKGND和一些LB_ *消息以及没有WM_DRAWITEM来到ListWndProc
。
代码是:
#include <windows.h>
bool InitInstance(HINSTANCE hInstance, int nCmdShow)
{
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_UPDATER));
wc.hCursor = 0;
//wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wc.hbrBackground = CreatePatternBrush(LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_BITMAP1)));
wc.lpszMenuName = 0;
wc.lpszClassName = szWindowClass;
if(!RegisterClass(&wc)) { return FALSE; }
// MainWindow
g_hWndMain = CreateWindowEx(WS_EX_NOANIMATION,
szWindowClass,
szTitle,
WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
_ASSERT(g_hWndMain != NULL);
if (!g_hWndMain) { return FALSE; }
ShowWindow(g_hWndMain, nCmdShow);
UpdateWindow(g_hWndMain);
主窗口过程:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
{
g_hWndList = CreateWindowEx(0,
_T("LISTBOX"),
NULL,
WS_CHILD | WS_VISIBLE | LBS_NOSEL | LBS_HASSTRINGS,
10, // Top X coord
10, // Top Y coord
600, // Width
400, // Height
hWnd,
NULL,
g_hInst,
NULL);
_ASSERT(g_hWndList != NULL);
defProcList = (WNDPROC)SetWindowLong(g_hWndList, GWL_WNDPROC, (LPARAM)(ListWndProc));
}
}
ListBox wndproc:
LRESULT CALLBACK ListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
case WM_ERASEBKGND:
{
return TRUE;
}
case WM_DRAWITEM:
{
}
break;
}
答案 0 :(得分:3)
WM_DRAWITEM消息
当按钮,组合框,列表框或菜单的可视方面发生更改时,发送到所有者绘制按钮,组合框,列表框或菜单的父窗口。
列表框不应该获取该消息,即使是所有者绘制的。它的父窗口是你的主窗口,它们可以获取它们,这样你就不必将列表框子类化了。