Ok, I started by creating a main window, then upon menu click, create a new window, but when I close that window with DestroyWindow then shut the main program down, the process still runs, couldn't figure it out so I stopped that project for the time being. Now here is my question, I want to create 5 text boxes and 5 buttons.... Started by doing:



invoke CreateWindowEx,\
WS_EX_CLIENTEDGE,\
ADDR WndClsText,\
NULL,\
WS_VISIBLE + WS_CHILDWINDOW + ES_AUTOHSCROLL + ES_NOHIDESEL,\
1,\ ; Left
1,\ ; Top
302,\ ; Width
20,\ ; Height
hwnd,\
NULL,\
hInstance,\
NULL
invoke SendMessage, eax, WM_SETFONT, hFont, NULL

and I would do this 5 times to create 5 different text boxes(Yes, I would increase the top value) which worked, but then I said there has to be an easier way... then I looked into loops... Well I tried:


push ecx
xor ecx, ecx
mov ecx, 5
.WHILE ecx != 0
invoke CreateWindowEx,\
WS_EX_CLIENTEDGE,\
ADDR WndClsText,\
NULL,\
WS_VISIBLE + WS_CHILDWINDOW + ES_AUTOHSCROLL + ES_NOHIDESEL,\
1,\ ; Left
Some value here!,\ ; Top
302,\ ; Width
20,\ ; Height
hwnd,\
NULL,\
hInstance,\
NULL
invoke SendMessage, eax, WM_SETFONT, hFont, NULL

sub ecx, 1
.ENDW
pop ecx


and that put my progam into some kind of loop.. and either the program would not start (stays in some kind of loop) or the main window would show but no text boxes! ( I don't remember, playing around with too much code) :(
Then I found the debug libs and I tried:



push ecx
xor ecx, ecx
mov ecx, 5
.WHILE ecx != 0
PrintDec ecx
sub ecx, 1
.ENDW
pop ecx


Which prints correctly! Why is my CreateWindow loop not working? Is there an easier (better) way of creating more then one textbox (besides Dialogs)?
Posted on 2002-06-24 23:20:55 by Gunner
Try this:
xor ecx, ecx

mov ecx, 5
.WHILE ecx != 0
push ecx
invoke CreateWindowEx,\
WS_EX_CLIENTEDGE,\
ADDR WndClsText,\
NULL,\
WS_VISIBLE + WS_CHILDWINDOW + ES_AUTOHSCROLL + ES_NOHIDESEL,\
1,\ ; Left
Some value here!,\ ; Top
302,\ ; Width
20,\ ; Height
hwnd,\
NULL,\
hInstance,\
NULL
invoke SendMessage, eax, WM_SETFONT, hFont, NULL
pop ecx
dec ecx
.ENDW
Your ecx was destroyed by the CreateWindowEx And SendMessage, try pushing ecx before the API call and pop it afterwards. :) remember to push any registers except ebx esi and edi if you plan to use them after an API call.
Posted on 2002-06-24 23:37:43 by stryker
Outstanding!!! Thanks Stryker! Have to keep this in mind.
Posted on 2002-06-25 09:35:52 by Gunner
personally i make a different procedure for each controls i make that way i dont have to pass the class, and styles to my procedure only a unique ID. The top code example is a single procedure you can use but i prefer the second example. use procedures makes your code much more readable i think.
   ID_BTN1    equ 2000

ID_BTN2 equ 2001

.data
WndEditCls db "edit",0
WndBtnCls db "button",0

.data?
hEdit1 HANDLE ?
hEdit2 HANDLE ?
hButton1 HANDLE ?
hButton2 HANDLE ?

.code
.IF uMsg == WM_CREATE
;// Create EditBox's
invoke CreateControls,WndEditCls,WS_VISIBLE + WS_CHILDWINDOW + ES_AUTOHSCROLL + ES_NOHIDESEL,0
mov hEdit1,eax
invoke CreateControls,WndEditCls,WS_VISIBLE + WS_CHILDWINDOW + ES_AUTOHSCROLL + ES_NOHIDESEL,0
mov hEdit2,eax
;// Create Buttons
invoke CreateControls,WndBtnCls, WS_VISIBLE + WS_CHILDWINDOW,ID_BTN1
mov hButton1,eax
invoke CreateControls,WndBtnCls, WS_VISIBLE + WS_CHILDWINDOW,ID_BTN2
mov hButton2,eax


;=========================================================
CreateControls proc CLASS:DWORD,STYLES:DWORD,ID:DWORD
invoke CreateWindowEx,\
WS_EX_CLIENTEDGE,\
CLASS,\
NULL,\
STYLES,\
1,\ ; Left
1,\ ; Top
302,\ ; Width
20,\ ; Height
hwnd,\
ID,\
hInstance,\
NULL
push eax
invoke SendMessage, eax, WM_SETFONT, hFont, NULL
pop eax
ret
CreateControls endp

example 2:
   ID_BTN1    equ 2000

ID_BTN2 equ 2001

.data
WndEditCls db "edit",0
WndBtnCls db "button",0

.data?
hEdit1 HANDLE ?
hEdit2 HANDLE ?
hButton1 HANDLE ?
hButton2 HANDLE ?

.code
.IF uMsg == WM_CREATE
;// Create EditBox's
invoke CreateEdit
mov hEdit1,eax
invoke CreateEdit
mov hEdit2,eax
;// Create Buttons
invoke CreateControls,ID_BTN1
mov hButton1,eax
invoke CreateControls,ID_BTN2
mov hButton2,eax


;=================================================
CreateEdit proc
invoke CreateWindowEx,\
WS_EX_CLIENTEDGE,\
WndEditCls,\
NULL,\
WS_VISIBLE + WS_CHILDWINDOW + ES_AUTOHSCROLL + ES_NOHIDESEL,\
1,\ ; Left
1,\ ; Top
302,\ ; Width
20,\ ; Height
hwnd,\
ID,\
hInstance,\
NULL
push eax
invoke SendMessage, eax, WM_SETFONT, hFont, NULL
pop eax
ret
CreateEdit endp
;=================================================
CreateButton proc ID:DWORD
invoke CreateWindowEx,\
WS_EX_CLIENTEDGE,\
WndBtnCls,\
NULL,\
WS_VISIBLE + WS_CHILDWINDOW,\
1,\ ; Left
1,\ ; Top
302,\ ; Width
20,\ ; Height
hwnd,\
ID,\
hInstance,\
NULL
push eax
invoke SendMessage, eax, WM_SETFONT, hFont, NULL
pop eax
ret
CreateButton endp
Posted on 2002-06-25 09:44:20 by smurf
gunner,

A couple of things, when you make a function call like CreateWindowEx where you split it across different lines, you only need to leave a trailing comma (,) to continue the line, saves you the extra typing.

My approach for multiple windows is to put the CreateWindowEx call in its own proc then call it the number of times you need. I do this with all of the normal controls as the code is fully reusable if you write it properly, you just pass stuff to the procedure like different strings and styles etc ...

This way you get the handle of each window as the return value and you have a tidy style of code.

Regards,

hutch@movsd.com
Posted on 2002-06-25 10:46:23 by hutch--