+WXLRESULT
+wxTreeCtrl::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
+{
+ // default WM_RBUTTONDOWN handler enters modal loop inside DefWindowProc()
+ // waiting for WM_RBUTTONUP and then sends the resulting WM_CONTEXTMENU to
+ // the parent window, not us, which completely breaks everything so simply
+ // don't let it see this message at all
+ if ( nMsg == WM_RBUTTONDOWN )
+ return 0;
+
+ // but because of the above we don't get NM_RCLICK which is normally
+ // generated by tree window proc when the modal loop mentioned above ends
+ // because the mouse is released -- synthesize it ourselves instead
+ if ( nMsg == WM_RBUTTONUP )
+ {
+ NMHDR hdr;
+ hdr.hwndFrom = GetHwnd();
+ hdr.idFrom = GetId();
+ hdr.code = NM_RCLICK;
+
+ WXLPARAM rc;
+ MSWOnNotify(GetId(), (LPARAM)&hdr, &rc);
+
+ // continue as usual
+ }
+
+ if ( nMsg == WM_CHAR )
+ {
+ // also don't let the control process Space and Return keys because it
+ // doesn't do anything useful with them anyhow but always beeps
+ // annoyingly when it receives them and there is no way to turn it off
+ // simply if you just process TREEITEM_ACTIVATED event to which Space
+ // and Enter presses are mapped in your code
+ if ( wParam == VK_SPACE || wParam == VK_RETURN )
+ return 0;
+ }
+
+ return wxControl::MSWDefWindowProc(nMsg, wParam, lParam);
+}
+