#basic template of a Windows program. Modify to your requirement. begin imports #many frequently used functions are here [Kernel32.dll] GetModuleHandleA GetCommandLineA LoadLibraryA ExitProcess GlobalAlloc GlobalSize GlobalFree GlobalReAlloc Sleep CreateFileA ReadFile WriteFile CloseHandle GetFileSize CreateThread CreateProcessA SuspendThread ResumeThread ExitThread TerminateThread [user32.dll] RegisterClassExA CreateWindowExA ShowWindow UpdateWindow DefWindowProcA GetMessageA TranslateMessage DispatchMessageA SendMessageA LoadCursorA LoadIconA LoadMenuA BeginPaint EndPaint DrawTextA GetClientRect PostQuitMessage MessageBoxA SetForegroundWindow SetActiveWindow BringWindowToTop FindWindowA DestroyWindow PostMessageA CreatePopupMenu AppendMenuA SetMenu CreateMenu GetCursorPos TrackPopupMenu SetFocus ExitWindowsEx [gdi32.dll] CreateFontIndirectA Rectangle CreateSolidBrush SelectObject SetBkMode ExtFloodFill CreatePen SetTextColor [comctl32.dll] InitCommonControls [comdlg32.dll] GetOpenFileNameA GetSaveFileNameA [crtdll.dll] fopen fclose fgets fputs fgetc fputc feof malloc realloc free fread fwrite fprintf fscanf _itoa memcpy memcmp memmove memset sprintf atoi strcpy strstr strncat end imports #-----------------Constants---------------------------------------------- begin const #many commonly used constants are here SW_HIDE 0 SW_SHOW 5 WS_CHILD 1073741824 WS_VISIBLE 268435456 WS_BORDER 8388608 WS_HSCROLL 1048576 WS_VSCROLL 2097152 WS_CAPTION 12582912 WS_CHILDWINDOW 1073741824 WS_OVERLAPPEDWINDOW 13565952 WS_POPUPWINDOW 2156396544 WS_SYSMENU 524288 WS_CLIENTEDGE 512 WS_MINIMIZEBOX 131072 WS_MAXIMIZEBOX 65536 WS_SIZEBOX 262144 WM_CREATE 1 WM_COPY 769 WM_CUT 768 WM_PASTE 770 WM_CLOSE 16 WM_COMMAND 273 WM_DESTROY 2 WM_ENABLE 10 WM_GETTEXT 13 WM_GETTEXTLENGTH 14 WM_INITDIALOG 272 WM_INITMENU 278 WM_KEYDOWN 256 WM_KEYUP 257 WM_KILLFOCUS 8 WM_LBUTTONDBLCLK 515 WM_LBUTTONDOWN 513 WM_LBUTTONUP 514 WM_MOVE 3 WM_NOTIFY 78 WM_PAINT 15 WM_ACTIVATE 6 WM_QUIT 18 WM_RBUTTONDBLCLK 518 WM_RBUTTONDOWN 516 WM_RBUTTONUP 517 WM_SETFOCUS 7 WM_SETFONT 48 WM_SETTEXT 12 WM_SIZE 5 WM_TIMER 275 WM_UNDO 772 BS_AUTOCHECKBOX 3 BS_AUTORADIOBUTTON 9 BS_GROUPBOX 7 LB_ADDSTRING 384 LB_RESETCONTENT 388 LB_SELECTSTRING 396 LB_SETTOPINDEX 407 LBS_HASSTRINGS 64 DT_SINGLELINE 32 DT_CENTER 1 DT_VCENTER 4 DT_BOTTOM 8 IDI_APPLICATION 32512 IDC_CROSS 32515 ES_AUTOVSCROLL 64 ES_AUTOHSCROLL 128 ES_MULTILINE 4 ES_WANTRETURN 4096 ES_LEFT 0 ES_NOHIDESEL 256 EN_MSGFILTER 1792 EN_CHANGE 768 ENM_MOUSEEVENTS 131072 ENM_SELCHANGE 524288 ENM_PROTECTED 2097152 ENM_KEYEVENTS 65536 ENM_UPDATE 2 ENM_SCROLL 4 ENM_CHANGE 1 EM_STREAMIN 1097 EM_STREAMOUT 1098 EM_GETFIRSTVISIBLELINE 206 EM_FINDTEXTEX 1103 EM_LINEFROMCHAR 201 EM_LINESCROLL 182 EM_SETLIMITTEXT 197 EM_SETEVENTMASK 1093 MF_ENABLED 0 MF_BYPOSITION 1024 MF_SEPARATOR 2048 MF_STRING 0 MF_POPUP 16 MF_DISABLED 2 MF_BYCOMMAND 0 GENERIC_READ 2147483648 GENERIC_WRITE 1073741824 OPEN_EXISTING 3 FILE_ATTRIBUTE_NORMAL 128 GMEM_ZEROINIT 64 SFF_SELECTION 32768 SFF_PLAINRTF 16384 SF_TEXT 1 SF_RTF 2 CB_ADDSTRING 323 CB_DELETESTRING 324 CB_GETCOUNT 326 CB_GETLBTEXT 328 CB_GETLBTEXTLEN 329 CB_INSERTSTRING 330 CB_RESETCONTENT 331 CB_GETCURSEL 327 CB_SETCURSEL 334 CB_FINDSTRINGEXACT 344 CBS_DROPDOWN 2 CBS_DROPDOWNLIST 3 CBS_HASSTRINGS 512 CBS_SORT 256 CBS_SIMPLE 1 CBN_DROPDOWN 7 CBN_SELENDOK 9 CBN_SELCHANGE 1 CBN_CLOSEUP 8 OFN_EXPLORER 524288 OFN_HIDEREADONLY 4 OFN_LONGNAMES 2097152 OFN_PATHMUSTEXIST 2048 MB_ICONASTERISK 64 end const #-----------------Data Section------------------------------------------- #some useful predefined variables are here begin data dword hwndMain 0 string Class Window dword hInstance 0 string ClassName WinClass string AppName Windows Template ! string MenuName Menu string btn button string text Edit string combo combobox string list listbox string label static string rich RICHED32.DLL string riched RICHEDIT string colon : dword quit 0 string font1 ms sans serif string font2 Courier New sequence fon1 60 sequence fon2 60 dword hfont1 0 dword hfont2 0 string ofnfilter All Files string read r string write w string readb rb string writeb wb string WindowCaption Quick Exit Or ReBoot By Yves Turgeon string ab About ... string ab1 MyApp Version 1.0 string ab2 by .... string ab3 ---------------------------------------------------- string spc string spc6 dword hmenu 0 dword hfilemenu 0 dword heditmenu 0 dword hviewmenu 0 dword hhelpmenu 0 string fmenu &File string new &New string open &Open string save &Save string hyphen - string exit E&xit string emenu &Edit string undo &Undo string cut &Cut string copy C&opy string paste &Paste string find &Find... string replace &Replace... string selall &Select All string pmenu &Help string about &About ... sequence buffer 256 sequence buf 48 sequence listbuf 48 sequence icobuf 24 sequence pt 8 sequence ofnfname 256 dword htext1 0 dword htext2 0 dword htext3 0 dword htext4 0 dword htext5 0 dword hbtn1 0 dword hbtn2 0 dword hbtn3 0 dword hbtn4 0 dword hbtn5 0 dword hbtn6 0 dword hbtn7 0 dword hlist 0 dword hlist1 0 dword hcombo1 0 sequence blank 1 dword CommandLine 0 dword hmem 0 sequence wndclass 16 sequence msg 28 sequence ibuf 32 dword mem 0 dword vHbtn1 0 string btnCaption1 Shut Down dword vHbtn2 0 string btnCaption2 ReBoot dword dataend 4294967295 end data #------------------------------------------------------------------------- begin code #the real code begin here ! proc WndProc dword hwnd dword msg dword wparam dword lparam dword fn 0 dword hdc 4 sequence ps 64 sequence rect 16 dword ordata 0 dword n 0 dword m 0 dword x 0 dword y 0 push ebp mov ebp esp add esp -180 cmp msg {WM_CREATE} je wmcreate cmp msg {WM_PAINT} je wmpaint cmp msg {WM_COMMAND} je wmcommand cmp msg {WM_DESTROY} jne default push 0 call PostQuitMessage jmp exit wmcreate: mov eax {WS_CHILD} or eax {WS_VISIBLE} or eax {WS_BORDER} vHbtn1 = CreateWindowExA 0 btn btnCaption1 eax 2 2 150 35 hwnd 0 hInstance 0 invoke SendMessageA vHbtn1 {WM_SETFONT} hfont1 0 mov eax {WS_CHILD} or eax {WS_VISIBLE} or eax {WS_BORDER} vHbtn2 = CreateWindowExA 0 btn btnCaption2 eax 155 2 150 35 hwnd 0 hInstance 0 invoke SendMessageA vHbtn2 {WM_SETFONT} hfont1 0 jmp exit wmpaint: lea eax ps invoke BeginPaint hwnd eax mov hdc eax lea eax ps invoke EndPaint hwnd eax jmp exit wmcommand: #menu items if lparam = 0 if wparam = 101 jmp exit endif if wparam = 102 jmp exit endif if wparam = 200 jmp exit endif if wparam = 202 jmp exit endif if wparam = 203 jmp exit endif if wparam = 204 endif if wparam = 806 endif jmp default endif #end of menu items btn1: mov eax vHbtn1 cmp lparam eax jne btn2 invoke ExitWindowsEx 1 # Flags for ExitWindowEx # EWX_LOGOFF equ 0 # EWX_SHUTDOWN equ 1 # EWX_REBOOT equ 2 # EWX_FORCE equ 4 # EWX_POWEROFF equ 8 jmp exit btn2: mov eax vHbtn2 cmp lparam eax jne btn3 invoke ExitWindowsEx 2 jmp exit btn3: mov eax hbtn3 cmp lparam eax jne btn4 jmp exit btn4: mov eax hbtn4 cmp lparam eax jne btn5 jmp exit btn5: mov eax hbtn5 cmp lparam eax jne btn6 jmp exit btn6: mov eax hbtn6 cmp lparam eax jne default jmp exit default: invoke DefWindowProcA hwnd msg wparam lparam leave ret 16 exit: xor eax eax leave ret 16 endp #------------------------------------------------------------------------ proc WinMain dword hinst dword previnst dword comline dword cmdshow sequence wc 48 dword ordata 0 dword len 0 dword topmenu 0 dword dropmenu 0 dword sepmenu 0 push ebp mov ebp esp add esp -80 call CreateMenu hfilemenu=eax call CreateMenu heditmenu=eax call CreateMenu hviewmenu=eax call CreateMenu hhelpmenu=eax call CreateMenu hmenu=eax mov eax {MF_STRING} or eax {MF_POPUP} or eax {MF_BYPOSITION} or eax {MF_ENABLED} topmenu=eax mov eax {MF_STRING} or eax {MF_ENABLED} dropmenu=eax mov eax {MF_STRING} or eax {MF_SEPARATOR} sepmenu=eax invoke AppendMenuA hmenu topmenu hfilemenu fmenu invoke AppendMenuA hfilemenu dropmenu 100 new invoke AppendMenuA hfilemenu dropmenu 101 open invoke AppendMenuA hfilemenu dropmenu 102 save invoke AppendMenuA hfilemenu sepmenu 103 hyphen invoke AppendMenuA hfilemenu dropmenu 104 exit invoke AppendMenuA hmenu topmenu heditmenu emenu invoke AppendMenuA heditmenu dropmenu 200 undo invoke AppendMenuA heditmenu sepmenu 201 hyphen invoke AppendMenuA heditmenu dropmenu 202 cut invoke AppendMenuA heditmenu dropmenu 203 copy invoke AppendMenuA heditmenu dropmenu 204 paste invoke AppendMenuA heditmenu sepmenu 205 hyphen invoke AppendMenuA heditmenu dropmenu 206 find invoke AppendMenuA heditmenu dropmenu 207 replace invoke AppendMenuA heditmenu sepmenu 208 hyphen invoke AppendMenuA heditmenu dropmenu 209 selall invoke AppendMenuA hmenu topmenu hhelpmenu pmenu invoke AppendMenuA hhelpmenu dropmenu 806 about mov eax fon2 mov [eax] 16 add eax 16 mov [eax] 400 add eax 12 invoke strcpy eax font2 hfont2 = CreateFontIndirectA fon2 mov eax fon1 mov [eax] 10 add eax 16 mov [eax] 400 add eax 12 invoke strcpy eax font1 hfont1 = CreateFontIndirectA fon1 [wc]= 48 [wc+4] =3 [wc+8]= WndProc [wc+12]= 0 [wc+16] =0 eax =hInstance [wc+20]= eax push 1 push hInstance call LoadIconA [wc+24]= eax [wc+44]= eax push {IDC_CROSS} push 0 call LoadCursorA [wc+28] =eax [wc+32]= 16 [wc+36]= 0 [wc+40]= ClassName lea eax wc invoke RegisterClassExA eax or eax {WS_SYSMENU} or eax {WS_MINIMIZEBOX} or eax {WS_SIZEBOX} ordata=eax invoke CreateWindowExA {WS_CLIENTEDGE} ClassName WindowCaption ordata 50 50 320 80 0 0 hInstance 0 hwndMain= eax #this is old style before the advent of invoke push 1 push hwndMain call ShowWindow push hwndMain call UpdateWindow MsgLoop: invoke GetMessageA msg 0 0 0 cmp eax 0 je exitprocess invoke TranslateMessage msg invoke DispatchMessageA msg jmp MsgLoop exitprocess: mov eax [msg+8] leave ret 16 endp #------------------------------------------------------------------------ EntryPoint #this is old style before the advent of invoke push 0 call GetModuleHandleA mov hInstance eax call GetCommandLineA mov CommandLine eax invoke WinMain hInstance 0 CommandLine 10 push eax call ExitProcess end code #-----------------Resources--------------------------------------- begin resources icon win32app.ico end resources