Changing Dialog like UNIX or LINUX App | CodeGuru

Changing Dialog like UNIX or LINUX App

When I worked on Unix systems, I thought that the Unix applications were so cool !! Therefore, I decided to sumbit this article/code that will enable you to achieve some of the same features regarding the appearance of Windows dialogs that Unix and LINUX programmers/users have come to know and love. Enjoy! First of all, […]

Written By
CodeGuru Staff
CodeGuru Staff
May 17, 1999
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

When I worked on Unix systems, I thought that the Unix applications were so cool !!
Therefore, I decided to sumbit this article/code that will enable you to
achieve some of the same features regarding the appearance of Windows dialogs that
Unix and LINUX programmers/users have come to know and love. Enjoy!

First of all, create ‘dialog based app’ and insert the following code into your …Dlg.h

class CDlg : public CDialog
{
// Construction
public:
	CRect m_rcOldRect;		// for original window position.
	void LargeWindow();		// Recovering original window feature
	bool IsSmall;
	CDC m_dcSmallIcon;	   // CDC for smallIcon
….
// Implementation
protected:
	…
	afx_msg void OnSmallButton();
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnNcLButtonDblClk(UINT nHitTest, CPoint point);
	afx_msg UINT OnNcHitTest(CPoint point);
	…
};

Next insert following code into your …Dlg.cpp
////////////////////////////////////////////////////////////
// Declare Information for ICON.. Global variable!
int ICON_X = 100;		// Small Icon position.
int ICON_Y = 400;
int ICON_WIDTH = 32;	//Small Icon Width.
int ICON_HEIGHT = 32;
int COUNT = 20;
int TIME = 10;
///////////////////////////////////////////////////////////////
// Code for BEGIN_MESSAGE_MAP
BEGIN_MESSAGE_MAP(CSmallDlg, CDialog)
	//{{AFX_MSG_MAP(CSmallDlg)
	…
	ON_BN_CLICKED(IDC_SMALL_BUTTON, OnSmallButton)
	ON_WM_NCLBUTTONDBLCLK()
	ON_WM_NCHITTEST()
	…
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
////////////////////////////////////////////////////////////////////////
// Code for OnPaint method..
void C…Dlg::OnPaint()
{
	if (IsIconic())
	{
		…
	}
	else if ( IsSmall == true)
	{
		CWindowDC dc(this);
		dc.BitBlt(0, 0 ,32, 32, &m_dcSmallIcon, 0,0,SRCCOPY);
		CDialog::OnPaint();
	}
	….
}
/////////////////////////////////////////////////////////////////////////////////
// code for small button
void C…Dlg::OnSmallButton()
{
	CWindowDC dc(NULL);
	dc.SelectStockObject(WHITE_PEN);
	// Declare variable
	CRect m_rcClient;
	GetWindowRect(&m_rcClient);
	GetWindowRect(&m_rcOldRect);
	dc.DPtoLP(&m_rcClient);
	dc.DPtoLP(&m_rcOldRect);
	int differ_x,differ_y;
	int differ_x1, differ_y1;
	dc.BitBlt(ICON_X, ICON_Y, ICON_WIDTH,ICON_HEIGHT, &dc, 0,0,SRCCOPY);	// Draw Icon
	differ_x = (ICON_X – m_rcClient.left)/COUNT;
	differ_y = (ICON_Y – m_rcClient.top)/COUNT;
	differ_x1 = (ICON_X+ICON_WIDTH – m_rcClient.right) /COUNT;
	differ_y1 = (ICON_Y+ICON_HEIGHT – m_rcClient.bottom) /COUNT;
	CRect rect;
	rect = m_rcClient;
	if( ICON_X > m_rcClient.right )
		rect.right = ICON_X;
	if( ICON_Y > m_rcClient.top)
		rect.top = ICON_Y;
	for( int i = 0 ; i < COUNT; i++)
	{
		dc.MoveTo(m_rcClient.left+differ_x*i, m_rcClient.top + differ_y*i);
		dc.LineTo(m_rcClient.right+differ_x1*i,m_rcClient.top + differ_y*i);
		dc.LineTo(m_rcClient.right+differ_x1*i , m_rcClient.bottom + differ_y1*i);
		dc.LineTo(m_rcClient.left+differ_x*i,m_rcClient.bottom + differ_y1*i);
		dc.LineTo(m_rcClient.left+differ_x*i, m_rcClient.top + differ_y*i);


//		dc.Rectangle(m_rcClient.left+differ_x*i, m_rcClient.top + differ_y*i,
//			m_rcClient.right+differ_x1*i , m_rcClient.bottom + differ_y1*i);

		// If you want to draw line between icon and app, insert following comment code.
/*
		dc.MoveTo(m_rcClient.left+differ_x*i,m_rcClient.top + differ_y*i);
		dc.LineTo(ICON_X, ICON_Y);
		dc.MoveTo(m_rcClient.left , m_rcClient.bottom + differ_y1*i);
		dc.LineTo(ICON_WIDTH+ICON_X, ICON_Y);
		dc.MoveTo(m_rcClient.right + differ_x1*i, m_rcClient.top + differ_y*i);
		dc.LineTo(ICON_X+ICON_WIDTH, ICON_Y);
		dc.MoveTo(m_rcClient.right + differ_x1*i, m_rcClient.bottom + differ_y1*i);
		dc.LineTo(ICON_X+ICON_WIDTH, ICON_Y+ ICON_HEIGHT);
*/
		::Sleep(TIME);

	}

	::InvalidateRect(NULL, &rect, FALSE);

	IsSmall = true;

	SetWindowPos(NULL,0,0,ICON_WIDTH, ICON_HEIGHT,SWP_NOMOVE|SWP_NOZORDER);

	MoveWindow(ICON_X, ICON_Y,ICON_WIDTH, ICON_HEIGHT,TRUE);

	OnPaint();

}



////////////////////////////////////////////////////////////////////////
// Code for OnCreate method.
int C...Dlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;


	// Create small bitmap icon..
	CClientDC dc (this);

	m_dcSmallIcon.CreateCompatibleDC(&dc);

	CBitmap bitmap;

	bitmap.LoadBitmap(IDB_BITMAP);
	m_dcSmallIcon.SelectObject(&bitmap);
	bitmap.DeleteObject();
	return 0;

}



//////////////////////////////////////////////////////////////////////////////
// Code for OnNcLButtonDblClk and OnNcHitTest
void C...Dlg::OnNcLButtonDblClk(UINT nHitTest, CPoint point)
{
	if( IsSmall == true)
		LargeWindow();
	else
		CWnd::OnNcLButtonDblClk(nHitTest, point);
}

UINT C...Dlg::OnNcHitTest(CPoint point)
{
	UINT nHitTest = CWnd::OnNcHitTest(point);

	if( nHitTest == HTCLIENT)
		nHitTest = HTCAPTION;
	return nHitTest;
}


/////////////////////////////////////////////////////////////////////////////////
// Code for LargeWindow() function.

void C...Dlg::LargeWindow()
{
	CWindowDC dc(NULL);

	dc.SelectStockObject(WHITE_PEN);

	// Declare variable
	CRect m_rcClient;
	GetWindowRect(&m_rcClient);

	dc.DPtoLP(&m_rcClient);

	ICON_X = m_rcClient.left;
	ICON_Y = m_rcClient.top;

	m_rcClient = m_rcOldRect;

	int differ_x,differ_y;
	int differ_x1, differ_y1;

	dc.BitBlt(ICON_X, ICON_Y, ICON_WIDTH,ICON_HEIGHT, &dc, 0,0,SRCCOPY);

	differ_x = (ICON_X - m_rcClient.left)/COUNT;
	differ_y = (ICON_Y - m_rcClient.top)/COUNT;

	differ_x1 = (ICON_X+ICON_WIDTH - m_rcClient.right) /COUNT;
	differ_y1 = (ICON_Y+ICON_HEIGHT - m_rcClient.bottom) /COUNT;

	CRect rect;
	rect = m_rcClient;

	if( ICON_X > m_rcClient.right )
		rect.right = ICON_X;
	if( ICON_Y > m_rcClient.top)
		rect.top = ICON_Y;
	for( int i = COUNT ; i > 0 ; i–)
	{
		dc.MoveTo(m_rcClient.left+differ_x*i, m_rcClient.top + differ_y*i);
		dc.LineTo(m_rcClient.right+differ_x1*i,m_rcClient.top + differ_y*i);
		dc.LineTo(m_rcClient.right+differ_x1*i , m_rcClient.bottom + differ_y1*i);
		dc.LineTo(m_rcClient.left+differ_x*i,m_rcClient.bottom + differ_y1*i);
		dc.LineTo(m_rcClient.left+differ_x*i, m_rcClient.top + differ_y*i);
		::Sleep(5);
	}
	::InvalidateRect(NULL, &rect, FALSE);
	MoveWindow(m_rcOldRect.left, m_rcOldRect.top,  m_rcOldRect.Width(),m_rcOldRect.Height());
	IsSmall = false;
	InvalidateRect(m_rcOldRect,FALSE);
}

Download demo project – 58 KB

Date Last Updated: May 17, 1999

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.