Re: [GD-Windows] TreeView label editing (+ group box repaint bug)
Brought to you by:
vexxed72
From: Pierre T. <pte...@ag...> - 2007-07-06 14:23:54
|
> Be sure to post what was causing your problems if you figure it out, > it could help someone out in the future.. you never know Yep, will do. I'll try to check this out this week-end. Meanwhile I have another issue with a group box not being repainted correctly... sounds familiar? I found this problem mentioned in the MSDN but the provided solution is less than satisfying, as it produces a really nasty flickering instead. I'm not sure if there is a known standard solution to this? The bug is demonstrated in the code below (creating a group box around a treeview - whose label edition does work :)). The bug is simply that the group box is not repainted correctly when you move another window in front of it. The bug disappears when the parent window is not created with WS_CLIPCHILDREN, but not using this flag is not really an option..... - Pierre #include <windows.h> #include <commctrl.h> #define null 0 static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam) { switch(uMessage) { case WM_SYSKEYUP: case WM_SYSKEYDOWN: return 0; case WM_NOTIFY: { const NMHDR* nmhdr = (NMHDR*)lParam; if(nmhdr->code == TVN_BEGINLABELEDIT) { LPNMTVDISPINFO ptvdi = (LPNMTVDISPINFO)lParam; return 0; } if(nmhdr->code == TVN_ENDLABELEDIT) { LPNMTVDISPINFO ptvdi = (LPNMTVDISPINFO)lParam; return TRUE; } } break; case WM_CLOSE: case WM_DESTROY: ::PostQuitMessage(0); return 0; } return ::DefWindowProc(hwnd, uMessage, wParam, lParam); } static void* AddItem(HWND hwnd, void* parent, const char* item) { TV_ITEM tvItem; tvItem.mask = TVIF_TEXT; tvItem.pszText = (LPSTR)item; tvItem.cchTextMax = 256; HTREEITEM hParent; if(!parent) hParent = TVI_ROOT; else hParent = (HTREEITEM)parent; TV_INSERTSTRUCT tvInsert; tvInsert.hParent = hParent; tvInsert.hInsertAfter = TVI_LAST; tvInsert.item = tvItem; return TreeView_InsertItem(hwnd, &tvInsert); } static void CreateGroupBox(int x, int y, int w, int h, HWND parent) { HWND handle = ::CreateWindowEx( 0, "BUTTON", "Group box", WS_VISIBLE | WS_CHILD | BS_GROUPBOX, x, y, w, h, parent, (HMENU)null, (HINSTANCE)GetModuleHandle(null), null ); ::SendMessage(handle, WM_SETFONT, (WPARAM) (HFONT) ::GetStockObject(ANSI_VAR_FONT), MAKELPARAM (TRUE, 0)); } int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX WndClass; WndClass.cbSize = sizeof(WNDCLASSEX); WndClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS; WndClass.lpfnWndProc = WndProc; WndClass.cbClsExtra = 0; WndClass.cbWndExtra = 0; WndClass.hInstance = (HINSTANCE)GetModuleHandle(null); WndClass.hIcon = null; WndClass.hCursor = ::LoadCursor(null, IDC_ARROW); WndClass.hbrBackground = (HBRUSH)COLOR_WINDOW; WndClass.lpszMenuName = null; WndClass.lpszClassName = "IceGUIClass"; WndClass.hIconSm = null; if(!::RegisterClassEx(&WndClass)) return false; ::InitCommonControls(); ////////// DWORD Style = WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN; HWND handle = ::CreateWindowEx( 0, "IceGUIClass", "Label", Style, 10, 10, 640, 480, null, (HMENU)null, (HINSTANCE)GetModuleHandle(null), null ); ::ShowWindow(handle, SW_SHOW); ////////// DWORD TVStyle = TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_SHOWSELALWAYS | WS_VISIBLE | WS_CHILD; TVStyle |= TVS_EDITLABELS; HWND TVHandle = ::CreateWindowEx( WS_EX_CLIENTEDGE, WC_TREEVIEW, "", TVStyle, 30, 30, 100, 100, handle, (HMENU)0, (HINSTANCE)GetModuleHandle(null), null ); ::SendMessage(TVHandle, WM_SETFONT, (WPARAM) (HFONT) ::GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0)); ::ShowWindow(TVHandle, SW_SHOW); AddItem(TVHandle, null, "Item1"); AddItem(TVHandle, null, "Item2"); AddItem(TVHandle, null, "Item3"); //////////////////////// CreateGroupBox(10, 10, 140, 140, handle); //////////////////////// MSG msg; while (1) { if(::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { if(!::GetMessage (&msg, NULL, 0, 0)) { break; } ::TranslateMessage (&msg); ::DispatchMessage (&msg); } } return 0; } |