Problem mit Menü



  • Hallo,

    ich habe folgende Ressource-Datei für ein Menü erstellt:

    #define IDM_Ende 1010
    
    100 MENU
    BEGIN
    	POPUP "&Datei"
    	BEGIN
    		MENUITEM "Be&enden", IDM_Ende
    	END
    	POPUP "&?"
    	BEGIN
    		POPUP "Hier geht's zur Info";
    		BEGIN
    			MENUITEM "&Info", 1020
    		END
    	END
    END
    

    Wie kann ich es schaffen, mit Alt+d den Menüpunkt Datei aufklappen zu lassen? Bei mir funktioniert es nur, wenn ich erst Alt drücke, die Taste loslasse und dann d drücke.
    Kann mir da jemand weiterhelfen?

    Mit freundlichen Grüßen
    DerRatlose

    EDIT: Hat sich erledigt. Das Beispielcode war nicht vollständig.

    invoke TranslateMessage, ADDR msg
    

    fehlte.



  • Was hat das mit Assembler zu tuen?



  • zeige mal den zugehörigen Assemblercode.



  • .386
    .model flat, stdcall
    option casemap :none
    include \masm32\include\windows.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib
    
    WndProc			 PROTO :DWORD, :DWORD, :DWORD, :DWORD
    RegisterWinClass PROTO :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
    
    .const
    	IDM_Ende equ 1010
    
    .data
    	szCaption	db "Fenster 1.0",0
    	szClassName	db "My_Class",0
    	Text		db "Info-Menü",0
    	Caption		db "Menü-Demo",0
    .data?
    	hInstance	dd ?
    	hIcon		dd ?
    	hCursor		dd ?
    	hWnd		dd ?
    
    .code
    start:
    		call Init
    		call Main
    		invoke ExitProcess, eax
    
    ;##################################################
    
    Init proc
    		invoke GetModuleHandle, NULL
    		mov hInstance, eax
    		invoke LoadIcon, NULL, IDI_EXCLAMATION
    		mov hIcon, eax
    		invoke LoadCursor, NULL, IDC_CROSS
    		mov hCursor, eax
    		ret
    Init endp
    
    ;##################################################
    
    Main proc
    		LOCAL Wwd:DWORD, Wht:DWORD, Wtx:DWORD, Wty:DWORD
    
    		mov Wtx, 0
    		mov Wty, 0
    		mov Wwd, 400
    		mov Wht, 400
    
    		invoke RegisterWinClass, ADDR WndProc, ADDR szClassName, hIcon, hCursor, COLOR_BTNFACE+1
    
    		invoke CreateWindowEx, WS_EX_LEFT, ADDR szClassName, ADDR szCaption, WS_OVERLAPPEDWINDOW, Wtx, Wty, Wwd, Wht, NULL, NULL, hInstance, NULL
    		mov hWnd, eax
    
    		invoke LoadMenu, hInstance, 100
    		invoke SetMenu, hWnd, eax
    
    		invoke ShowWindow, hWnd, SW_SHOWNORMAL
    		invoke UpdateWindow, hWnd
    
    		call MsgLoop
    		ret	
    Main endp
    
    ;##################################################
    
    m2m macro M1, M2
    		push M2
    		pop M1
    endm
    
    ;##################################################
    
    RegisterWinClass proc lpWndProc:DWORD, lpClassName:DWORD, Icon:DWORD, Cursor:DWORD, bColor:DWORD
    		LOCAL wc:WNDCLASSEX
    		mov wc.cbSize, 			sizeof WNDCLASSEX
    		mov wc.style, 			CS_BYTEALIGNCLIENT or CS_BYTEALIGNWINDOW
    		m2m wc.lpfnWndProc,		lpWndProc
    		mov wc.cbClsExtra,		NULL
    		mov wc.cbWndExtra,		NULL
    		m2m wc.hInstance,		hInstance
    		m2m wc.hbrBackground,	bColor
    		mov wc.lpszMenuName,	NULL
    		m2m wc.lpszClassName,	lpClassName
    		m2m wc.hIcon,			Icon
    		m2m wc.hCursor,			Cursor
    		m2m wc.hIconSm,			Icon
    
    		invoke RegisterClassEx, ADDR wc
    		ret
    RegisterWinClass endp
    
    ;##################################################
    
    MsgLoop proc
    		LOCAL msg:MSG
    
    		StartLoop:
    			invoke GetMessage, ADDR msg, NULL, 0, 0
    			cmp eax, 0
    			je ExitLoop
    			invoke TranslateMessage, ADDR msg
    			invoke DispatchMessage, ADDR msg
    			jmp StartLoop
    		ExitLoop:
    			mov eax, msg.wParam
    			ret
    MsgLoop endp
    
    ;##################################################
    
    WndProc proc hWin:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
    		.if uMsg == WM_DESTROY
    			invoke PostQuitMessage, NULL
    			mov eax, 0
    			ret
    		.elseif uMsg == WM_COMMAND
    			.if wParam == IDM_Ende
    				invoke ExitProcess, 0
    			.endif
    			.if wParam == 1020
    				invoke MessageBox, 0, addr Text, addr Caption, MB_OK
    			.endif
    		.endif
    
    		invoke DefWindowProc, hWin, uMsg, wParam, lParam
    		ret
    WndProc endp
    end start
    

    Bitte sehr 🙂


Anmelden zum Antworten