Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

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
          | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
          !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
     {
          TRACE0("Failed to create toolbar\n");
          return -1;      
     }

     if (!m_wndStatusBar.Create(this) ||
          !m_wndStatusBar.SetIndicators(indicators,
            sizeof(indicators)/sizeof(UINT)))
     {
          TRACE0("Failed to create status bar\n");
          return -1;      
     }


     m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
     EnableDocking(CBRS_ALIGN_ANY);
     DockControlBar(&m_wndToolBar);

     NOTIFYICONDATA nid;
     nid.cbSize = sizeof(NOTIFYICONDATA);
     nid.hWnd = m_hWnd;
     nid.uID = ID_SYSTEMTRAY;
     nid.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
     nid.uCallbackMessage = WM_SYSTEMTRAY;
     nid.hIcon = AfxGetApp()->LoadIcon(IDR_OLYMPUTYPE);
     strcpy(nid.szTip,"System Tray Tip");
     ::Shell_NotifyIcon(NIM_ADD,&nid);
     
     ::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.
0
alshaim
Asked:
alshaim
  • 2
  • 2
1 Solution
 
pcookeCommented:
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:
     CreateTrayIcon();

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()
{
     ShowWindow(SW_HIDE);
}

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.
0
 
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.
0
 
pcookeCommented:
Isn't that what the above does? Have you tried it?
0
 
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?
0
 
bcladdCommented:
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.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

-bcl (bcladd)
EE Cleanup Volunteer
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now