IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Dev-C++ Discussion :

TrackPopupMenu échoue et je ne vois pas pourquoi.


Sujet :

Dev-C++

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    91
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2002
    Messages : 91
    Points : 96
    Points
    96
    Par défaut TrackPopupMenu échoue et je ne vois pas pourquoi.
    Hello,

    J'ai beau chercher j'ai un problème avec cette fonction. Elle me retourne toujours 0, donc elle échoue.

    Je pose mon code pour voir si quelqu'un voit pourquoi elle échoue.

    Merci.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    #include <windows.h>
     
    /*  Declare Windows procedure  */
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
     
    int const WM_SHELLNOTIFY = WM_USER+5;
    int IDI_TRAY             = 0;
    int IDM_RESTORE          = 1000;
    int IDM_EXIT             = 1010;
     
    //.data
    char szClassName[] =     "TrayIconWinClass";
    char szAppName[] =       "TrayIcon Demo";
    char RestoreString[] =   "&Restore";
    char ExitString[] =      "E&xit Program";
     
    int result;                                 // Variables de
    char buffer[100];                           // déboggage
    char formatHexa[] =      "%lx";             // 
     
    //.data?
    int hInstance;
    NOTIFYICONDATA note;      // note est déclarée en tant que structure de type NOTIFYICONDATA
    int hPopupMenu;
     
     
     
    int WINAPI WinMain (HINSTANCE hThisInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpszArgument,
                        int nFunsterStil) {
     
        HWND hwnd;               /* This is the handle for our window */
        MSG messages;            /* Here messages to the application are saved */
        WNDCLASSEX wincl;        /* Data structure for the windowclass */
     
        /* The Window structure */
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
        wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
        wincl.cbSize = sizeof (WNDCLASSEX);
     
        /* Use default icon and mouse-pointer */
        wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
        wincl.lpszMenuName = NULL;                 /* No menu */
        wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
        wincl.cbWndExtra = 0;                      /* structure or the window instance */
        /* Use Windows's default color as the background of the window */
        wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
     
        /* Register the window class, and if it fails quit the program */
        if (!RegisterClassEx (&wincl))
            return 0;
     
        /* The class is registered, let's create the program*/
        hwnd = CreateWindowEx (
               WS_EX_CLIENTEDGE,    /* Extended possibilites for variation */
               szClassName,         /* Classname */
               szAppName,           /* Title Text */
               WS_OVERLAPPED+WS_CAPTION+WS_SYSMENU+WS_MINIMIZEBOX+WS_MAXIMIZEBOX+WS_VISIBLE,                   /* default window */
               CW_USEDEFAULT,       /* Windows decides the position */
               CW_USEDEFAULT,       /* where the window ends up on the screen */
               350,                 /* The programs width */
               200,                 /* and height in pixels */
               HWND_DESKTOP,        /* The window is a child-window to desktop */
               NULL,                /* No menu */
               hThisInstance,       /* Program Instance handler */
               NULL                 /* No Window Creation data */
               );
     
        /* Make the window visible on the screen */
        ShowWindow (hwnd, nFunsterStil);
     
        /* Run the message loop. It will run until GetMessage() returns 0 */
        while (GetMessage (&messages, NULL, 0, 0))
        {
            /* Translate virtual-key messages into character messages */
            TranslateMessage(&messages);
            /* Send message to WindowProcedure */
            DispatchMessage(&messages);
        }
     
        /* The program return-value is 0 - The value that PostQuitMessage() gave */
        return messages.wParam;
    }
     
     
    /*  This function is called by the Windows function DispatchMessage()  */
     
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
    	POINT pt;
        RECT rect;
        HMENU hPopupMenu;
     
        switch (message)                  /* handle the messages */
        {
            case WM_CREATE:
               hPopupMenu = CreatePopupMenu();
               AppendMenu (hPopupMenu, MF_STRING, IDM_RESTORE, RestoreString);
    		   AppendMenu (hPopupMenu, MF_STRING, IDM_EXIT, ExitString);
    		   break;
     
            case WM_DESTROY:
                DestroyMenu (hPopupMenu);
    		    PostQuitMessage (0);
                break;
     
            case WM_SIZE:
    		    if (wParam == SIZE_MINIMIZED) {
    			    note.cbSize = sizeof (NOTIFYICONDATA);
    			    note.hWnd = hwnd;
    			    note.uID = IDI_TRAY;
    			    note.uFlags = NIF_ICON+NIF_MESSAGE+NIF_TIP;
    			    note.uCallbackMessage = WM_SHELLNOTIFY;
    			    note.hIcon = LoadIcon (NULL, IDI_WINLOGO);
    			    lstrcpy (note.szTip, szAppName);
    			    ShowWindow (hwnd, SW_HIDE);
    			    Shell_NotifyIcon (NIM_ADD, &note);
    		    } // endif
                break;
     
            case WM_COMMAND:
    	        if (lParam == 0) {
    			    Shell_NotifyIcon (NIM_DELETE, &note);
    		        wParam = wParam & 0x0000FFFF;                                           // <-- recupère les bits de poids faibles de wParam
    			    if (wParam == IDM_RESTORE) {ShowWindow (hwnd, SW_RESTORE);}
    			    else {DestroyWindow (hwnd);}
                 }
                break;
     
            case WM_SHELLNOTIFY:
                if (wParam == IDI_TRAY) {
    			    if (lParam == WM_RBUTTONDOWN) {
    				   GetCursorPos (&pt);
    				   SetForegroundWindow (hwnd);
    				   result = TrackPopupMenu (hPopupMenu, TPM_RIGHTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, 0, hwnd, NULL);     // <---------------------ici ça échoue....
    /*
    		   wsprintf (buffer, formatHexa, result);
    		   MessageBoxA (0, buffer, buffer, 0);
    */
    				   PostMessage (hwnd, WM_NULL, 0, 0);
    			    } else if (lParam == WM_LBUTTONDBLCLK) {
    				   SendMessage (hwnd, WM_COMMAND, IDM_RESTORE, 0);
                    }
                }
                break;
     
            default:                      /* for messages that we don't deal with */
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
     
        return 0;
    }
    @+

  2. #2
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    91
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2002
    Messages : 91
    Points : 96
    Points
    96
    Par défaut
    J'ai trouvé.

    J'avais définit hPopupMenu en tant que variable globale et ensuite je l'ai redéfinit en tant que variable locale. du coup elle valait 0 dans cette procédure alors qu'elle n'était pas nulle dans la procedure précédente.

    HMENU hPopupMenu; // en variable globale
    @+

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. update error code 1093 .. vois pas pourquoi
    Par maysa dans le forum Requêtes
    Réponses: 2
    Dernier message: 20/10/2009, 11h55
  2. loadvar et onload, là je vois pas pourquoi ça bug!
    Par pierrickg dans le forum ActionScript 1 & ActionScript 2
    Réponses: 5
    Dernier message: 23/08/2009, 12h59
  3. Argument de "Sheets" incorrect? Je ne vois pas pourquoi!
    Par Bubale dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 16/05/2008, 07h19
  4. [SQL] Requete SQL mal formée : mais je vois pas pourquoi !
    Par Thomus38 dans le forum PHP & Base de données
    Réponses: 4
    Dernier message: 21/06/2006, 18h03
  5. [UML] Je ne vois pas où mettre la vue !
    Par le Daoud dans le forum MVC
    Réponses: 12
    Dernier message: 19/03/2006, 09h31

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo