Title: Win32 Programming with Masm Author: Evil Homer Dated: March 7, 2004 This time we'll be adding some meat to our Main proc... We'll need to register a "window class" before we can create our window. The function RegisterClassEx will do the job. This function requires that we fill out a WNDCLASSEX structure, and hand the address of the structure to the function as a param. You might think of a structure as being a little like a FORM. Don't worry too much about all the fields in the struct, but do note the reference to another function called WndProc, which is our "Window Procedure", we'll get to that. .DATA szClassName db "MyApplication",0 hWnd dd 0 .CODE Main proc local wc:WNDCLASSEX local msg:MSG mov wc.cbSize, sizeof WNDCLASSEX mov wc.style, CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW mov wc.lpfnWndProc, offset WndProc mov wc.cbClsExtra, NULL mov wc.cbWndExtra, NULL push hInst pop wc.hInstance mov wc.hbrBackground, COLOR_BTNFACE+1 mov wc.lpszMenuName, NULL mov wc.lpszClassName, offset szClassName push hIcon pop wc.hIcon invoke LoadCursor,NULL,IDC_ARROW mov wc.hCursor,eax push hIcon pop wc.hIconSm invoke RegisterClassEx, ADDR wc Now we have registered our "window class", we can create it using CreateWindow or alternatively, CreateWindowEx which gives us more styles to choose from. Note that we are going to make a window whose top left corner is at 0,0 on our desktop, and the application window we are making is 500 by 250 in size. invoke CreateWindowEx,WS_EX_LEFT, ADDR szClassName, ADDR szDisplayName, WS_OVERLAPPED or WS_SYSMENU, 0,0,500,250, NULL,NULL, hInst,NULL mov hWnd,eax Now we have created our window, let's display it :) invoke ShowWindow,hWnd,SW_SHOWNORMAL invoke UpdateWindow,hWnd Our window has been created... the function WndProc will be called by the Window OS so we'd better make one :) We'll do that in a moment. Right now though, lets finish up the code for Main procedure. We now enter an INFINITE LOOP. During this loop,we will be monitoring something called the "Message Queue". We will be looking for a user-generated "message to quit". If we get any other kind of messages, we'll hand them to WndProc to be processed. But when we get a Quit message, we will break out of this loop, and RETurn to our EntryCode, where we will call ExitProcess and say good night. So THATS a MessagePump :) StartLoop: invoke GetMessage,ADDR msg,NULL,0,0 cmp eax, 0 je ExitLoop invoke TranslateMessage, ADDR msg invoke DispatchMessage, ADDR msg jmp StartLoop ExitLoop: ret Main ENDP Finally, our Main procedure is complete. We cannot yet compile this program however, because we need a WndProc procedure. Note we never call WndProc ourselves, as I said earlier, Windows OS will call it for us. We'll continue in the next exciting episode by creating a basic WndProc, and then we will be able to build our basic Windows application and see it on the screen :)