{"id":15,"date":"2013-06-29T09:11:19","date_gmt":"2013-06-29T09:11:19","guid":{"rendered":"https:\/\/praveenkatiyar.wordpress.com\/?p=15"},"modified":"2013-06-29T09:11:19","modified_gmt":"2013-06-29T09:11:19","slug":"creating-a-status-bar-in-a-dialog-box-vc-mfc","status":"publish","type":"post","link":"https:\/\/praveenkatiyar.in\/blog\/index.php\/2013\/06\/29\/creating-a-status-bar-in-a-dialog-box-vc-mfc\/","title":{"rendered":"Creating a status Bar in a Dialog Box ( VC++, MFC)"},"content":{"rendered":"<p>Normally in MFC Applications one can not create a status bar by default, this article shows you how status bar can be created in a dialog box.<\/p>\n<p>Create a Dialog based application, using MFC AppWizard,<\/p>\n<p>compile and make sure that every thing is working fine.<\/p>\n<p>Open \u201cresource.h\u201d<\/p>\n<p>define two identifiers in the file <strong>\u201dresource.h\u201d<\/strong>, for two panes, these identifier will be used to identify two panes in the status bar you are going to create.<\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>#define ID_INDICATOR_PANE&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 106        <br \/>#define ID_INDICATOR_TIME&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 107<\/strong><\/font><\/p>\n<p>define an array of indicators in&#160; DialogBox Source file, let say if you need to create two panes, you need&#160; to define two values as shown below. <\/p>\n<p> <font size=\"1\"><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">     <\/p>\n<p><strong>static UINT BASED_CODE indicators[] =          <br \/>{           <br \/>&#160;&#160;&#160; ID_INDICATOR_PANE,           <br \/>&#160;&#160;&#160; ID_INDICATOR_TIME           <br \/>};<\/strong><\/p>\n<p>   <\/font><\/font>  <\/p>\n<p>Now make the necessary modifications in the Dialog Box\u2019s <strong><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">InitDialog<\/font><\/strong> function.<\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>BOOL CMyStatusBarDialogDlg::OnInitDialog()        <br \/>{         <br \/>\/\/&#160;&#160;&#160; rudimentary stuff         <br \/>&#160;&#160;&#160; CDialog::OnInitDialog(); <\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>\/\/ Set the icon for this dialog.&#160; <\/strong><\/font><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>       <br \/>&#160;&#160;&#160; SetIcon(m_hIcon, TRUE);&#160;&#160;&#160;&#160;&#160;&#160;&#160; \/\/ Set big icon         <br \/>&#160;&#160;&#160; SetIcon(m_hIcon, FALSE);&#160;&#160;&#160;&#160;&#160;&#160; \/\/ Set small icon         <br \/><\/strong><\/font><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong><\/strong><\/font><\/p>\n<blockquote>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>\/\/ Here is what you need, to create a status bar          <br \/>m_StatusBar.Create(this);&#160;&#160;&#160;&#160; \/\/Create status bar           <br \/>m_StatusBar.SetIndicators(indicators,2); <\/strong><\/font><\/p>\n<\/blockquote>\n<blockquote>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>\/\/&#160;&#160;&#160; Find the Size of Dialog box<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>CRect rect;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br \/>GetClientRect(&amp;rect);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br \/><\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>\/\/&#160;&#160;&#160; Size the two panes          <br \/>m_StatusBar.SetPaneInfo(0,ID_INDICATOR_PANE, SBPS_NORMAL, rect.Width()-100);&#160;&#160;&#160;&#160;&#160; <br \/><\/strong><\/font><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>m_StatusBar.SetPaneInfo(1,ID_INDICATOR_TIME, SBPS_STRETCH ,0);          <br \/><\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>\/\/&#160;&#160;&#160; This is where we actually draw it RepositionBars( AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, ID_INDICATOR_TIME ) ; <\/strong><\/font><\/p>\n<\/blockquote>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>&#160;&#160;&#160; \/\/ Timer is Set to Update the Time on the status Bar.&#160;&#160;&#160; <br \/>&#160;&#160;&#160; SetTimer(100,1000,NULL); <\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>&#160;&#160;&#160; return TRUE;&#160; \/\/ return TRUE&#160; unless . . . .        <br \/>}<\/strong><\/font><\/p>\n<p><strong><font color=\"#0000ff\" face=\"Courier New\">Implement the Message WM_TIMER to update time <\/font><\/strong><\/p>\n<p>Implement the <strong><font color=\"#0000ff\" face=\"Courier New\">WM_TIMER<\/font><\/strong> message handler to update the current time on the pane of the status bar.<\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>void CStatusBarDialogDlg::OnTimer(UINT nIDEvent)        <br \/>{         <br \/>&#160;&#160;&#160; \/\/ TODO: Add your message handler code here&#160; <\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>&#160;&#160;&#160; if ( nIDEvent==STATUS_TIMEER )        <br \/>&#160;&#160;&#160; {         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; CTime t1 ;         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; t1 = CTime::GetCurrentTime();         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_StatusBar.SetPaneText(1,t1.Format(&quot;%H:%M:%S&quot;));         <br \/>&#160;&#160;&#160; }         <br \/>&#160;&#160;&#160; CDialog::OnTimer(nIDEvent);         <br \/>}<\/strong><\/font><\/p>\n<p>build and execute, and voila you are done.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Normally in MFC Applications one can not create a status bar by default, this article shows you how status bar can be created in a dialog box. Create a Dialog based application, using MFC AppWizard, compile and make sure that every thing is working fine. Open \u201cresource.h\u201d define two identifiers in the file \u201dresource.h\u201d, for&hellip; <a class=\"more-link\" href=\"https:\/\/praveenkatiyar.in\/blog\/index.php\/2013\/06\/29\/creating-a-status-bar-in-a-dialog-box-vc-mfc\/\">Continue reading <span class=\"screen-reader-text\">Creating a status Bar in a Dialog Box ( VC++, MFC)<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,11],"tags":[24],"class_list":["post-15","post","type-post","status-publish","format-standard","hentry","category-codeproject","category-mfc","tag-gui","entry"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/posts\/15","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=15"}],"version-history":[{"count":0,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/posts\/15\/revisions"}],"wp:attachment":[{"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}