|
Tutorial 2. A Simple Window Last updated: 4 January 2000 by Dolphinz SUMMARY
This is my second tutorial about win32 programming,
in assembly languaje, and this time cover about how
to make our first simple window. The complete source code and
program for this tutorial can be downloaded from here :
Tutorial 2 THEORY
The window class, defines several characteristics of the window, such as it's icon, it's cursor, it's color, it's procedure... Now, let me explain, some fields of this structure: lpfnWndProc : contains the address of the window procedure, that defines how windows of this class will behave. hInstance : contains the handle for the module that "owns" the window class. And remember that, a Instance or module handle are unique only for the current program. hIcon : contains the handle of the icon to be used by the window. hCursor : contains the handle of the cursor to be used by the window. hbrBackground : contains a handle to a brush to paint the window. Here you can use a bitmap to be set as the background. lpszMenuName : contains the address of a null terminated string, defining the menu resource. This must be the same as defined in the resource script file. You can also use a number defining a menu. lpszClassName : contains the address or a null-terminated string, which specifies the class of the window. THE CODE
Now let's see the code for the second tutorial and look what has changed since last tutorial.
GetModuleHandle( ) : is the first function what I use in my program, this function returns the Instance handle of our program. The Instance handle is like the ID of our program. Several win32 API functions use the Instance handle as a parameter. RegisterClassExA( ) : is the second function I use in my program, which registers the window class, this is very important, because remember that if you want to create a window, you have to register it's class. After registering our window class, we can create our window using CreateWindowExA( ) function, and note that this function has 12 parameters:
At this point, the window handle is stored in hMain, so I save it for later use. The window we just created is not automatically displayed, so we have to use ShowWindow( ) function, with the window handle, and the desired display mode as parameters. After this, you can call the UpdateWindow( ) function, in order to repaint the client area, of the window.
Now, our window is displayed on the screen, but we can't reveice input from it, so we have to accomplish this with a message loop. The message loop, checks for the messages from windows, using the function GetMessageA( ). TranslateMessage( ) is a function that takes keyboard input and generates new messages that are placed on the message queue. And the function DispatchMessageA( ) sends the message data to our window procedure.
This code below, is the window procedure, that responds to each window message, and it's contained in the WndProc procedure. The DefWindowProcA( ) is a API function that processes all the messages, that your program is not interested in. The only one message that you must respond to is the WM_DESTROY message. This message is sent to your window procedure whenever your window is closed.
Well, this has been my second tutorial about win32asm programming, and we'll see in the next tutorial. Happy coding!... |