Click here to Skip to main content
15,887,596 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Writing Vector object into a .txt file Pin
Member 935023723-Mar-15 23:47
Member 935023723-Mar-15 23:47 
GeneralRe: Writing Vector object into a .txt file Pin
Jochen Arndt24-Mar-15 0:17
professionalJochen Arndt24-Mar-15 0:17 
GeneralRe: Writing Vector object into a .txt file Pin
Member 935023725-Mar-15 4:25
Member 935023725-Mar-15 4:25 
GeneralRe: Writing Vector object into a .txt file Pin
Jochen Arndt25-Mar-15 4:46
professionalJochen Arndt25-Mar-15 4:46 
GeneralMessage Closed Pin
25-Mar-15 6:47
Member 935023725-Mar-15 6:47 
GeneralRe: Writing Vector object into a .txt file Pin
Jochen Arndt25-Mar-15 6:56
professionalJochen Arndt25-Mar-15 6:56 
QuestionBIG trouble with 64-bit Shell_NotifyIcon() - can anyone help? Pin
Tacitonitus16-Mar-15 11:24
Tacitonitus16-Mar-15 11:24 
AnswerRe: BIG trouble with 64-bit Shell_NotifyIcon() - can anyone help? Pin
Frankie-C16-Mar-15 13:00
Frankie-C16-Mar-15 13:00 
From code you posted it seems very improbable to me that it can work with memory dynamically allocated (new) for NOTIFYICONDAT. This memory is released when sub exits, while it is not reused may happen that it works, as soon it is reused and filled with data making nosense for IconNotify it will not work anymore.
The problem you mentioned is related only to services and program that starts before desktop (iexplorer) is started (that is the case of utilities wrote by the author of article you mentioned). In that case the solution is to wait for initialization to complete. You will find all info, if you need, here[^].
Making it static and changing the access to its members it works for me.
This is the amended code:
C++
#define MSG_FROM_TRAY  (WM_APP + 0xDAD)   // <== ..the "callback message" ID..

static BOOL Opning = TRUE;

static NOTIFYICONDATA NID;
 
static void Init_NID( HWND hDlg )
{
    //if ( NID = new NOTIFYICONDATA )
    //{
         memset( &NID, 0, sizeof( NOTIFYICONDATA ) );
 
         if ( LoadIconMetric( AppInst,
                              (PCWSTR)MAKEINTRESOURCE( IDR_TrayIcon ),
                              LIM_SMALL, &NID.hIcon ) == S_OK )
         {
              if ( LoadIconMetric( AppInst,
                                   (PCWSTR)MAKEINTRESOURCE( IDR_BallIcon ),
                                   LIM_SMALL, &NID.hBalloonIcon ) == S_OK )
              {
                   strcpy( NID.szTip, "My App Name" );
                   strcpy( NID.szInfoTitle, "Hi There" );
                   strcpy( NID.szInfo, "My notification message.." );
 
                   if ( Opning )
                   {
                        NID.uTimeout = 5000;
                        NID.uID = TRAY_ICON_ID;
                        NID.dwInfoFlags = NIIF_USER;
                        NID.uCallbackMessage = MSG_FROM_TRAY;
                        NID.cbSize = sizeof( NOTIFYICONDATA );
                        NID.dwState = 0;
                        NID.dwStateMask = NIS_HIDDEN | NIS_SHAREDICON;
 
                        return;
                   }
 
                   DestroyIcon( NID.hBalloonIcon );
              }
 
              DestroyIcon( NID.hIcon );
         }
 
         //delete NID;
         //NID = NULL;
    //}
}

static BOOL Min2SysTray( HWND hDlg )
{
    BOOL Success = FALSE;
 
    //if ( NID )
    //{
         NOTIFYICONDATA Ver;
         memset( &Ver, 0, sizeof( NOTIFYICONDATA ) );
 
         Ver.uID = NID.uID;
         Ver.uVersion = NOTIFYICON_VERSION_4;
         Ver.cbSize = sizeof( NOTIFYICONDATA );
 
         NID.hWnd = Ver.hWnd = hDlg;
         NID.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP | NIF_SHOWTIP;
 
         if ( Shell_NotifyIcon( NIM_ADD, &NID ) &&  // <== ..adds the icon..
              Shell_NotifyIcon( NIM_SETVERSION, &Ver ) )
         {
              NID.uFlags =  NIF_INFO | NIF_MESSAGE | NIF_TIP | NIF_SHOWTIP;
 
              if ( Success = Shell_NotifyIcon( NIM_MODIFY, &NID ) )
                   ShowWindow( hDlg, SW_HIDE );
         }
    //}
 
    return( Success );
}

static void ProcMsgFromTray( HWND hDlg, WPARAM wParam, LPARAM lParam )
{
    if ( HIWORD( lParam ) == NID.uID )
    {
         switch ( LOWORD( lParam ) )
         {
//           case WM_CONTEXTMENU:   // <== ..I don't need this..
//               break;

             case NIN_SELECT:
             case NIN_KEYSELECT:
             case WM_LBUTTONDBLCLK:
 
                 /*if ( NID )*/ Shell_NotifyIcon( NIM_DELETE, &NID );
                 ShowWindow( hDlg, SW_SHOW );
         }
    }
}


modified 16-Mar-15 19:13pm.

GeneralRe: BIG trouble with 64-bit Shell_NotifyIcon() - can anyone help? Pin
Tacitonitus16-Mar-15 15:36
Tacitonitus16-Mar-15 15:36 
GeneralRe: BIG trouble with 64-bit Shell_NotifyIcon() - can anyone help? Pin
Frankie-C16-Mar-15 22:39
Frankie-C16-Mar-15 22:39 
GeneralRe: BIG trouble with 64-bit Shell_NotifyIcon() - can anyone help? Pin
Tacitonitus17-Mar-15 3:34
Tacitonitus17-Mar-15 3:34 
GeneralRe: BIG trouble with 64-bit Shell_NotifyIcon() - can anyone help? Pin
Frankie-C17-Mar-15 4:11
Frankie-C17-Mar-15 4:11 
GeneralRe: BIG trouble with 64-bit Shell_NotifyIcon() - can anyone help? Pin
Tacitonitus17-Mar-15 7:21
Tacitonitus17-Mar-15 7:21 
GeneralRe: BIG trouble with 64-bit Shell_NotifyIcon() - can anyone help? Pin
Frankie-C17-Mar-15 7:29
Frankie-C17-Mar-15 7:29 
GeneralRe: BIG trouble with 64-bit Shell_NotifyIcon() - can anyone help? Pin
Frankie-C17-Mar-15 22:48
Frankie-C17-Mar-15 22:48 
QuestionVC++ DLL throws error when call it from C#[EntryPointNotFound] Pin
Member 988367216-Mar-15 1:38
Member 988367216-Mar-15 1:38 
AnswerRe: VC++ DLL throws error when call it from C#[EntryPointNotFound] Pin
Richard Andrew x6416-Mar-15 5:48
professionalRichard Andrew x6416-Mar-15 5:48 
QuestionIAccessible - get word under mouse pointer in IE Pin
Fourblack15-Mar-15 22:01
Fourblack15-Mar-15 22:01 
QuestionC++ to C problem Pin
alexx00614-Mar-15 10:03
alexx00614-Mar-15 10:03 
AnswerRe: C++ to C problem Pin
Richard Andrew x6414-Mar-15 13:15
professionalRichard Andrew x6414-Mar-15 13:15 
AnswerRe: C++ to C problem Pin
Frankie-C15-Mar-15 5:49
Frankie-C15-Mar-15 5:49 
GeneralRe: C++ to C problem Pin
David Crow16-Mar-15 2:54
David Crow16-Mar-15 2:54 
QuestionUI widget Pin
Member 1152499814-Mar-15 7:01
Member 1152499814-Mar-15 7:01 
AnswerRe: UI widget Pin
Albert Holguin15-Mar-15 17:19
professionalAlbert Holguin15-Mar-15 17:19 
QuestionUI widget Pin
Member 1152499814-Mar-15 6:52
Member 1152499814-Mar-15 6:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.