Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

N00b Menu problem 1

Status
Not open for further replies.

devilmech

Programmer
Aug 24, 2002
1
US
Ok, I have a problem. I'm trying to learn how to create menus, but I can't get my menu to show up on my program. This is my program code:
_______________________________________________
.386
.model flat,stdcall
option casemap :none

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD

include \masm32\include\windows.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\gdi32.inc
includelib \masm32\lib\gdi32.lib

.data
ClassName db "WinClass_1",0
AppName db "A retarded Window",0
char WPARAM 20h
MouseClick db 0
MenuName db "FirstMenu",0
Test_String db "This is a test string",0
Hello_String db "Hello, you devil",0
Bye_String db "See you later, bro",0

.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
hitpoint POINT <>

.const
IDM_TEST equ 1
IDM_HELLO equ 2
IDM_GOODBYE equ 3
IDM_EXIT equ 4

.code
start:

invoke GetModuleHandle, NULL
mov hInstance, eax
invoke GetCommandLine
mov CommandLine, eax
invoke WinMain, hInstance, NULL, CommandLine, SW_SHOWDEFAULT
invoke ExitProcess, eax

WinMain proc hInst:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR, CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND

mov wc.cbSize, SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
push hInstance
pop wc.hInstance
mov wc.hbrBackground, COLOR_WINDOW+1
mov wc.lpszMenuName, NULL
mov wc.lpszClassName, OFFSET ClassName
invoke LoadIcon, NULL, IDI_APPLICATION
mov wc.hIcon, eax
mov wc.hIconSm, eax
invoke LoadCursor, NULL, IDC_ARROW
mov wc.hCursor, eax
invoke RegisterClassEx, addr wc
invoke CreateWindowEx, NULL, ADDR ClassName, ADDR AppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL
mov hwnd, eax
invoke ShowWindow, hwnd, SW_SHOWNORMAL
invoke UpdateWindow, hwnd

.WHILE TRUE
invoke GetMessage, ADDR msg, NULL,0,0
.BREAK .IF(!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW

mov eax, msg.wParam
ret
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL hdc:HDC
LOCAL ps:pAINTSTRUCT

.IF uMsg == WM_DESTROY
invoke PostQuitMessage, NULL
.ELSEIF uMsg == WM_COMMAND
mov eax, wParam
.IF ax == IDM_TEST
invoke MessageBox, NULL, ADDR Test_String, OFFSET AppName, MB_OK
.ELSEIF ax == IDM_HELLO
invoke MessageBox, NULL, ADDR Hello_String, OFFSET AppName, MB_OK
.ELSEIF ax == IDM_GOODBYE
invoke MessageBox, NULL, ADDR Bye_String, OFFSET AppName, MB_OK
.ELSE
invoke DestroyWindow, hWnd
.ENDIF
.ELSEIF uMsg == WM_LBUTTONDOWN
mov eax, lParam
and eax, 0FFFFh
mov hitpoint.x, eax
mov eax, lParam
shr eax, 16
mov hitpoint.y, eax
mov MouseClick, TRUE
invoke InvalidateRect, hWnd, NULL, TRUE
.ELSEIF uMsg == WM_PAINT
invoke BeginPaint, hWnd, ADDR ps
mov hdc, eax
.IF MouseClick
invoke lstrlen, ADDR AppName
invoke TextOut, hdc, hitpoint.x,hitpoint.y, ADDR AppName, eax
.ENDIF
invoke EndPaint, hWnd, ADDR ps
.ELSE
invoke DefWindowProc, hWnd, uMsg, wParam, lParam
ret
.ENDIF

xor eax, eax
ret
WndProc endp

end start
___________________________________

I have defined my menu in a resource file named the same thing as my asm file. I tried to compile the resource file, but it says rsrc.rc cannot be opened. So I renamed my resource file to rsrc.rc, and the resource file compiled, but it still will not show up in my program. I'm using QEditor to compile everything, because I don't know how to do it manually. If anyone can help, or knows somewhere to get info on manually compiling my program, please help. Sorry for the long message, I'm a newbie just trying to understand
 
I'm away from a windows box right now so I can't test but it appears that should change:
mov wc.lpszMenuName, NULL
TO...
mov wc.lpszMenuName,OFFSET MenuName ; Put our menu name here

The Iczzi tutes are a good place to start for win32asm. you can also ask at...
 
This does appear to be the problem. &quot;Information has a tendency to be free. Which means someone will always tell you something you don't want to know.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top