hello all, this is my first post.so forgive me i am at the wrong forum. I have coded the following so far, compiled and inked successfully but can't see the window. Whats wrong ?? plz somebody help
Here is the code
.386
.model flat, stdcall
option casemap:none
include d:\masm32\include\windows.inc
include d:\masm32\include\kernel32.inc
include d:\masm32\include\user32.inc
include d:\masm32\include\gdi32.inc
includelib d:\masm32\lib\kernel32.lib
includelib d:\masm32\lib\user32.lib
includelib d:\masm32\lib\gdi32.lib
includelib d:\masm32\lib\import32.lib
WinMain proto :DWORD, :DWORD, :DWORD, :DWORD
;WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int nShowCmd)
.data
wClassName db "SimpleWindowClassA", 0
wWinName db "My First Window using Assembly", 0
.data?
hInstance HINSTANCE ?
cmdLine LPSTR ?
.code
start:
; getting instace of our program
invoke GetModuleHandle, NULL
mov hInstance, eax
; get command line
;invoke GetCommandLine
;mov cmdLine, eax
; call WinMain
invoke WinMain, hInstance, NULL, NULL, SW_SHOWDEFAULT
; quit if we return from win main
invoke ExitProcess, NULL
;the WinMain
WinMain proc hInst:HINSTANCE, hPrevInst:HINSTANCE, CommandLine:LPSTR, nShowCmd:DWORD
; take note dfining a local variable
; the WindowClass structure
LOCAL wc :WNDCLASSEX
LOCAL msg : MSG
LOCAL hWnd: HWND
; filling up wc
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 wClassName
invoke LoadIcon, NULL, IDI_APPLICATION
mov wc.hIcon, eax
mov wc.hIconSm, eax
Invoke LoadCursor, NULL, IDC_ARROW
mov wc.hCursor, eax
; now register class
Invoke RegisterClassEx, addr wc
;create it actully
invoke CreateWindowEx, NULL, addr wClassName, addr wWinName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL
mov hWnd, eax
; show window
invoke ShowWindow, hWnd, nShowCmd
; update it
invoke UpdateWindow, hWnd
; notice MASM's easier than C Macro WHILE loop
.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
.IF uMsg == WM_DESTROY
invoke PostQuitMessage, NULL
.ELSE
invoke DefWindowProc, hwnd, uMsg, wParam, lParam
.ENDIF
xor eax, eax
ret
WndProc endp
end start
and using following commands for assembling and linking
ml /c /coff /Cp ice3.asm
link /SUBSYSTEM:WINDOWS /LIBPATH:d:\masm32\lib ice3.obj
ice3.exe
I am not see where error
http://www.mbuilder.jino-net.ru/en/index.html
The window is not showing because your call to CreateWindowEx is failing. When your window procedure calls DefWindowProc it normally should return whatever DefWindowProc returns.
WndProc proc hwnd: HWND, uMsg: UINT, wParam: WPARAM, lParam: LPARAM
.IF uMsg == WM_DESTROY
invoke PostQuitMessage, NULL
.ELSE
invoke DefWindowProc, hwnd, uMsg, wParam, lParam
ret ;<<<<<<
.ENDIF
xor eax, eax
ret
WndProc endp
terminal,
Tell us what OS version you are running, I am getting very strange error messages right at the "start:" label and onwards. If you are not committed to this particular bare window, we can easily give you a reliable one that does work.
@MicahelW: Salute Sir. That was awsome sir, just added the ret, and it showed....!!! well masm is fun, no more fooling around just to write a nested if. But it wud be gr8 if u explain a litttle bit more, i am a n00b right now.
@hutch-- : well sir Windows XP (yeah a bit backdated).
The problem is with the handling of the WM_NCCREATE (http://msdn.microsoft.com/en-us/library/ms632635(VS.85).aspx) message.
"If an application processes this message, it should return TRUE to continue creation of the window. If the application returns FALSE, the CreateWindow or CreateWindowEx function will return a NULL handle."
Since your window procedure does not handle WM_NCCREATE directly it gets passed to the default window procedure. The default window procedure returns TRUE, but your .IF block then falls through and the return value gets overwritten with NULL.
Quote from: MichaelW on September 12, 2010, 01:46:05 PM
The problem is with the handling of the WM_NCCREATE (http://msdn.microsoft.com/en-us/library/ms632635(VS.85).aspx) message.
"If an application processes this message, it should return TRUE to continue creation of the window. If the application returns FALSE, the CreateWindow or CreateWindowEx function will return a NULL handle."
Since your window procedure does not handle WM_NCCREATE directly it gets passed to the default window procedure. The default window procedure returns TRUE, but your .IF block then falls through and the return value gets overwritten with NULL.
Oh i see, thank u Sir. :clap: