A Journey 2 Eternity

ComboBox with no borders

Posted on: December 18, 2008

void CMyComboBox::OnPaint()
{
	CPaintDC dc(this);
	CRect rect;
	GetClientRect(rect);

	// draw borders
	dc.Draw3dRect(rect, ::GetSysColor(COLOR_3DSHADOW), ::GetSysColor(COLOR_BTNHIGHLIGHT));
	rect.DeflateRect(1,1);
	
	dc.Draw3dRect(rect, ::GetSysColor(COLOR_3DDKSHADOW), ::GetSysColor(COLOR_BTNFACE));
	rect.DeflateRect(1,1);

	if( (GetStyle() & 0x0000000f) > CBS_SIMPLE) {
		CRect rectBtn=rect;
		rectBtn.left = rectBtn.right – ::GetSystemMetrics(SM_CXHTHUMB);

		BOOL bPressed = FALSE;
		if(GetKeyState(VK_LBUTTON) < 0) {
			CPoint point;
			::GetCursorPos(&point);
			ScreenToClient(&point);

			if(rectBtn.PtInRect(point)) {
				bPressed=TRUE;
			}
		}

		// draw button
		UINT uState = DFCS_SCROLLDOWN;
		uState |= (bPressed ? DFCS_FLAT | DFCS_PUSHED : 0);
		
		dc.DrawFrameControl(rectBtn, DFC_SCROLL, uState );
		rect.right = rectBtn.left;
	}

	if((GetStyle()&0x0000000f)==CBS_DROPDOWNLIST) {
		CString sText;
		GetWindowText(sText);
		if(sText.IsEmpty()) {
			dc.FillSolidRect(rect, ::GetSysColor(COLOR_WINDOW));
		}
	} else {
		// draw border around edit control
		dc.Draw3dRect(rect, ::GetSysColor(COLOR_BTNHIGHLIGHT), ::GetSysColor(COLOR_BTNHIGHLIGHT));
	}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Pages

Categories

December 2008
M T W T F S S
« Sep   Apr »
1234567
891011121314
15161718192021
22232425262728
293031  

Blog Stats

  • 26,968 hits
%d bloggers like this: