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

  • Live Webinar June 2, 2015 - 11 am PST / 2 pm EST Your organization and brand are increasingly digital today, proliferating across websites, media outlets, social networks, search engines, mobile apps, online marketplaces and more. Each digital touch point not only enhances the value of your brand, but also represents far greater risk for your company. They increase opportunities for brand defamation and data leakage; act as discreet places to conspire and collude; and open the door to new security …

  • Employees must exchange sensitive emails with customers and partners. These emails might contain protected health information, protected financial information, or corporate information that should not be made public. Globalscape® Mail Express® allows you to encrypt the emails that it manages so that no one but the sender and recipient--not even the administrator--can view the contents of the email. "Secure the Transfer of Sensitive Emails" is the property of GlobalSCAPE

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date