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

C / C++ / MFC

 
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 
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 
I see, I have misinterpreted the usage of new in your code.
What I mean is that I compiled a sample with a C (not C++) compiler and it works for me.
The only problem I found compiling the code in 64bits is that a manifest resource is required.
This is my full sample:
C++
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <tchar.h>
#include <shellapi.h>
#include <stdio.h>
#include <stdlib.h>
#include "main.h"

#define NELEMS(a)  (sizeof(a) / sizeof((a)[0]))

static INT_PTR CALLBACK MainDlgProc(HWND, UINT, WPARAM, LPARAM);

#define AppInst ghInstance
static HANDLE ghInstance;

#define TRAY_ICON_ID  0xABC  // <== ..our System Tray Icon Id
#define BALL_ICON_ID  0xDEF  // <== ..our Balloon Tip Icon Id

#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 );
         }
    }
}

int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
    INITCOMMONCONTROLSEX icc;
    WNDCLASSEX wcx;

    ghInstance = hInstance;

    icc.dwSize = sizeof(icc);
    icc.dwICC = ICC_WIN95_CLASSES /*|ICC_COOL_CLASSES|ICC_DATE_CLASSES|ICC_PAGESCROLLER_CLASS|ICC_USEREX_CLASSES|... */;
    InitCommonControlsEx(&icc);

    wcx.cbSize = sizeof(wcx);
    if (!GetClassInfoEx(NULL, MAKEINTRESOURCE(32770), &wcx))
        return 0;

    wcx.hInstance = hInstance;
    wcx.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDR_ICO_MAIN));
    wcx.lpszClassName = _T("TacitoniClass");
    if (!RegisterClassEx(&wcx))
        return 0;

    return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)MainDlgProc);
}

static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
        case WM_INITDIALOG:
			Init_NID( hwndDlg );
            return TRUE;

        case WM_SIZE:
            return TRUE;

        case WM_COMMAND:
            switch (GET_WM_COMMAND_ID(wParam, lParam))
            {
                case IDOK:
                    EndDialog(hwndDlg, TRUE);
                    return TRUE;
            }
            break;

        case WM_SYSCOMMAND:
 
            switch ( wParam )
            {
                case SC_CLOSE:      // <== ..as for example..

                    PostQuitMessage(0);
                    return TRUE;
 
                case SC_MINIMIZE:
					if ( Min2SysTray( hwndDlg ) )
						return TRUE;
            }
 
            break;

		case MSG_FROM_TRAY:
			ProcMsgFromTray(hwndDlg, wParam, lParam);
			break;
 
        case WM_CLOSE:
            EndDialog(hwndDlg, 0);
            return TRUE;
    }

    return FALSE;
}


modified 17-Mar-15 4:53am.

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 
QuestionFeatures and rich documentation of MFC vs Small Executable of WTL Pin
Member 1120327711-Mar-15 4:21
Member 1120327711-Mar-15 4:21 
AnswerRe: Features and rich documentation of MFC vs Small Executable of WTL Pin
jeron111-Mar-15 5:53
jeron111-Mar-15 5:53 

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.