2015-10-02 2 views
0

Je suis en train de coder une application comme Notepad dans Win32 C++. Mais quand je change szClassName dans createWindow(), le menu ne peut pas fonctionner bien qu'il montre encore quand je lanceWin 32 API C++ Bloc-notes Le menu ne fonctionne pas

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) 
{ 
    HWND hWnd; 

    hInst = hInstance; // Store instance handle in our global variable 


    hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDC_NOTEPAD)); 

    hWnd = CreateWindow(L"EDIT", szTitle, WS_OVERLAPPEDWINDOW, 
     CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, hMenu, hInstance, NULL); 

    //SetWindowLong(hWnd, GWL_WNDPROC, (LONG)WndProc); 

    if (!hWnd) 
    { 
     return FALSE; 
    } 

    ShowWindow(hWnd, nCmdShow); 
    UpdateWindow(hWnd); 



    return TRUE; 
} 
+0

Vous voulez que votre fenêtre principale soit une commande d'édition ou quoi? Cela ne marchera pas. –

+0

Oui. Je commence à apprendre l'API Win32 et je ne sais pas comment faire une application comme Notepad – AdamTruong

+0

[Procédure pas à pas: création d'applications de bureau Windows (C++)] (https://msdn.microsoft.com/fr-fr/library/ bb384843.aspx) – IInspectable

Répondre

1

En CreateWindow(), le paramètre hMenu est l'ID de contrôle, mais pas la poignée de menu.

Je propose la création de la fenêtre principale avant d'ajouter une zone de texte:

WNDCLASSEX wc; 
// ... 
wc.lpszClassName="window class"; 
wc.lpszMenuName=hMenu; 
// ... 
RegisterWindowEx(&wc); 
hWnd=CreateWindow("window class", ...); 

// When processing WM_CREATE message in WndProc() 
hEdit=CreateWindow("EDIT","your textbox", ... /* set hWndParent as hWnd */); 

Je pense que theForger's Win32 API Programming Tutorial est aussi un bon endroit pour vous de commencer.