Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Dialog Application to Hide

39 views
Skip to first unread message

JCO

unread,
Sep 17, 2010, 7:42:07 PM9/17/10
to
VS2008 C++, MFC

I want a dialog type app to be hidden when executed. I've done some reading
and I think I added all the necessary items to do this, but it still
displays itself when executed. This is what I've done so far. I understand
that a dialog, by design, will be set to "WM_SHOW" at the end of the
OnInitDialog(), therefore I must call WM_WINDOWPOSCHANGED (based on what
I've read). I can walk through the code and it steps into the
WM_WINDOWPOSCHANGED but I can't tell if the flag changes. Can anybody help
me. I'm guessing a changes were made to VS2008 that prevents dialogs from
starting up as Hidden.

//.h file
Created a variable:
protected:
BOOL m_bVisible;

public:
BOOL IsVisible(void) { return m_bVisible==true; }
void SetVisible(BOOL b) { m_bVisible = b; }
BOOL GetVisible(void) { return m_bVisible; }

//.cpp file

Constructor:
m_bVisible(FALSE);

//Message Map
BEGIN_MESSAGE_MAP(CMyTrayDlg, CDialog)
ON_REGISTERED_MESSAGE( UWM_TRAY_CALLBACK, OnTrayCallback )
//}}AFX_MSG_MAP
ON_WM_WINDOWPOSCHANGED()
ON_COMMAND(ID_FILE_HIDE, &CMyTrayDlg::OnFileHide)
ON_COMMAND(ID_FILE_RESTORE, &CMyTrayDlg::OnFileRestore)
ON_COMMAND(ID_FILE_EXIT, &CMyTrayDlg::OnFileExit)
END_MESSAGE_MAP()


//handles message WM_WINDOWPOSCHANGED
void CMyTrayDlg::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
if( !IsVisible() )
lpwndpos->flags &= ~SWP_SHOWWINDOW;

CDialog::OnWindowPosChanged(lpwndpos);

// TODO: Add your message handler code here
}

Joseph M. Newcomer

unread,
Sep 18, 2010, 3:54:57 AM9/18/10
to
Read my essay on dialog-based apps on my MVP Tips site; Nish allowed me to include his
code for hidden-at-startup dialog-based apps.
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

JCO

unread,
Sep 19, 2010, 9:10:07 AM9/19/10
to
Thanks Joseph. I had already read it and implemented you fix, however, it
will not start up in hidden mode. I did not include the code to Hide &
Restore the app (via menu) but I figured that was obvious. Plus, using the
menu works fine. I can hide the app and by using the menu in the System
Tray Icon, I can Restore (un-hide) the dialog.
Thanks

"Joseph M. Newcomer" <newc...@flounder.com> wrote in message
news:c0s8961f3q5lbiqk2...@4ax.com...

Joseph M. Newcomer

unread,
Sep 19, 2010, 7:22:42 PM9/19/10
to
Read his code carefully; it really does come up hidden if you use the code as shown.
joe

JCO

unread,
Sep 21, 2010, 1:18:46 PM9/21/10
to
The only way I was able to get the application to start out hidden, is by
the code below:

void CMyTrayDlg::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
if( !IsVisible() )
{
lpwndpos->flags &= ~SWP_SHOWWINDOW;
ShowWindow(SW_HIDE); //should not have to do
RegisterTray(); //should not have to do
}
CDialog::OnWindowPosChanged(lpwndpos);
}

However, this method creates the "Flash" that you discussed in your essay.
I'm not sure what I'm doing wrong. I'm believe I followed your essay
correctly. My original post has the code for your review.
Thanks


"Joseph M. Newcomer" <newc...@flounder.com> wrote in message

news:ap6d969bgef7ff75i...@4ax.com...

0 new messages