Archived

This topic is now archived and is closed to further replies.

antareus

Treeview holding focus hostage!

Recommended Posts

I have a ''main'' window with a treeview that holds items the user clicks on. When a double click is detected, a new window is opened up:
// WTL

ConversationWindow* newConvo = new ConversationWindow(e.contact);
			newConvo->Create(::GetDesktopWindow(),
				location,
				newConvo->Title().c_str(),
				WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SIZEBOX,
				WS_EX_CLIENTEDGE);
			SetForegroundWindow(newConvo->m_hWnd);
			SetActiveWindow(newConvo->m_hWnd);
The problem is I cannot get it to actually keep the focus on the window. What happens (when I use Spy++) is the window gets the focus and then the main window steals the focus back somehow. It seems like the Treeview needs the focus back to finish updating itself after it runs the handler. Here is my treeview WM_NOTIFY handler:
	LRESULT ContactListWindow::OnNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&)
	{
		NMHDR*	mhdr = reinterpret_cast<NMHDR*>(lParam);
		if(mhdr->code == NM_DBLCLK)
		{
			Node* selectedNode = reinterpret_cast<Node*>(m_treeView.GetSelectedItem().GetData());
			if(selectedNode != 0)
				selectedNode->OnDoubleClick();
		}
		return CFrameWindowImpl<ContactListWindow>::DefWindowProc(uMsg, wParam, lParam);
	}
This URL seems to be what my problem is but I tried implementing it by hooking the TVN_SELCHANGING message to no avail.

Share this post


Link to post
Share on other sites
Here''s what you do.

For whatever reason you can''t transfer the focus away from the Treeview in event handlers. Apparently this shows itself in the .NET framework as well. In Win32 at least, you have to post a user defined message to the parent window that you handle and take your double click action on.

Roundabout way of getting something to work but I''ve seen worse.

Share this post


Link to post
Share on other sites