2015-01-05 5 views
-1

현재 WIN32 프로그램 용 메뉴를 만들려고합니다.
불행히도 하위 메뉴를 만들 수 없습니다. 다음은 내 코드입니다 : 예상대로 C++ - 하위 메뉴가 작동하지 않습니다.

HMENU menu = CreateMenu(); 
HMENU mFile = CreatePopupMenu(); 

AppendMenu(menu, MF_STRING | MF_POPUP, (UINT_PTR)mFile, L"File"); 
AppendMenu(mFile, MF_STRING, NULL, L"Exit"); 

SetMenu(hwnd, menu); 

메뉴 자체

가 표시되지만 내가 클릭하면 아무 일도 일어나지 않는다 "파일".
그럼에도 불구하고 파일을 클릭하면 하위 메뉴가 나타납니다.
누구든지이 코드가 작동하지 않는 이유가 무엇인지 설명 할 수 있습니까?

: @IInspectable 제안 해 주셔서 감사합니다. 반환 값을 확인한 결과 함수가 실패했습니다.

HMENU menu = CreateMenu(); 
HMENU mFile = CreatePopupMenu(); 

AppendMenu(menu, MF_STRING | MF_POPUP, (UINT_PTR)mFile, L"File"); 
AppendMenu(mFile, MF_STRING, NULL, L"Exit"); 

MessageBox(hwnd, L"An error occured.", L"Error!", MB_OK); 

SetMenu(hwnd, menu); 

내가이 코드 작업 이유를 전혀 몰라,하지만 지금 하위 메뉴 내가 "파일"을 클릭 할 때까지 보여주고있다 : 놀랍게도 다음 코드는 작동합니다.
이 동작에 대한 설명이 있습니까?

+0

인사말이 누락되어 죄송합니다.하지만 불행히도 변경을 무시하기 때문에 추가 할 수 없습니다. – Daniel

+0

[여기를 참조하십시오] (http://meta.stackexchange.com/questions/2950). –

+0

[AppendMenu] (http://msdn.microsoft.com/en-us/library/windows/desktop/ms647616.aspx)에는 반환 값이 있습니다. 이것은 당신이 관심을 가져야하는 정보의 종류입니다. – IInspectable

답변

0

그래서, 나는 무엇이 원인인지 알아 냈습니다. 드롭 다운 메뉴를 클릭했을 때 표시되지 않습니다. 솔직히 말해서, 조금 어색하지만 확장 윈도우 스타일을 WS_EX_NOACTIVATION으로 설정했습니다. 다른 것으로 교체하면 메뉴가 나타납니다.

0

코드에 아무 문제가 없습니다. 그것은 내 시스템에서 작동합니다. 그러나 디자인은 "일종의"잘못된 것입니다.

mFile은 일반 메뉴 여야합니다.

Example 1

#define EXIT_ID 1 

case WM_CREATE: 
{ 
    HMENU hMenubar = CreateMenu(); 
    HMENU hFileMenu = CreateMenu(); //file is a regular menu.. Exit is a regular sub-menu.. 

    AppendMenu(hMenubar, MF_POPUP, (UINT_PTR)hFileMenu, "File"); //create file menu. 
    AppendMenu(hFileMenu, MF_STRING, EXIT_ID, "Exit"); //regular menu. Has no children. 
    SetMenu(hwnd, hMenubar); 
} 
break; 

예 2 :

Example 2

#define EXIT_ID 1 
#define SUB_ID 2 

case WM_CREATE: 
{ 
    HMENU hMenubar = CreateMenu(); 
    HMENU hFileMenu = CreateMenu(); //file is a regular menu.. Exit is a regular sub-menu.. 
    HMENU hDisplayMenu = CreatePopupMenu(); //display is a popup-menu because it has children. 

    AppendMenu(hMenubar, MF_POPUP, (UINT_PTR)hFileMenu, "File"); 
    AppendMenu(hFileMenu, MF_STRING | MF_POPUP, (UINT_PTR)hDisplayMenu, "Display"); //popup menu. Has children. 
    AppendMenu(hDisplayMenu, MF_STRING, SUB_ID, "Sub"); //regular menu. Has no children. 
    AppendMenu(hFileMenu, MF_STRING, EXIT_ID, "Exit"); //regular menu. Has no children. 
    SetMenu(hwnd, hMenubar); 
} 
break; 
가 상위 메뉴 자체가 아니면 서브 메뉴는 그 후

예 ..뿐만 아니라 일반 메뉴이다

관련 문제