I need the value of the subj.
Posted on 2002-02-16 17:48:53 by The Svin

hey while i got you here do u think you can send me the source code to the optimized generic window you made back during the old message board?
Posted on 2002-02-16 18:16:50 by smurf
Do you need optimization for size or speed.
Centered window or not?
Posted on 2002-02-16 18:46:23 by The Svin
it would be nice to study both. but if i had to chose for now i would go for speed not centered. but i didnt think you need to code up anothing because i thought you made it back on the old message board?
Posted on 2002-02-16 18:50:25 by smurf
OK compromise for speed and size:
I used data in code section for pure speed purpose you need
to put wc stuct in .data and msg in .data? sections

.model flat,stdcall
option casemap:none
include C:\masm32\include\windows.inc
include C:\masm32\include\user32.inc
include C:\masm32\include\kernel32.inc
includelib kernel32.lib
includelib user32.lib
jmp init

wc WNDCLASSEX <sizeof wc,CS_VREDRAW or CS_HREDRAW,offset WndProc,0,0,400000h,0,0,5,0,offset wc.hbrBackground,0>
msg MSG <>
init: xor edi,edi
invoke LoadCursor,edi,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx,offset wc
mov ebx,eax
mov ecx,250
and ebx,0FFFFh ;most speedy part - use atom
invoke CreateWindowEx,0,ebx,edi,
mov ebx,offset msg
@@: invoke GetMessage,ebx,edi,edi,edi
invoke DispatchMessage,ebx
jmp @B
@end: call ExitProcess
WndProc proc hWnd,uMsg,wParam,lParam
je @end
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
WndProc endp
end start
Posted on 2002-02-18 19:08:22 by The Svin
svin thank you for the code. i have a few questions though.

1. why does it crash? it doesnt even bring up a window.

2. and ebx,0FFFFh ;// i dont understand this line at all

3. you dont use a .data or a .data? section and you say this is for speed. where should i put the rest of my .data and .data? variables and such in the same place where you put yours?
Posted on 2002-02-18 21:01:39 by smurf
I checked it on both NT and 98 and it didn't cruch.
I did say absolutly oposite - but forgot to put comma -
my fault
for pure speed purpose you need to put wc stuct in .data and msg in .data? sections

Here is compiled version - try if it crashes.

I put comments about ebx - do I need write again was is written
few line below - use atom.
If you still don't understand - read about ClassName param
in CreateWindow.
Posted on 2002-02-18 21:23:38 by The Svin
Posted on 2002-02-18 21:27:39 by The Svin
EDIT your ziped program runs fine

very strange mine still crashes on me. these 2 lines are the problem it appears.

invoke LoadCursor,edi,IDC_ARROW
mov wc.hCursor,eax

when i comment out these two lines the program works but doenst respond to any cursor movements.

can you please post so i can download the same source code you assembled with?

also i use windows 2000 sp2

Posted on 2002-02-18 22:20:53 by smurf

I think you need to mark the code section as read/write, when you include data in the code section like this, under W2K. :)
Posted on 2002-02-18 22:29:02 by S/390
S/390: i moved the data and data? sections up and out of the code section and the program works fine now.

wc WNDCLASSEX <sizeof wc,CS_VREDRAW or CS_HREDRAW,offset WndProc,0,0,400000h,0,0,5,0,offset wc.hbrBackground,0>

msg MSG <>

but i fail to understand why The Svin zip file .exe ran fine for me.
Posted on 2002-02-18 22:35:12 by smurf

The code section defaults to read only.

mov wc.hCursor,eax

is trying to write to it. :)
Posted on 2002-02-18 22:44:30 by S/390
ok i understand now. but if i did want to use this method how would i mark my .code section to read and write or is this not possible?
Posted on 2002-02-18 22:51:06 by smurf
You can use the /SECTION link option. Here's the MSDN ref for link options:


I would guess this is what The Svin did. Hopefully he'll post a follow-up. :)
Posted on 2002-02-18 23:13:23 by S/390
Use this option on the linker command line.

Posted on 2002-02-18 23:15:22 by bitRAKE
bitRake is reight, to write \ read into .code section you
need to set in linking stage flags of the section as ERW

E - executable
R - readable
W - writable.

And you was right putting wc and msg into the data and data?
Read\write code section slows things down.
Just forget of this part of example.
I can name what and why know.
1. Not using WinMain - save time and bytes for calling
2. Put class struct in data sections with most members init.
Saves bytes and clocks
3. Use not changable by API registers in first stage for values
that is repeatedly used (zero etc). Saves bytes.
4. If you don't need class name for some cpecial perpose -
use for it any existing value that start with not zero byte and
ends in zero (I used in example back ground color) not big deal
but few needless bytes out.
5. The only need in most apps using PostQuitMessage - just
to go terminate inner loop so you can go to the next instruction
after it -- you can jmp directly to the next instruction without
any Posts :)
PostQuitMessage actually may be usefull - but I didn't see ANY examples here that show how to use it.
The same about ExitProcess - it's param may be used and usefull, but I didn't see here any example of usage of it, and at the same
time people always fill it for unknown reason :)
It used to send messages to process creater -
(it can look at the value bu GetExitCode) if you don't need to inform creater of anything - why people write this stupid code
of filling and sending param with Exit code?
If I need it I use it, otherwise - just call ExitProcess with whatever
is in the stack.

Don't use code you are not absolutly sure what the code is for.
This is main rule for holding control and optimal design
Posted on 2002-02-19 10:03:07 by The Svin