Subclassing a tree control?
-
Hi, I have a tree view control in a dialog-based app (non-MFC) and I want to use VK_RETURN and VK_ESCAPE to send the TVM_ENDEDITLABELNOW message to end label editing. This is fairly difficult, because the dialog traps all key messages (I think). There is an article on MSDN that covers the basics of how to solve this here: http://support.microsoft.com/default.aspx?scid=kb;en-us;130691 Unfortunately I'm relatively new to coding C++, and I don't know how to go about implementing the advice given in that article. From the article: "To work around this problem, subclass the edit control in response to the TVN_BEGINLABELEDIT notification that is sent by the tree view control when the tree view is about to start label editing for an item. To obtain the edit control's window handle, send the tree view control a TVM_GETEDITCONTROL message. The subclass procedure should handle the WM_GETDLGCODE message by returning DLGC_WANTALLKEYS. This allows the tree view's subclass procedure to handle ESC and ENTER keystrokes." Could someone explain to me how to subclass the tree view control in this way to get this working, or point me to some examples (non-MFC)? Many thanks to anyone who can help, KB
-
Hi, I have a tree view control in a dialog-based app (non-MFC) and I want to use VK_RETURN and VK_ESCAPE to send the TVM_ENDEDITLABELNOW message to end label editing. This is fairly difficult, because the dialog traps all key messages (I think). There is an article on MSDN that covers the basics of how to solve this here: http://support.microsoft.com/default.aspx?scid=kb;en-us;130691 Unfortunately I'm relatively new to coding C++, and I don't know how to go about implementing the advice given in that article. From the article: "To work around this problem, subclass the edit control in response to the TVN_BEGINLABELEDIT notification that is sent by the tree view control when the tree view is about to start label editing for an item. To obtain the edit control's window handle, send the tree view control a TVM_GETEDITCONTROL message. The subclass procedure should handle the WM_GETDLGCODE message by returning DLGC_WANTALLKEYS. This allows the tree view's subclass procedure to handle ESC and ENTER keystrokes." Could someone explain to me how to subclass the tree view control in this way to get this working, or point me to some examples (non-MFC)? Many thanks to anyone who can help, KB
Take a look at the SetWindowLong function in the Microsoft SDK documentation. This function will allow you to set a new wndproc (GWL_WNDPROC) which is what is meant by subclassing. When you change the wndproc all messages will come to your new wndproc...messages you do not handle should be sent to the original wndproc. You should probably be able to find actual example code by searching msdn as well as information regarding subclassing...there is an article called 'Safe subclassing in Win32' that may get you started http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwui/html/msdn\_subclas3.asp