--------------------------------------winddow.asm--------------------------------- %include "nagoa+.inc" ;; our API macro (we can include this in our nagoa+.inc , ;; so that we need not type this macro in all pgms) %macro API 2 import %1 %2 extern %1 %endmacro API GetModuleHandleA, kernel32.dll API LoadIconA,user32.dll API LoadCursorA,user32.dll API RegisterClassExA, user32.dll API CreateWindowExA, user32.dll API MessageBoxA, user32.dll API SendMessageA, user32.dll API DefWindowProcA, user32.dll API ExitProcess, kernel32.dll API GetMessageA, user32.dll API DispatchMessageA, user32.dll API TranslateMessage,user32.dll API ShowWindow,user32.dll API UpdateWindow,user32.dll API GetCommandLineA,kernel32.dll API PostQuitMessage,user32.dll ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; segment .data USE32 Windowname db 'First Window',0 CommandLine dd 0 Windowhandle dd 0 Instance dd 0 Windowclassname db "Windowclass_1",0 OurWindowclass: istruc WNDCLASSEX at WNDCLASSEX.cbSize, dd WNDCLASSEX_size at WNDCLASSEX.style, dd CS_HREDRAW|CS_VREDRAW at WNDCLASSEX.lpfnWndProc, dd WindowProc at WNDCLASSEX.hbrBackground, dd COLOR_BTNFACE+1 at WNDCLASSEX.lpszMenuName, dd 0 at WNDCLASSEX.lpszClassName, dd Windowclassname iend Buttonhandle dd 0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; segment .bss USE32 MessageBuffer resb MSG_size ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; segment .code USE32 ..start: call GetModuleHandleA,0 mov dword [Instance], eax call GetCommandLineA mov dword [CommandLine], eax loccall WinMain, [Instance], NULL, eax, SW_SHOW call ExitProcess, eax ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; proc WinMain, hInstance, hPrevInstance, lpCmdLine, nCmdShow mov eax, dword [@hInstance] mov dword [OurWindowclass+WNDCLASSEX.hInstance], eax call LoadIconA, NULL, IDI_APPLICATION mov dword [OurWindowclass+WNDCLASSEX.hIcon], eax mov dword [OurWindowclass+WNDCLASSEX.hIconSm], eax call LoadCursorA, NULL, IDC_ARROW mov dword [OurWindowclass+WNDCLASSEX.hCursor], eax call RegisterClassExA,OurWindowclass if eax,e,0 return endif ;--- create and show the main program window call CreateWindowExA,NULL,Windowclassname,Windowname,WS_OVERLAPPED|WS_VISIBLE|WS_CAPTION|WS_MINIMIZEBOX |WS_MAXIMIZEBOX|WS_SYSMENU,200,200,400,300, NULL, NULL, [@hInstance], NULL mov dword [Windowhandle], eax call ShowWindow, [Windowhandle], [@nCmdShow] call UpdateWindow,[Windowhandle] while eax,e,eax ;;infinite loop (in order to get all messages imputed by the user ) call GetMessageA,MessageBuffer, NULL, 0, 0 if eax,g,0 call TranslateMessage,MessageBuffer call DispatchMessageA,MessageBuffer elseif eax,e,0 mov eax, dword[MessageBuffer+MSG.wParam] return else call MessageBoxA, 0, "ERROR", "Sorry ...", MB_OK return endif wend endproc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;Our window procedure proc WindowProc,hwnd,uMsg,wParam,lParam if dword [@uMsg],e,WM_CLOSE call ExitProcess,0 elseif dword [@uMsg],e,WM_DESTROY call PostQuitMessage, 0 xor eax,eax elseif dword [@uMsg],e,WM_CREATE ;;****************** ;; We can create child controls(edit boxes, buttons, listbox etc).. here.. ;;****************** BUTTON_ID equ 2000 call CreateWindowExA,NULL,"BUTTON","Click here",WS_CHILD |WS_TABSTOP|WS_VISIBLE|BS_PUSHBUTTON,125,10,100,30,[@hwnd],2000,[Instance],NULL mov [Buttonhandle],eax ;;eax => Buttonhandle elseif dword [@uMsg],e,WM_COMMAND ;;****************** ;; Button is pressed or menu item selected ..... ;;****************** if dword [@wParam],e,BUTTON_ID call MessageBoxA,[@hwnd],"Button pressed","hi",0 endif else defaultaction: call DefWindowProcA, [@hwnd], [@uMsg], [@wParam], [@lParam] endif endproc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;