First of all CreateWindow function isn't added in the masm9 libs, so i'm using the extended version. With this function i tried creating some child windows, but i failed; when i debugged i observed CreateWindowEx(2nd one used in this code) retuns 0 in eax.

http://wolfshade.home.ro/Project.Asm  (keep refreshing its a crappy ftp)

Posted on 2006-08-23 04:24:08 by w0lfshad3
Firstly, you forgot to specify a width and height for the child window(s).
Secondly, you are passing garbage? values for the Menu ID..
If you don't intend for the window to have a menu, use NULL there.
Posted on 2006-08-23 05:09:52 by Homer
Firstly, you forgot to specify a width and height for the child window(s).


No i didn't, its 0, 0 and i use MoveWindow to set it again later.

Secondly, you are passing garbage? values for the Menu ID


Do you know win32api or not? Those are the ChildIDs made up from 13000 to 13013.

If you don't intend for the window to have a menu, use NULL there.


...
Posted on 2006-08-23 05:41:02 by w0lfshad3
link's not working.. paste the code here,
Posted on 2006-08-23 06:15:30 by lone_samurai5
You should've kept trying its a crappy ftp or perhaps because i had it opened in browser?
Anyway here it is:

.386

.model flat,stdcall

option casemap:none

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


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

.data
ClassName db "Parent", 0
ChildClassName db "Child", 0
AppName db "Project", 0

.data?
hInstance dd ?
CommandLine dd ?
cxClient dd ?
cyClient dd ?
ChildIDsArray HWND 13 dup(?)
i dd ?
temp1 dd ?
temp2 dd ?
temp3 dd ?

.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 hInst
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

mov wc.lpfnWndProc, OFFSET ChildWndProc
mov wc.cbWndExtra, 4
mov wc.lpszClassName, OFFSET ChildClassName
mov wc.hIcon, NULL

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 temp:DWORD
.if uMsg==WM_CREATE
mov ecx, 13; i = 13
push esi
xor esi, esi
label1::
mov edx, 13000
add edx, ecx
mov temp, edx
push ecx
invoke CreateWindowEx, NULL, ADDR ChildClassName, NULL,\
WS_CHILDWINDOW + WS_VISIBLE,\
0, 0, 0, 0,\
hwnd, , hInstance, NULL
mov , eax
add esi, 4
pop ecx
loop label1
pop esi

.elseif uMsg==WM_SIZE
mov eax, lParam
mov edx, eax
and eax ,0FFFFh
shr edx, 16
mov cxClient, eax; Client width
mov cyClient, edx; Client height

finit

mov temp2, 4
fld1 ; 1
fild temp2 ; 4, 1
fdivp ST(1), ST(0) ; 1/4
fild cxClient ; cxClient, (1/4)
fmulp ST(1), ST(0) ; cxClient * (1/4)
fistp temp2 ; temp2 = ST(0), FPU stack balanced

mov temp3, 7
fld1 ; 1
fild temp3 ; 7, 1
fdivp ST(1), ST(0) ; 1/7
fild cxClient ; cxClient, (1/7)
fmulp ST(1), ST(0) ; cxClient * (1/7)
fistp temp3 ; temp3 = ST(0), FPU stack balanced

mov ecx, 4
push esi
xor esi, esi
push edi
xor edi, edi
label2::
mov i, edi

mov temp1, 3
fild i ; i
fild temp1 ; 4, i
fdivp ST(1), ST(0) ; i/4
fild cxClient ; cxClient, i/4
fmulp ST(1), ST(0) ; cxClient*(i/4)
fistp temp1 ; temp1 = ST(0), FPU stack balanced

push ecx
invoke MoveWindow, , temp1, 0, temp2, temp3, TRUE
inc edi
add esi, 4
pop ecx
loop label2
pop edi
pop esi

    .elseif uMsg==WM_DESTROY
invoke PostQuitMessage, NULL

.else
invoke DefWindowProc, hwnd, uMsg, wParam, lParam
ret

.endif
xor eax,eax
ret
WndProc endp

ChildWndProc PROC hwnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL temp:DWORD
LOCAL hdc:HDC
LOCAL ps:PAINTSTRUCT
LOCAL rect:RECT

.if uMsg==WM_CREATE
invoke SetWindowLong,hwnd, 0, 0

.elseif uMsg==WM_LBUTTONDOWN
invoke GetWindowLong, hwnd, 0
xor eax, 1
invoke SetWindowLong, hwnd, 0, eax
invoke InvalidateRect, hwnd, NULL, FALSE

.elseif uMsg==WM_PAINT
invoke BeginPaint, hwnd, ADDR ps
mov hdc, eax
invoke GetClientRect, hwnd, addr rect
invoke Rectangle, hdc, 0, 0, rect.right, rect.bottom

invoke GetWindowLong, hwnd, 0
.if eax
invoke MoveToEx, hdc, 0, 0, NULL
invoke LineTo, hdc, rect.right, rect.bottom
invoke MoveToEx, hdc, 0, rect.bottom, NULL
invoke LineTo, hdc, rect.right, 0
.endif
invoke EndPaint, hdc , ADDR ps

.else
invoke DefWindowProc, hwnd, uMsg, wParam, lParam

.endif
xor eax, eax
ret

ChildWndProc endp
end start
Posted on 2006-08-23 06:31:37 by w0lfshad3
The problem is in your ChildWindowProc.


.
.
.
.else
invoke DefWindowProc, hwnd, uMsg, wParam, lParam
.endif
xor eax, eax
ret


There should be a ret after DefWindowProc so that it can return the value. As it is now, it always returns 0. That's why your CreateWindowEx calls appear to fail.
Posted on 2006-08-23 06:40:59 by JimmyClif
Sorry, thats a bit older code, i have a ret in there but it still doesn't work and still CreateWindowEx() returns 0 wich it shouldn't.

updated: http://wolfshade.home.ro/Project.Asm
Posted on 2006-08-23 06:45:32 by w0lfshad3
Hurray, it just stroke me, i'm using WNDCLASSEX but only RegisterClass, now some child windows started appearing after i registered them right.

So nm its fixed.
Posted on 2006-08-23 07:01:22 by w0lfshad3
Sorry I didn't get it fixed up - started at my new job monday, so I've been a bit busy. *sigh*, I almost never get stuff done in a timely fashion >_<
Posted on 2006-08-23 08:48:37 by f0dder