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, create 'dialog based app' and insert the following code into your ...Dlg.h



class C...Dlg : 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



Comments

  • Good, but just a question

    Posted by Legacy on 02/18/2002 12:00am

    Originally posted by: Matrix

    Can i use that without making a dialog based app, i mean a mfc app, that have dialogs inside and then when minimize get the small button, and not the common system menu?

    Reply
  • Good~~

    Posted by Legacy on 11/29/2001 12:00am

    Originally posted by: nyamnyam

    good

    Reply
  • Thankx..

    Posted by Legacy on 12/03/1999 12:00am

    Originally posted by: seaousak


    Thank you for your bug fix.

    Have a good day!!

    Reply
  • How to avoid displaying of system menu !!

    Posted by Legacy on 12/03/1999 12:00am

    Originally posted by: Michael Kuelshammer

    Everything works nice but when system menu is included in dialog box then there must be a way to destroy systemmenu when minimizing and show it again when maximizing.

    Any solution for this problem ???

    Bye,
    Michael

    Reply
  • What about SDI Applications?

    Posted by Legacy on 08/29/1999 12:00am

    Originally posted by: Cody Mack

    The code is nice for a dialog, but how would I add it to a SDI application?

    Reply
  • Neat, well done...

    Posted by Legacy on 05/17/1999 12:00am

    Originally posted by: Hans Wedemeyer

    Neat...

    Is there anyway to stop the repaint of all desktop icons ?
    The flicker spoils the effect.

    regards
    Hans Wedemeyer

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

Top White Papers and Webcasts

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

Most Popular Programming Stories

More for Developers

RSS Feeds