Drop down a popdown window instead of a dropdown list from a combobox

Environment: VC++ 5.0 , Windows NT 4.0

 

This article explains how to drop down a tool window from a combobox. The dropdown tool window will replace the default dropdown list in an ordinary combobox. The following procedure describes how to go about it:

Step 1:

When the user clicks the arrow button in the combobox, the ON_CBN_DROPDOWN handler gets to have a go at it. ON_CBN_DROPDOWN(IDC_COMBO1, OnDropdownCombo)

Now to disable the default drop down call ShowDropDown() member function of the combobox with the flag set to FALSE.

void CCoolComboDlg::OnDropdownCombo()
{

	// prevent drop down of the combo
	m_CoolCombo.ShowDropDown(FALSE);  

	// Display our own popdown window instead 
	DisplayPopdownWindow(); 
} 

Step 2:

Now it's time to display our pop down window. Make sure you create the window with the extended styles WS_EX_TOPMOST and WS_EX_TOOL_WINDOW. The WS_EX_PALETTE_WINDOW style is optional.

void CCoolComboDlg::DisplayPopdownWindow()
{
	//Get the combo's alignment
	CRect rectCombo;
	m_CoolCombo.GetWindowRect(&rectCombo);

	//if window is already present delete it
	if(m_pWndPopDown) delete m_pWndPopDown;
	
	///Register class and create window
	LPCTSTR lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW);
	m_pWndPopDown = new CPopDownWnd();
	m_pWndPopDown->CreateEx(WS_EX_TOPMOST | WS_EX_TOOLWINDOW|WS_EX_PALETTEWINDOW
	                        lpszClass, 
	                        _T(""),
	                        WS_POPUP | WS_VISIBLE,
	                        rectCombo.left,rectCombo.bottom, 
	                        rectCombo.Width(),200,
	                        m_CoolCombo.GetSafeHwnd(),
	                        NULL,
	                        NULL);
}

Step 3:

Now there is one problem that crops up. Grab the title bar and move the dialog. What happens ?. Our tool window floats freely independent of the dialog. So we need to prevent the user from dragging the dialog. Trapping the non client hit test notifications is the way to go about it. When the user clicks the title bar , a HTCAPTION is returned. To nullify the drag attempt, simply return HTNOWHERE.

UINT CCoolComboDlg::OnNcHitTest(CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	UINT nHitTest =  CDialog::OnNcHitTest(point);
	//HTCAPTION  implies user clicked on the title bar , so return HTNOWHERE 
	return (nHitTest == HTCAPTION) ? HTNOWHERE : nHitTest;
}

That's it. So you now have your own window popping out from the combobox instead of the default list entries.

Last updated: 13 June 1998



Comments

  • louis vuitton evidence sunglasses for women thjahj

    Posted by Achiegaic on 05/16/2013 06:48am

    http://hermesbags.citationguide.net 27497 965631how to identify fake louis vuitton bags louis vuitton outlet store online cheap hermes belts china hermes bags for sale on ebay

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

  • Hybrid cloud platforms need to think in terms of sweet spots when it comes to application platform interface (API) integration. Cloud Velocity has taken a unique approach to tight integration with the API sweet spot; enough to support the agility of physical and virtual apps, including multi-tier environments and databases, while reducing capital and operating costs. Read this case study to learn how a global-level Fortune 1000 company was able to deploy an entire 6+ TB Oracle eCommerce stack in Amazon Web …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds