Hide the window and Communication among the progrma

1.I want to hide the main window ,and only let it show in the system tray . But when I use the following words , it can't work. Where does the error occur?

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
     if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
          return -1;

     if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
          TRACE0("Failed to create toolbar\n");
          return -1;      

     if (!m_wndStatusBar.Create(this) ||
          TRACE0("Failed to create status bar\n");
          return -1;      


     nid.cbSize = sizeof(NOTIFYICONDATA);
     nid.hWnd = m_hWnd;
     nid.uID = ID_SYSTEMTRAY;
     nid.uCallbackMessage = WM_SYSTEMTRAY;
     nid.hIcon = AfxGetApp()->LoadIcon(IDR_OLYMPUTYPE);
     strcpy(nid.szTip,"System Tray Tip");
     ::ShowWindow((HWND)AfxGetApp()->m_pMainWnd ,SW_HIDE);
// The fowllowing words also can't work.
//     AfxGetApp()->m_nCmdShow = SW_HIDE;
     return 0;

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
     if( !CFrameWnd::PreCreateWindow(cs) )
          return FALSE;
     return TRUE;

Please help me,thanks very much.

2.I want to make a progrom.It should communicate with the anothing program in the same computer. Which way is the best? Can you tell me where has the information about this type of communication?

Thanks very much.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Iconize to tray:
I used the following:

a) in MainFrame Constructor:
m_hTrayIcon = ::AfxGetApp()->LoadIcon(IDI_ICON_TRAY);

b) in OnCreate() - call a separate function just to make it look neater:

c) add the function:
void CMainFrame::CreateTrayIcon(void)
     NOTIFYICONDATA icondata;
     memset(&icondata, 0, sizeof(NOTIFYICONDATA));

     icondata.cbSize                    = sizeof(NOTIFYICONDATA);     //
     icondata.uFlags                    = 0;
     icondata.uFlags                    |= NIF_ICON;     //The hIcon member is valid.  
     icondata.uFlags                    |= NIF_MESSAGE;     //The uCallbackMessage member is valid.
     icondata.uFlags                    |= NIF_TIP;          //The szTip member is valid.

     //Handle to the window that receives notification messages associated with an icon in the taskbar
     //status area. The Shell uses hWnd and uID to identify which icon to operate on when
     //Shell_NotifyIcon is invoked.
     icondata.hWnd                    = m_hWnd;    
     icondata.uID                    = IDI_ICON_TRAY;     //
     icondata.hIcon                    = m_hTrayIcon;     //
     icondata.uCallbackMessage     = CONS_BH_MSGS::dwWM_TRAY_NOTIFY;     //

     _tcscpy(icondata.szTip, _T("Bughunter"));     //

     ::Shell_NotifyIcon(NIM_ADD, &icondata);

d) Just call:
void CMainFrame::MinimizeToTray()

The difference, as far as I can see, are the zeroing of the ICONDATA memory - this shouldn't matter - and the choice of which window you are calling ShowWindow(SW_HIDE) for.

Interprocess Communications:
There's lots of different methods to use, such as a named pipes, sockets, message queuing, etc and the one you choose depends on what it's going to do, how fast it needs to be and other factors.
alshaimAuthor Commented:
I want the main window will be only on system tray ,and it should not be seen on task bar. I don't know how to realize it.
Isn't that what the above does? Have you tried it?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
alshaimAuthor Commented:
In this "BOOL CApp::InitInstance()" function, there is a sentence "m_pMainWnd->ShowWindow(SW_SHOW);".Now I change it to "m_pMainWnd->ShowWindow(SW_HIDE);". And it can work.
But before the window disappears, there is a flash.How can the flash disappear?
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered: Points to pcooke

Please leave any comments here within the next seven days. Experts: Silence
means you don't care.


-bcl (bcladd)
EE Cleanup Volunteer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.