basically what i want to to is create a windowless program that displays an icon in the system tray. but i notice right away that it seems impossible to create such a program without registering a window so i can receive the messages. its a bummer that my memory shoots up around the 1300 area even after i strip down all i can from the WNDCLASSEX structure. is there a solution for this?

EDIT: i have another question. way back on the other message board The Svin posted some optimised code and numbered each post. the numbers went all the way up to 10 i believe and each post had a different optimization of some code. one of the them was how to create a basic window but he had optimized it. does anyone have that code for me?
Posted on 2002-02-15 21:57:14 by smurf

just start a normal window off the screen, you are usually safe by starting the top X/Y co-ordinates at about -1000.

Posted on 2002-02-15 22:20:11 by hutch--
A normal window off the screen? Why the heck not just make it
Posted on 2002-02-16 06:56:21 by f0dder
You would have to ensure it behaved like a normal window with that attribute.

Posted on 2002-02-16 08:03:17 by hutch--
errror... i must not have explained what i am trying to do well enough.

1. to receive normal window messages is it required to register a window or is there a work around?

2. if i must register a window(which i dont need) is there a more compact method than this code:
   invoke GetModuleHandle, NULL

mov hInstance, eax
invoke WinMain,hInstance,0,0,0
invoke ExitProcess,eax

; #########################################

WinMain proc hInst:DWORD, hPrevIns:DWORD, CmdLine:DWORD, CmdShow:DWORD

mov wc.cbSize, sizeof wc
mov, 0
mov wc.lpfnWndProc, offset WndProc
mov eax, hInstance
mov wc.hInstance, eax
mov wc.hIcon, 0
mov wc.hCursor, 0
mov wc.hbrBackground,0
mov wc.lpszMenuName, 0
mov wc.lpszClassName,OFFSET ClassName
invoke RegisterClassEx, addr wc

invoke CreateWindowEx, 0,addr ClassName,0,0,0,0,0,0,0,0,0,0

invoke GetMessage,ADDR msg,NULL,0,0
cmp eax, 0
je ExitLoop
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
jmp StartLoop

mov eax,msg.wParam

WinMain endp

3. The Svin posted an optimized version of how to create a simple window on the old message board. does anyone have the code or will i need to ask him directly?
Posted on 2002-02-16 10:09:27 by smurf
i was doing somthing similiar
a program that will sit i taskbar and on left button click it will present menu with options, no needs for real window on screen

so i just registrated window class and created windows becouse in order to recive wm messages u have to at least register windows
and i didnt used ShowWindow at all, its no needed
and app runs fine

so i think that this code is compact as much as it can be
Posted on 2002-02-18 17:46:41 by Mikky
You don't need to register a window, you just need to create a window or a dialog box.

Any control can be used as a window, although there might be some problems with using them as main windows. For one, you'll need to subclass them to make them quit the program.

With a dialog box, you trade size of executable with size of resources.

With a normal window, you can also declare wc as global in .data and initialize all the constant values in .data. You only need to set the hInstance field in executable code.
Posted on 2002-02-18 20:27:27 by tank
tank: if you dont mind i would like for you for to write an example of creating a window without registering it and still be able to receive the normal WM_CREATE etc messages. i dont really see how it can be possible.
Posted on 2002-02-18 23:20:48 by smurf
There shouldn't be any real problems smurf. Simply create a static or button control with CreateWindow, then subclass it. I'd go for a button with the ownerdraw style.

You'll miss the WM_CREATE message as by the time you've subclassed it that will has have been sent, but you'll get all the rest.
Posted on 2002-02-19 02:35:44 by Eóin

What you are after will not save you much space in disk size terms and thats if you can get it to work, a normal window with a registered class is still very small, as long as you don't use any resources like an icon or menu or otherwise.

One of Alex's tricks was to write the WNDCLASSEX in the DATA section and add the necessary code dynamically to it in the WinMain but its hard to measure the size difference as PE files are built in 512 byte increments using the linker from the win98ddk.

The advantage of using a normal window is that it processes everything in the normal manner which saves you a lot of messing around.

Good luck with it.
Posted on 2002-02-19 03:24:27 by hutch--

Here is the code for a 1.5k window and its all normal stuff with no hacks or non standard PE stuff.


PS: Build it with the supplied batch file and have a look at how its done.

Use the next version posted below.
Posted on 2002-02-19 03:45:04 by hutch--
Hutch, this is a problem I've never seen before but the code crashes here
00401060 push 0
00401062 call 00401220
00401067 mov [00401230],eax
0040106C push 7F00h
00401071 push 0
00401073 call 004011F6
00401078 mov [0040123C],eax
0040107D call 00401088
00401082 push eax
00401083 call 0040121A

which to the best of my knowledge is the following line of code
invoke GetModuleHandle,NULL
mov hInstance,eax

This is a college PC I'm on running Win NT, could that be related to the problem.
Posted on 2002-02-19 04:41:03 by Eóin

Thnks for finding this one, NT4 spits the dummy because of the multiple /MERGE lines but building it without them produces a file at 2k so it may do what smurf is after.

I just tweaked it again and it now runs on NT4 sp6a at 1.5k

Next version attached.

Posted on 2002-02-19 04:58:12 by hutch--

NT4 spits the dummy because of the multiple /MERGE lines

Merged all sections and forgot to set the main section as rwe?
Posted on 2002-02-19 07:19:18 by f0dder
Feel free to write a smaller version yourself. :tongue:

Posted on 2002-02-19 14:58:19 by hutch--