Hide the window and Communication among the progrma

Posted on 2003-03-24
Medium Priority
Last Modified: 2010-04-01
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.
Question by:alshaim
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Expert Comment

ID: 8196121
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.

Author Comment

ID: 8199291
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.

Accepted Solution

pcooke earned 200 total points
ID: 8200863
Isn't that what the above does? Have you tried it?

Author Comment

ID: 8200893
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?
LVL 11

Expert Comment

ID: 9558689
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question