| Index | Manual | Download | Source | Macros | Embedded word Case ins.
Sitemap | Links | Forum | Tests | Projects

# skelet32.htm
Header
Resource
WinMain
WndCreate
WndProc

Skeleton is a sample program for MS Windows which uses Graphic User Interface (GUI) and Windows resources (menu and icon).

It displays a white window with standard menu on the top and simple status bar on the bottom.

Program can be assembled in ANSI or WIDE (UNICODE) version, which is selected by `EUROASM UNICODE=` option in the Header . No other intervention in source text is required, because all strings are defined with unspecified character width, and all system calls are managed by macro WinAPI, which automatically selects ANSI or WIDE version.

Format
  PE 32bit FLAT GUI
Platform
  MS Windows. It works in 32bit and 64bit Windows.
Import-library build
  If you don't have the import library ..\objlib\winapi.lib yet,
  compile in prowin32 subdirectory with command `euroasm dll2lib.htm`.
Resource build
  If you have changed resource script source , generate the script ..\objlib\skelet.rc with command `euroasm skelet32.htm` in directory ..\prowin32\,
  then use 3rd party resource compiler and compile the script ..\objlib\skelet.rc
  to the module ..\objlib\skelet.res with command `rc.exe skelet.rc` in directory ..\objlib\.
Build
  Assemble the project in ..\prowin32\ directory with command `euroasm skelet32.htm`.
Run
  `skelet32.exe`

Header

  The header specifies program format, included macrolibraries, linked import library and other modules.

  > Included macrolibraries are available in subdirectory ..\maclib\.

  > If you don't have the linked import library winapi.lib, you can create it with sample project DLL2LIB.

  > If you don't have the linked resource module skelet.res, you can create it with `rc.exe ..\objlib\skelet.rc`.

  The header defines numeric menu identificators `%MenuId*` which will be used both in resource script (`skelet PROGRAM` ) and in the window procedure of the main `skelet32 PROGRAM` . That is why they have the form of preprocessing %variables rather than EQU symbols.
  Menu identificator values are chosen arbitrary, they are biased by the constant WM_APP to avoid collision with other internal MS Windows message identifiers.

                 EUROASM UNICODE=Enabled     ; This option selects ANSI or WIDE version.
                 INCLUDE "winsgui.htm"       ; This file defines the constant WM_APP.
    %IconResName %SET SkeletIcon
    %MenuResName %SET SkeletMenu
    %MenuIdExit  %SETA WM_APP + 1
    %MenuIdHelp  %SETA WM_APP + 2
    %MenuIdAbout %SETA WM_APP + 3
    %StatusBarId %SETA WM_APP + 9
    ;;
    skelet32     PROGRAM Format=PE, Subsystem=GUI, Width=32, Entry=WinMain
                   INCLUDE winapi.htm, wins.htm, winsgui.htm, stdcal32.htm, \
                           cpuext.htm, cpuext32.htm
                   LINK winapi.lib, skelet.res

Resource

  Resources of this project are defined here in the form of text file skelet.rc created by an embedded program block named skelet.

  The resource script skelet.rc will be created in subdirectory ..\objlib\ and it has to be compiled to ..\objlib\skelet.res by an external resource compiler (EuroAssembler cannot compile resources).

  Resource script may be written in ASCII or UNICODE encoding (OEM or WIDE), because Microsoft Resource Compiler rc.exe available in [WindowsSDK] treats both variants equally.

Documented
  [RC]

    skelet PROGRAM Format=BIN, OutFile="..\objlib\skelet.rc"
    D ' /* Resource definition for skeleton programs        ',13,10
    D '     which are shipped with EuroAssembler. */        ',13,10
    D '%IconResName ICON "..\objlib\skelet.ico"             ',13,10
    D '%MenuResName MENU                                    ',13,10
    D '              BEGIN                                  ',13,10
    D '                POPUP "&File"                        ',13,10
    D '                BEGIN                                ',13,10
    D '                  MENUITEM "E&xit  [Esc]",%MenuIdExit',13,10
    D '                END                                  ',13,10
    D '                POPUP "&Help"                        ',13,10
    D '                BEGIN                                ',13,10
    D '                  MENUITEM "&Help  [F1]",%MenuIdHelp ',13,10
    D '                  MENUITEM "&About [F2]",%MenuIdAbout',13,10
    D '                END                                  ',13,10
    D '               END                                   ',13,10
           ENDPROGRAM skelet

WinMain

  This is the main program entry procedure which represents the target executable skelet32.exe.

Invoked by
  MS Windows loader.
Invokes
  WndCreate

    [.data]
    InfoText   D "Skeleton of Windows program written in EuroAssembler."
               DU 0 ; This NUL character works both for ANSI and WIDE variants.
    HelpText   D "Press [F1] to show this help.",13,10, \
                 "Press [F2] to show information about this program.",13,10, \
                 "Press [Esc] to quit the program.",0
    %IF %^UNICODE
      %Char %SET UNICODE
    %ELSE
      %Char %SET ANSI
    %ENDIF
    AboutText  D "This %Char %^WIDTH[]bit program %^PROGRAM.exe was created",13,10, \
                 "by EuroAssembler ver.%^VERSION %^EUROASMOS",13,10, \
                 "on %^DATE[7..8].%^DATE[5..6].%^DATE[1..4] %^TIME[1..2]:%^TIME[3..4] UTC.",0
    StatusInfo D "Status bar displays information about menu items.",0
    [.bss]
    Msg        D MSG           ; Window message.
    [.text]
    WinMain PROC                      ; Program entry point.
         Clear SEGMENT#[.bss],Size=SIZE#[.bss] ; Make sure to start with zeroed memory of uninitialized reserved data.
         CALL WndCreate               ; Initialize the program window.
    .MsgLoop:
         WinAPI GetMessage, Msg,0,0,0
         TEST EAX
         JZ .MsgQuit:                 ; ZF signalises message WM_QUIT - request for program termination.
         WinAPI TranslateMessage, Msg ; Remap character keys from national keyboards.
         WinAPI DispatchMessage,  Msg ; Let Windows call our WndProc.
         JMP .MsgLoop:                ; Wait for another message.
    .MsgQuit:
         TerminateProgram Errorlevel=[Msg.wParam]
      ENDPROC WinMain

WndProc, hWnd, uMsg, wParam, lParam
  This is a callback procedure which receives and handles messages for the program window.
  Involved messages are dispatched to their handlers.
  Ignored messages are passed to DefWindowProc.
Handler Input
  EAX=uMsg, EBX=hWnd, ESI=wParam, EDI=lParam.
Handler Output
  EAX=0 if the message was completely processed by the handler. Otherwise the message is processed by WinAPI DefWindowProc and EAX outputs its return value.
  EBX,ECX,EDX,ESI,EDI may be destroyed in the handlers.
Invoked by
  WinAPI DispatchMessage.

    [.bss]
    PaintStruct  DS PAINTSTRUCT ; Structured variable used in painting.
    hDC          D DWORD        ; Handle od device context used in painting.
    [.text]
    WndProc Procedure hWnd, uMsg, wParam, lParam
         MOV EBX,[%hWnd]
         MOV EAX,[%uMsg]
         MOV ESI,[%wParam]
         MOV EDI,[%lParam] ; Load msg attributes to registers for handler's convenience.
        ; Fork message uMsg=EAX to its handler using macro Dispatch:
         Dispatch EAX, WM_CREATE, WM_DESTROY, WM_PAINT, WM_KEYDOWN, WM_COMMAND, WM_MENUSELECT
    .Def:WinAPI DefWindowProc,[%hWnd],[%uMsg],[%wParam],[%lParam]  ; Ignored events pass to DefWindowProc.
         JMP .Ret:  ; Go to EndProcedure WndProc with value EAX returned from DefWindowProc.
         ; Message handlers terminate with a jump to label .Def: or .Ret0:.
    .WM_CREATE: ; The main window is being created.
         WinAPI SendMessage,[hStatusBar],SB_SIMPLE,1,0  ; Tell the status bar to be simple.
         WinAPI SendMessage,[hWindow],WM_MENUSELECT,0,0 ; Initialize status bar with StatusInfo.
         JMP .Ret0:
    .WM_PAINT:  ; Window needs to repaint its contents.
         WinAPI BeginPaint,[hWindow],PaintStruct
         MOV [hDC],EAX
         WinAPI TextOut,[hDC],30,30,InfoText, SIZE# InfoText << %^UNICODE ; TextOutW expects text size in characters.>>
         WinAPI EndPaint,[hWindow],PaintStruct
         JMP .Ret0:
    .WM_COMMAND:   ; User selected menu item identified by ESI=wParam.
         Dispatch ESI, %MenuIdExit, %MenuIdHelp, %MenuIdAbout
         JMP .Def: ; Pass unhandled items to WinAPI DefWindowProc.
    .WM_KEYDOWN:   ; Non-character hot key ESI=wParam was pressed.
         Dispatch ESI, VK_ESCAPE, VK_F1, VK_F2
         JMP .Def: ; Pass unhandled keys to WinAPI DefWindowProc.
    .%MenuIdExit:  ; Menu Exit selected.
    .VK_ESCAPE:    ; Esc pressed.
         WinAPI SendMessage,EBX,WM_DESTROY,0,0
         JMP .Ret0:
    .%MenuIdHelp:  ; Menu Help selected.
    .VK_F1:        ; F1 pressed.
         WinAPI MessageBox,[hWindow],HelpText,WndClassName,MB_ICONINFORMATION
         JMP .Ret0:
    .%MenuIdAbout: ; Menu About selected.
    .VK_F2:        ; F2 pressed.
         WinAPI MessageBox,[hWindow],AboutText,WndClassName,MB_ICONINFORMATION
         JMP .Ret0:
    .WM_MENUSELECT: ; User unrolled a menu item. Show online help in status bar.
    MenuStatus PROC ; Namespace MenuStatus is used to avoid collision in %MenuId* labels.
         AND ESI,0x0000_FFFF  ; Menu identifier is in the low word of wParam.
         Dispatch ESI,%MenuIdExit,%MenuIdHelp,%MenuIdAbout
         MOV EDI,StatusInfo ; Use neutral StatusInfo help text for undispatched menu items.
     .ShowStatus:WinAPI SendMessage,[hStatusBar],SB_SETTEXT,SB_SIMPLEID,EDI
         JMP WndProc.Ret0:
     .%MenuIdExit: MOV EDI,="Terminate program."
                   JMP .ShowStatus:
     .%MenuIdHelp: MOV EDI,="Show help information."
                   JMP .ShowStatus:
     .%MenuIdAbout:MOV EDI,="Show information about this program."
                   JMP .ShowStatus:
     ENDP MenuStatus
    .WM_DESTROY: ; Program terminates.
         WinAPI PostQuitMessage,0     ; Tell Windows to quit this program with errorlevel 0.
        ; JMP .Ret0:
    .Ret0:
          XOR EAX,EAX
    .Ret: MOV [%ReturnEAX],EAX
        EndProcedure WndProc

WndCreate
  Program skelet32.exe uses one graphical window. Procedure WndCreate constructs the window class and window object.
Called by
  WinMain

    [.data]
    WndClassName D "SKELET",0
    [.bss]
    WndClassEx DS WNDCLASSEX ; Definition of the window class structure.
    hWindow    D DWORD       ; Handle of the window object.
    hStatusBar D DWORD       ; Handle of the status bar.
    [.text]
    WndCreate PROC
        ; Register class SKELET for the main window.
        MOV [WndClassEx.cbSize],SIZE# WNDCLASSEX
        MOV [WndClassEx.lpszClassName],WndClassName
        MOV [WndClassEx.style],CS_HREDRAW|CS_VREDRAW
        MOV [WndClassEx.lpfnWndProc],WndProc
        WinAPI GetModuleHandle,0
        MOV [WndClassEx.hInstance],EAX
        WinAPI LoadIcon,EAX,="%IconResName"  ; Icon name used in resources.
        MOV [WndClassEx.hIcon],EAX
        WinAPI LoadCursor,0,IDC_HAND         ; Load cursor shape from stock.
        MOV [WndClassEx.hCursor],EAX
        WinAPI GetStockObject,WHITE_BRUSH    ; Default window background colour.
        MOV [WndClassEx.hbrBackground],EAX
        MOV [WndClassEx.lpszMenuName],="%MenuResName" ; Menu name used in resources.
        WinAPI RegisterClassEx,WndClassEx
        ; Define the main window.
        WinAPI CreateWindowEx, WS_EX_CLIENTEDGE,                        \
               WndClassName, WndClassName, WS_OVERLAPPEDWINDOW,         \
               CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT, \
               0, 0, [WndClassEx.hInstance], 0
        MOV [hWindow],EAX
        MOV EBX,EAX
        ; Define status bar as the child of the main window.
        WinAPI CreateStatusWindow,WS_CHILD+WS_BORDER+WS_VISIBLE,StatusInfo,EBX,%StatusBarId
        MOV [hStatusBar],EAX
        WinAPI ShowWindow, EBX, SW_SHOWNORMAL
        WinAPI UpdateWindow, EBX
        RET
       ENDP WndCreate

       ENDPROGRAM skelet32

▲Back to the top▲