2010-02-22 5 views
6

Je suis en train de créer le menu contextuel pour une application win32 utilisantCréation menu contextuel API win32

case WM_RBUTTONDOWN: 
{ 
    HMENU hPopupMenu = CreatePopupMenu(); 
    InsertMenu(hPopupMenu, 0, MF_BYPOSITION | MF_STRING, ID_CLOSE, (LPCWSTR)"Exit"); 
    InsertMenu(hPopupMenu, 0, MF_BYPOSITION | MF_STRING, ID_EXIT, (LPCWSTR)"Play"); 
    SetForegroundWindow(hWnd); 
    TrackPopupMenu(hPopupMenu, TPM_BOTTOMALIGN | TPM_LEFTALIGN, 0, 0, 0, hWnd, NULL); 
}

Mais je reçois le menu contextuel toujours comme indiqué ci-dessous

alt text http://img191.imageshack.us/img191/866/70219076.png

Je veux texte sortie et lire à afficher dans le menu

Répondre

5

Vous ne pouvez pas convertir une chaîne littérale à l'échelle par coulée, vous devez déclarer comme une grande chaîne char. La conversion défait juste l'avertissement du compilateur, elle ne change pas le contenu de la chaîne.

changer cette

(LPCWSTR)"Exit" 
(LPCWSTR)"Play" 

à cette

_T("Exit") 
_T("Play") 

ou cette

L"Exit" 
L"Play" 
1

Are vous spécifiez le codage dans la définition de la fonction API? J'ai récemment rencontré ce problème et la suppression de la spécification a résolu le problème.

0

Suivant a fonctionné pour moi

case WM_RBUTTONDOWN: 
      { 
      HMENU hPopupMenu = CreatePopupMenu(); 
      InsertMenu(hPopupMenu, 0, MF_BYPOSITION | MF_STRING, ID_CLOSE, L"Exit"); 
      InsertMenu(hPopupMenu, 0, MF_BYPOSITION | MF_STRING, ID_EXIT, L"Play"); 
      SetForegroundWindow(hWnd); 
      TrackPopupMenu(hPopupMenu, TPM_BOTTOMALIGN | TPM_LEFTALIGN, 0, 0, 0, hWnd, NULL); 
      }