Wednesday, March 12, 2008

How to hide application at startup? VC++

It seems this->ShowWindow(SW_HIDE) doesnot work for C++ program when it is put under OnInitDialog.

Here is the way to do it.

Step 1: define a message and function at header file:

#define MY_MESSAGE WM_USER+123

void FuncHideWindow();

Step 2: Add message to message loop

ON_MESSAGE(MY_MESSAGE, FuncHideWindow)

and delcare function:
void CKeyBoardHookTestDlg::FuncHideWindow()
{
this->ShowWindow(SW_HIDE);
}

Step 3: post message at OnInitDialog immediately after CDialog::OnInitDialog();

::PostMessage(this->m_hWnd,MY_MESSAGE,0,0);

No comments: