问题描述
大家好!
我想首先感谢所有花时间查看此主题并尝试提供帮助的人。
我在主窗口中有子视图,使背景透明,工作正常,但其物品根本没有涂漆!
我在子类化方面缺乏经验,所以我请更有经验的成员帮我修改下面的代码,这样我就可以得到透明的树形视图,所有节点都正确显示:
Hello everyone!
I would like to start by saying thanks to everyone who takes some time to view this thread and try to help.
I have subclassed tree view in my main window to make his background transparent, which works fine, but its items are not painted at all!
I am inexperienced in subclassing, so I ask more experienced members to help me modify following code, so I can get transparent tree view with all nodes displayed properly:
// variable for storing old window procedure
static WNDPROC wp;
LRESULT CALLBACK wpTree(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps),
hdcMem = CreateCompatibleDC(hdc);
RECT r;
// get tree view's client rectangle
GetClientRect( hWnd, &r );
/* create compatible bitmap, size of tree's client
rectangle */
HBITMAP bmp = CreateCompatibleBitmap( hdc,
r.right - r.left,
r.bottom - r.top ) ,
bmpOld;
bmpOld = (HBITMAP)SelectObject( hdcMem, bmp );
// Blt it and make background transparent
TransparentBlt( hdc, 0, 0,
r.right - r.left,
r.bottom - r.top,
hdcMem, 0, 0,
r.right - r.left,
r.bottom - r.top,
RGB( 0, 0, 0 ) );
// take care for memory leak
SelectObject( hdcMem, bmpOld );
// cleanup
DeleteObject(bmp);
DeleteDC(hdcMem);
EndPaint(hWnd, &ps);
}
return 0L;
case WM_ERASEBKGND:
return 0L;
}
return CallWindowProc( wp, hWnd, message, wParam, lParam );
}
这就是我在主窗口程序中使用子树的方式:
This is how I have subclassed tree in main window procedure:
case WM_CREATE:
{
// create tree view
hwndTV = CreateWindowEx( ... );
// store old procedure
wp = (WNDPROC)GetWindowLongPtr( hwndTV, GWL_WNDPROC);
// subclass tree
SetWindowLongPtr( hwndTV, GWL_WNDPROC, (LONG)wpTree );
// add some nodes to the tree
.
.
.
}
代码示例或代码段会非常有用,但我也很感谢书面说明。
我的工作在MS Visual Studio Express 2008中,在Windows XP上,在C ++中,使用纯WIN32 API。
这就是全部,再次感谢所有试图帮助的人。谢谢非常非常!
Code example, or snippet would be very helpful, but I would also appreciate written instructions as well.
I work in MS Visual Studio Express 2008, on Windows XP, in C++, using pure WIN32 API.
That would be all, again I thank everyone who tries to help.Thank you very very much!
推荐答案
这篇关于当我以这种方式对它进行子类化时,为什么我看不到树视图的节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!