flat assembler
Message board for the users of flat assembler.
Index
> Windows > alternative lessons of Iczelion |
Author |
|
Mikl___ 09 Feb 2015, 06:35
The third lesson
Code: format PE GUI include 'win32ax.inc' ; import data in the same section xor ebx,ebx mov edi,wTitle mov esi,400000h ; +------------------------------+ ; | registering the window class | ; +------------------------------+ invoke RegisterClass,esp,ebx,window_procedure,ebx,\ ebx,esi,ebx,10011h,COLOR_WINDOW+1,ebx,edi ; +--------------------------+ ; | creating the main window | ; +--------------------------+ push ebx esi ebx ebx shl esi,9;400000h * 200h = 80000000h = CW_USEDEFAULT invoke CreateWindowEx,ebx,edi,edi,WS_OVERLAPPEDWINDOW+WS_VISIBLE,\ esi,esi,esi,esi mov ebp,esp ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ message_loop: invoke GetMessage,ebp,ebx,ebx,ebx invoke DispatchMessage,ebp jmp message_loop ; +----------------------+ ; | the window procedure | ; +----------------------+ window_procedure: cmp dword[esp+8],WM_DESTROY je wmDESTROY jmp dword [DefWindowProc] wmDESTROY: invoke ExitProcess,ebx wTitle db 'Iczelion Tutorial #3:The Simplest Window in FASM',0 ;name and class of our window data import library KERNEL32, 'KERNEL32.DLL',\ user32, 'USER32.DLL' import KERNEL32,\ ExitProcess, 'ExitProcess' import user32,\ RegisterClass, 'RegisterClassA',\ CreateWindowEx, 'CreateWindowExA',\ DefWindowProc, 'DefWindowProcA',\ GetMessage, 'GetMessageA',\ DispatchMessage, 'DispatchMessageA' end data |
|||
09 Feb 2015, 06:35 |
|
Mikl___ 09 Feb 2015, 06:38
The fourth lesson
Code: format PE GUI include 'win32ax.inc' ; import data in the same section xor ebx,ebx mov edi,wTitle mov esi,400000h ; +------------------------------+ ; | registering the window class | ; +------------------------------+ invoke RegisterClass,esp,CS_HREDRAW or CS_VREDRAW,WndProc,ebx,\ ebx,esi,ebx,10011h,COLOR_WINDOW+1,ebx,edi ; +--------------------------+ ; | creating the main window | ; +--------------------------+ push ebx esi ebx ebx shl esi,9 invoke CreateWindowEx,ebx,edi,edi,WS_OVERLAPPEDWINDOW+WS_VISIBLE,\ esi,esi,esi,esi mov ebp,esp ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ message_loop: invoke GetMessage,ebp,ebx,ebx,ebx invoke DispatchMessage,ebp jmp message_loop ; +----------------------+ ; | the window procedure | ; +----------------------+ proc WndProc hWnd, uMsg, wParam, lParam local ps:PAINTSTRUCT local expRect:RECT mov eax,[uMsg] mov edi,[hWnd] dec eax; cmp uMsg,WM_DESTROY dec eax je wmDESTROY sub eax,WM_PAINT-WM_DESTROY; cmp uMsg,WM_PAINT je wmPAINT leave jmp dword [DefWindowProc] wmPAINT: invoke BeginPaint,edi,esp lea esi,[expRect] invoke GetClientRect,edi,esi,eax invoke DrawText,dword[esp+16],expTxt,-1,esi,DT_SINGLELINE or DT_CENTER or DT_VCENTER invoke EndPaint,edi,esp ret wmDESTROY: invoke ExitProcess,eax endp wTitle db 'Iczelion Tutorial #4:Painting with Text',0 ;name of our window expTxt db 'Win32 assembly with FASM is great and easy',0 data import library KERNEL32, 'KERNEL32.DLL',\ user32, 'USER32.DLL' import KERNEL32,\ ExitProcess, 'ExitProcess' import user32,\ RegisterClass, 'RegisterClassA',\ CreateWindowEx, 'CreateWindowExA',\ DefWindowProc, 'DefWindowProcA',\ GetMessage, 'GetMessageA',\ BeginPaint, 'BeginPaint',\ GetClientRect, 'GetClientRect',\ DrawText, 'DrawTextA',\ EndPaint, 'EndPaint',\ DispatchMessage, 'DispatchMessageA' end data |
|||
09 Feb 2015, 06:38 |
|
Mikl___ 09 Feb 2015, 06:48
The fourth lesson (application "A")
Code: format PE GUI include 'win32ax.inc' ; import data in the same section xor ebx,ebx mov edi,wTitle mov esi,400000h ; +------------------------------+ ; | registering the window class | ; +------------------------------+ invoke CreateSolidBrush,0FF0000h,ebx,edi;blue brush invoke RegisterClass,esp,CS_HREDRAW or CS_VREDRAW,WndProc,ebx,\ ebx,esi,ebx,10011h,eax ; +--------------------------+ ; | creating the main window | ; +--------------------------+ push ebx esi ebx ebx shl esi,9 invoke CreateWindowEx,ebx,edi,edi,WS_OVERLAPPEDWINDOW+WS_VISIBLE,\ esi,esi,esi,esi invoke SetTimer,eax,ebx,50,ebx;create timer #0 for 50mSec mov ebp,esp ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ message_loop: invoke GetMessage,ebp,ebx,ebx,ebx invoke DispatchMessage,ebp jmp message_loop ; +----------------------+ ; | the window procedure | ; +----------------------+ proc WndProc hWnd, uMsg, wParam, lParam local ps:PAINTSTRUCT local expRect:RECT local expSize:SIZE local newfont:DWORD local oldfont:DWORD mov eax,[uMsg] mov edi,[hWnd] dec eax; cmp uMsg,WM_DESTROY dec eax je wmDESTROY sub eax,WM_PAINT-WM_DESTROY; cmp uMsg,WM_PAINT je wmPAINT sub eax,WM_TIMER-WM_PAINT; cmp uMsg,WM_PAINT je wmTIMER leave jmp dword [DefWindowProc] wmTIMER: invoke InvalidateRect,edi,ebx,1 add [angle],16 jmp wmBYE wmPAINT: invoke BeginPaint,edi,esp mov ecx,[angle] invoke CreateFont,26,12,ecx,ecx,400,ebx,ebx,ebx,\ -1,\;OEM_CHARSET ebx,\;OUT_DEFAULT_PRECIS ebx,\;CLIP_DEFAULT_PRECIS ebx,\;DEFAULT_QUALITY DEFAULT_PITCH or FF_SCRIPT,\ font,eax ;default font object mov [newfont],eax invoke SelectObject,dword[esp+4],eax mov [oldfont],eax lea esi,[expRect] invoke GetClientRect,edi,esi invoke SetTextColor,dword[esp+4],0x32C8C8;RGB=50,200,200 invoke SetBkColor,dword[esp+4],0xFF0000;RGB=0,0,255 lea eax,[expSize] invoke GetTextExtentPoint32,dword[esp+12],expTxt,len,eax push len;Num-expTxt push expTxt finit push 0.0017453292519943295769236907684886;=pi/1800 push eax fld dword[esp+4] mov eax,[angle] add eax,1800 mov [esp+4],eax fimul dword[esp+4] fsincos mov eax,[expSize+SIZE.cy] mul eax mov [esp+4],eax mov eax,[expSize+SIZE.cx] mul eax add [esp+4],eax shr dword[esp+4],2 fild dword[esp+4] fsqrt fistp dword[esp+4] fimul dword[esp+4] fistp dword[esp] fimul dword[esp+4] fchs fistp dword[esp+4];-y mov eax,[esi+RECT.bottom] shr eax,1 add [esp+4],eax mov ecx,[esi+RECT.right] shr ecx,1 add [esp],ecx invoke TextOut,dword[esp+16] ;--------------------------------------------------------------------- invoke DeleteObject,[newfont] invoke SelectObject,dword[esp+4],[oldfont] invoke EndPaint,edi,esp ;------------------------------------------------------------------ wmBYE: ret ;------------------------------------------------------------------- wmDESTROY: invoke KillTimer,ebx invoke ExitProcess,eax endp ;--------------------------------------------------------------------- wTitle db 'Iczelion Tutorial #4-1:Painting with Rotation Text',0 ;name of our window expTxt db 'Win32 assembly with FASM is great and easy' len = $ - expTxt font db "script",0 angle dd 0 buffer rb 30 ;-------------------------------------------------------- data import library KERNEL32, 'KERNEL32.DLL',\ user32, 'USER32.DLL',\ gdi32, 'gdi32.dll' import KERNEL32,\ ExitProcess, 'ExitProcess' import user32,\ RegisterClass, 'RegisterClassA',\ CreateWindowEx, 'CreateWindowExA',\ DefWindowProc, 'DefWindowProcA',\ GetMessage, 'GetMessageA',\ BeginPaint, 'BeginPaint',\ GetClientRect, 'GetClientRect',\ EndPaint, 'EndPaint',\ SetTimer, 'SetTimer',\ KillTimer, 'KillTimer',\ InvalidateRect, 'InvalidateRect',\ DispatchMessage, 'DispatchMessageA' import gdi32,\ TextOut, 'TextOutA',\ CreateFont, 'CreateFontA',\ SetTextColor, 'SetTextColor',\ SetBkColor, 'SetBkColor',\ GetTextExtentPoint32,'GetTextExtentPoint32A',\ SelectObject, 'SelectObject',\ DeleteObject, 'DeleteObject',\ CreateSolidBrush, 'CreateSolidBrush' end data
Last edited by Mikl___ on 10 Feb 2015, 06:57; edited 1 time in total |
||||||||||
09 Feb 2015, 06:48 |
|
typedef 10 Feb 2015, 03:42
I don't think you should call these alternatives. Perhaps supplements.
|
|||
10 Feb 2015, 03:42 |
|
Mikl___ 10 Feb 2015, 05:35
Hi, typedef !
Well, let it be supplements, I don't mind... |
|||
10 Feb 2015, 05:35 |
|
Mikl___ 10 Feb 2015, 08:55
Lesson# 4B
Code: format PE GUI include 'win32ax.inc' ; import data in the same section ZZZ_STATIC equ 1 ZZZ_DRAWTEXTEX equ 2 ZZZ_TEXTOUT equ 3 ZZZ_TABBEDTEXTOUT equ 4 ZZZ_DRAWTEXT equ 5 ZZZ_POLYTEXTOUT equ 6 ZZZ_EXTTEXTOUT equ 7 ZZZ_SETTEXT equ 8 ZZZ_EXIT equ 9 IDM_MENU equ 101 IDM_MAINMENU equ 101 struct POLYTEXTA x rd 1 y rd 1 n rd 1 lpStr rd 1 uiFlags rd 1 icl RECT pdx rd 1 ends xor ebx,ebx mov edi,wTitle mov esi,400000h ; +------------------------------+ ; | registering the window class | ; +------------------------------+ invoke RegisterClass,esp,ebx,WndProc,ebx,\ ebx,esi,ebx,10011h,COLOR_BTNFACE+1,IDM_MENU,edi ; +--------------------------+ ; | creating the main window | ; +--------------------------+ push ebx esi ebx ebx shl esi,9 invoke CreateWindowEx,ebx,edi,edi,WS_OVERLAPPEDWINDOW+WS_VISIBLE+WS_VSCROLL ,\ esi,esi,esi,esi invoke CreateWindowEx,ebx,static,expTxt0,WS_CHILD + SS_LEFT,\ 120,180,512,256,eax,ebx,400000h,ebx mov [hStaticText],eax mov ebp,esp ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ message_loop: invoke GetMessage,ebp,ebx,ebx,ebx invoke DispatchMessage,ebp jmp message_loop ; +----------------------+ ; | the window procedure | ; +----------------------+ proc WndProc hWnd, uMsg, wParam, lParam local ps:PAINTSTRUCT local expRect:RECT local expSize:SIZE mov eax,[uMsg] mov edi,[hWnd] dec eax; cmp uMsg,WM_DESTROY dec eax je .wmDESTROY sub eax,WM_PAINT-WM_DESTROY; cmp uMsg,WM_PAINT je .wmPAINT sub eax,WM_COMMAND-WM_PAINT; cmp uMsg,WM_COMMAND=111h je .wmCOMMAND sub eax,WM_CTLCOLORSTATIC-WM_COMMAND;WM_CTLCOLORSTATIC=138h je .wmCTLCOLORSTATIC .wmDEFAULT: leave jmp dword [DefWindowProc] .wmCTLCOLORSTATIC: invoke SetBkColor,dword[wParam],0DEEBEFh invoke GetStockObject,NULL_BRUSH jmp .wmBYE .wmPAINT: lea esi,[expRect] invoke GetClientRect,edi,esi add [esi+RECT.bottom],400 invoke BeginPaint,edi,esp invoke FillRect,eax,esi,COLOR_BTNFACE+1 invoke SetBkMode,dword[esp+4],TRANSPARENT mov eax,[Page] jmp [handle+eax*4] .STATICText:invoke ShowWindow,[hStaticText],SW_SHOW jmp .1 .TextOut1: invoke TextOut,dword[esp+4*4],40,100,expTxt3A,expTxt3B-expTxt3A-1 invoke TextOut,dword[esp+4*4],40,120,expTxt3B,expTxt3C-expTxt3B-1 invoke TextOut,dword[esp+4*4],40,140,expTxt3C,expTxt3D-expTxt3C-1 invoke TextOut,dword[esp+4*4],40,160,expTxt3D,expTxt3E-expTxt3D-1 invoke TextOut,dword[esp+4*4],40,180,expTxt3E,expTxt4 -expTxt3E-1 jmp .1 .TabbedTextOut1: invoke TabbedTextOut,dword[esp+28],40,40,expTxt4,-1,ebx,ebx,ebx jmp .1 .DrawText1: invoke DrawText,dword[esp+16],expTxt1,-1,esi,DT_WORDBREAK jmp .1 .ExtTextOut1:invoke ExtTextOut,dword[esp+28],40,40,ebx,esi,expTxt2,expTxt3A-expTxt2-1,ebx jmp .1 .PolyTextOut1:lea eax,[expSize] invoke GetTextExtentPoint32,dword[esp+12],expTxt8,pptxt-expTxt8-1,eax mov eax,[esi+RECT.bottom] lea eax,[eax+eax*4] shr eax,4 lea ecx,[pptxt] mov [ecx+POLYTEXTA.x],eax mov eax,[esi+RECT.right] sub eax,[expSize+SIZE.cx] shr eax,1 mov [ecx+POLYTEXTA.y],eax mov dword[ecx+POLYTEXTA.n],pptxt-expTxt8-1 mov dword[ecx+POLYTEXTA.lpStr],expTxt8 mov dword[ecx+POLYTEXTA.uiFlags],ETO_OPAQUE mov [ecx+POLYTEXTA.icl],esi invoke PolyTextOut,dword[esp+8],ecx,1 jmp .1 .SetText1: invoke SendMessage,dword[hWnd],WM_SETTEXT,ebx,expTxt7 .NullText: jmp .1 .wmCOMMAND: mov eax,[wParam] cmp eax,ZZZ_EXIT;03 je .wmDESTROY;menu_exit mov [Page],eax invoke SendMessage,dword[hWnd],WM_SETTEXT,ebx,wTitle invoke ShowWindow,[hStaticText],SW_HIDE invoke InvalidateRect,edi,ebx,ebx jmp .wmBYE .DrawTextEx1:invoke DrawTextEx,dword[esp+20],expTxt5,-1,esi,DT_LEFT+DT_WORDBREAK+DT_EXPANDTABS+\ DT_END_ELLIPSIS+DT_MODIFYSTRING+DT_WORD_ELLIPSIS,ebx .1: invoke EndPaint,edi,esp .wmBYE: ret .wmDESTROY: invoke ExitProcess,ebx handle dd WndProc.NullText,WndProc.STATICText,WndProc.DrawTextEx1,WndProc.TextOut1 dd WndProc.TabbedTextOut1,WndProc.DrawText1,WndProc.PolyTextOut1,WndProc.ExtTextOut1 dd WndProc.SetText1 endp ;----------------------------------------------------------------------- ;exp = experiment hStaticText rd 1 static db "STATIC",0 wTitle db 'Iczelion Tutorial #5-2:few ways of Text output in FASM',0 ;name of our window Page dd 0 ;--------------------------------------------------------------------------------------------- expTxt0 db '1) Text output using STATIC ', 10,' Understands newlines and tabs line ', 10 Â Â Â Â Â Â db 'does not require processing WM_PAINT messages',0 ;--------------------------------------------------------------------------------------------- expTxt1 db '5) To display multiple lines of text within the boundaries of a given rectangular area using DrawText API ', 10,' description ', 10 db 'function DrawText (DC: HDC; Str: PChar; Count: Integer; var Rect: TRect; Format: Word): Integer;', 10 db 'Draws fopmatipovanny text. Type fopmatipovaniya indicated PARAMETERS Format. If not explicitly dt_NoClip, ', 10 db 'text vypezaetsya in ogpanichivayuschy ppyamougolnik.', 10, 'PARAMETERS:', 10 db 'DC: symbols are device context.', 10, 'Str: you draw with string. If Count = -1, it must end with a null character. ', 10 db 'Rect: TRect, ogpanichivayuschy text.', 10, 'Format: One or more constants: dt_Bottom, dt_CalcRect, dt_Center, dt_ExpandTabs,', 10 db 'dt_ExternalLeading, dt_Left, dt_NoClip, dt_NoPrefix, dt_Right, dt_SingleLine, dt_TabStop, dt_Top, dt_VCenter and', 10 db 'dt_WordBreak. See. Section "Flags fopmatipovaniya text DURING pisovanii, dt_" in Chapter 1. ', 10 db 'Return value: The height of the text.', 10, 'function is in a file user32.dll',0 ;--------------------------------------------------------------------------------------------- expTxt2 db '7) ExtTextOut function allows you to output text string ' db 'in the specified rectangle using the current font and manages Background mode',0 ;--------------------------------------------------------------------------------------------- expTxt3A db '3) Text output using TextOut. Function displays the text ',0 expTxt3B db 'in the given coordinates, which are always given with respect',0 expTxt3C db 'to the (upper left corner) of the window. Does not understand hyphens and',0 expTxt3D db 'tabs line. When redrawing the workspace required to provide processing',0 expTxt3E db 'WM_PAINT. To display these lines TextOut function calls five times!',0 ;--------------------------------------------------------------------------------------------- expTxt4 db '4) To create a multi-column table with aligned columns of text, use ',9,' TabbedTextOut API',0 ;--------------------------------------------------------------------------------------------- expTxt5 db '2) The DrawText function draws formatted text in the specified rectangle. It formats the text according to the specified method (expanding tabs, justifying characters, breaking lines, and so forth). ' db ' To specify additional formatting options, use the DrawTextEx function.',0 expTxt7 db 'Text output in the window title through SendMessage',0 expTxt8 db 'Text output using PolyTextOut API',0 pptxt POLYTEXTA ;0,40,Numb,expTxt7,ETO_OPAQUE,ebx,ebx,10,10,ebx data import library KERNEL32, 'KERNEL32.DLL',\ gdi32, 'gdi32.dll',\ user32, 'USER32.DLL' import KERNEL32,\ ExitProcess, 'ExitProcess' import gdi32,\ TextOut, 'TextOutA',\ ExtTextOut, 'ExtTextOutA',\ SetTextColor, 'SetTextColor',\ SetBkColor, 'SetBkColor',\ GetStockObject, 'GetStockObject',\ SetTextAlign, 'SetTextAlign',\ GetTextExtentPoint32,'GetTextExtentPoint32A',\ PolyTextOut, 'PolyTextOutA',\ SetBkMode, 'SetBkMode' import user32,\ RegisterClass, 'RegisterClassA',\ GetClientRect, 'GetClientRect',\ CreateWindowEx, 'CreateWindowExA',\ DefWindowProc, 'DefWindowProcA',\ GetMessage, 'GetMessageA',\ DispatchMessage, 'DispatchMessageA',\ DestroyWindow, 'DestroyWindow',\ BeginPaint, 'BeginPaint',\ EndPaint, 'EndPaint',\ FillRect, 'FillRect',\ GetDC, 'GetDC',\ DrawTextEx, 'DrawTextExA',\ DrawText, 'DrawTextA',\ ReleaseDC, 'ReleaseDC',\ ShowWindow, 'ShowWindow',\ InvalidateRect, 'InvalidateRect',\ TabbedTextOut, 'TabbedTextOutA',\ SendMessage, 'SendMessageA' end data align 4 data resource directory RT_MENU,appMenu resource appMenu,\ IDM_MENU,LANG_ENGLISH,IDR_MAINMENU menu IDR_MAINMENU menuitem 'Text Output',0,MFR_POPUP menuitem 'Static',ZZZ_STATIC,MFT_STRING menuitem 'DrawTextEx',ZZZ_DRAWTEXTEX,MFT_STRING menuitem 'TextOut',ZZZ_TEXTOUT,MFT_STRING menuitem 'TabbedTextOut',ZZZ_TABBEDTEXTOUT,MFT_STRING menuitem 'DrawText',ZZZ_DRAWTEXT,MFT_STRING menuitem 'PolyTextOut',ZZZ_POLYTEXTOUT,MFT_STRING menuitem 'ExtTextOut',ZZZ_EXTTEXTOUT,MFT_STRING menuitem 'Settext',ZZZ_SETTEXT,MFT_STRING menuseparator menuitem '&Exit',ZZZ_EXIT,MFR_END menuitem '&Exit',ZZZ_EXIT,MFR_END end data
Last edited by Mikl___ on 13 Feb 2015, 08:10; edited 2 times in total |
||||||||||||||||||||
10 Feb 2015, 08:55 |
|
Mikl___ 10 Feb 2015, 08:58
Lesson# 5
Code: format PE GUI include 'win32ax.inc' ; import data in the same section xor ebx,ebx mov edi,wTitle mov esi,400000h ; +------------------------------+ ; | registering the window class | ; +------------------------------+ invoke RegisterClass,esp,ebx,WndProc,\ ebx,ebx,esi,ebx,10011h,COLOR_WINDOW+1,ebx,edi ; +--------------------------+ ; | creating the main window | ; +--------------------------+ push ebx esi ebx ebx shl esi,9 invoke CreateWindowEx,ebx,edi,edi,WS_OVERLAPPEDWINDOW+WS_VISIBLE,\ esi,esi,esi,esi mov ebp,esp ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ message_loop: invoke GetMessage,ebp,ebx,ebx,ebx invoke DispatchMessage,ebp jmp message_loop ; +----------------------+ ; | the window procedure | ; +----------------------+ proc WndProc hWnd, uMsg, wParam, lParam local ps:PAINTSTRUCT mov eax,[uMsg] mov edi,[hWnd] dec eax; cmp uMsg,WM_DESTROY dec eax je .wmDESTROY sub eax,WM_PAINT-WM_DESTROY; cmp uMsg,WM_PAINT je .wmPAINT leave jmp dword [DefWindowProc] .wmPAINT:invoke BeginPaint,edi,esp invoke GetCurrentObject,eax,ebx;OBJ_FONT invoke CreateFont,26,12,ebx,ebx,400,ebx,ebx,ebx,\ -1,\;OEM_CHARSET,\ ebx,\;OUT_DEFAULT_PRECIS,\ ebx,\;CLIP_DEFAULT_PRECIS,\ ebx,\;DEFAULT_QUALITY,\ DEFAULT_PITCH or FF_SCRIPT,\ fontname,eax ;default font object invoke SelectObject,dword[esp+8],eax invoke SetTextColor,dword[esp+8],0x32C8C8;RGB=50,200,200 invoke SetBkColor,dword[esp+8],0xFF0000;RGB=0,0,255 invoke TextOut,dword[esp+20],ebx,ebx,expTxt,Num invoke SelectObject,dword[esp];esi invoke EndPaint,edi,esp ret .wmDESTROY: invoke ExitProcess,ebx endp ;------------------------------------------------------------------------------- ;exp = experiment fontname db "script",0 wTitle db 'Iczelion Tutorial #5:More about Text',0 ;name of our window expTxt db 'Win32 assembly with FASM is great and easy' Num = $ - expTxt data import library KERNEL32, 'KERNEL32.DLL',\ GDI32, 'GDI32.DLL',\ user32, 'USER32.DLL' import KERNEL32,\ ExitProcess, 'ExitProcess' import user32,\ RegisterClass, 'RegisterClassA',\ CreateWindowEx, 'CreateWindowExA',\ DefWindowProc, 'DefWindowProcA',\ GetMessage, 'GetMessageA',\ BeginPaint, 'BeginPaint',\ EndPaint, 'EndPaint',\ DispatchMessage, 'DispatchMessageA' import GDI32,\ CreateFont, 'CreateFontA',\ SetTextColor, 'SetTextColor',\ SetBkColor, 'SetBkColor',\ TextOut, 'TextOutA',\ GetCurrentObject, 'GetCurrentObject',\ SelectObject, 'SelectObject' end data
Last edited by Mikl___ on 13 Feb 2015, 08:14; edited 3 times in total |
||||||||||
10 Feb 2015, 08:58 |
|
Mikl___ 10 Feb 2015, 09:02
Lesson# 6
Code: format PE GUI include 'win32ax.inc' ; import data in the same section xor ebx,ebx mov edi,wTitle mov esi,400000h ; +------------------------------+ ; | registering the window class | ; +------------------------------+ invoke RegisterClass,esp,ebx,WndProc,ebx,\ ebx,esi,ebx,10011h,COLOR_WINDOW+1,ebx,edi ; +--------------------------+ ; | creating the main window | ; +--------------------------+ push ebx esi ebx ebx shl esi,9 invoke CreateWindowEx,ebx,edi,edi,WS_OVERLAPPEDWINDOW+\ WS_VISIBLE,esi,esi,512,352 mov ebp,esp ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ message_loop: invoke GetMessage,ebp,ebx,ebx,ebx invoke TranslateMessage,ebp invoke DispatchMessage,ebp jmp message_loop ; +----------------------+ ; | the window procedure | ; +----------------------+ proc WndProc hWnd, uMsg, wParam, lParam local ps:PAINTSTRUCT mov eax,[uMsg] mov edi,[hWnd] mov esi,expChar sub eax,WM_DESTROY je .wmDESTROY sub eax,WM_PAINT-WM_DESTROY; cmp uMsg,WM_PAINT je .wmPAINT sub eax,WM_CHAR-WM_PAINT je .wmCHAR leave jmp dword [DefWindowProc] .wmCHAR: push dword [wParam] pop dword [esi] invoke InvalidateRect,edi,eax,TRUE jmp .wmBYE .wmPAINT: invoke BeginPaint,edi,esp invoke TextOut,eax,182,100,Message,expChar-Message-1 invoke TextOut,dword[esp+16],242,150,esi,1 invoke EndPaint,edi,esp .wmBYE: ret .wmDESTROY: invoke ExitProcess,eax endp ;exp = experiment wTitle db 'Iczelion Tutorial #6:Keyboard Input in FASM',0 ;name of our window Message db 'Press any key',0 expChar dd '?' data import library KERNEL32, 'KERNEL32.DLL',\ user32, 'USER32.DLL',\ GDI32, 'GDI32.DLL' import KERNEL32,\ ExitProcess, 'ExitProcess' import user32,\ RegisterClass, 'RegisterClassA',\ CreateWindowEx, 'CreateWindowExA',\ DefWindowProc, 'DefWindowProcA',\ GetMessage, 'GetMessageA',\ BeginPaint, 'BeginPaint',\ EndPaint, 'EndPaint',\ DispatchMessage, 'DispatchMessageA',\ TranslateMessage, 'TranslateMessage',\ InvalidateRect, 'InvalidateRect' import GDI32,\ TextOut, 'TextOutA' end data
Last edited by Mikl___ on 13 Feb 2015, 08:13; edited 1 time in total |
||||||||||
10 Feb 2015, 09:02 |
|
Mikl___ 12 Feb 2015, 02:43
Lesson# 7
Code: format PE GUI include 'win32ax.inc' ; import data in the same section MAXRECTS = 40 xor ebx,ebx mov edi,wTitle mov esi,400000h ; +------------------------------+ ; | registering the window class | ; +------------------------------+ invoke RegisterClass,esp,ebx,WndProc,ebx,\ ebx,esi,ebx,10011h,COLOR_WINDOW+1,ebx,edi ; +--------------------------+ ; | creating the main window | ; +--------------------------+ push ebx esi ebx ebx shl esi,9 invoke CreateWindowEx,ebx,edi,edi,WS_OVERLAPPEDWINDOW+\ WS_VISIBLE,esi,esi,esi,esi mov ebp,esp ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ message_loop: invoke GetMessage,ebp,ebx,ebx,ebx invoke DispatchMessage,ebp jmp message_loop ; +----------------------+ ; | the window procedure | ; +----------------------+ proc WndProc hWnd, uMsg, wParam, lParam local ps:PAINTSTRUCT local Rect:RECT mov eax,[uMsg] mov edi,[hWnd] dec eax; cmp uMsg,WM_DESTROY dec eax je .wmDESTROY sub eax,WM_PAINT-WM_DESTROY; cmp uMsg,WM_PAINT je .wmPAINT sub eax,WM_LBUTTONDOWN-WM_PAINT;cmp eax,WM_LBUTTONDOWN je .wmLBUTTONDOWN sub eax,WM_RBUTTONDOWN-WM_LBUTTONDOWN je .wmRBUTTONDOWN leave jmp dword [DefWindowProc] .wmPAINT: mov ebx,[nextRect] inc ebx;cmp nextRect,-1 jz .1 invoke BeginPaint,edi,esp invoke SetBkMode,eax,TRANSPARENT .3: mov edx,8 mov eax,[ebx*4+recs-4] mov ecx,eax shl ecx,1 jnc @f shl edx,1 @@: shr ecx,17 push [PS+edx] [PS+edx+4] ecx push word 0 push ax invoke TextOut,dword[esp+16] dec ebx jnz .3 invoke EndPaint,edi,esp jmp .1 .wmLBUTTONDOWN: mov eax,80000000h .wmRBUTTONDOWN: add eax,[lParam] cmp [nextRect],MAXRECTS-1 jge short @f inc [nextRect] mov ecx,[nextRect] mov [ecx*4+recs],eax movzx edx,ax shl eax,1 shr eax,17 lea esi,[Rect] mov [esi+RECT.left],edx mov [esi+RECT.top],eax add edx,150 mov [esi+RECT.right],edx add eax,20 mov [esi+RECT.bottom],eax invoke InvalidateRect,edi,esi,ebx jmp .1 @@: invoke MessageBeep,ebx .1: ret .wmDESTROY: invoke ExitProcess,ebx endp ;----------------------------------------------------------- ;exp = experiment wTitle db 'Iczelion Tutorial #7:Mouse Input',0 ;name of our window text1 db 'Right Mouse Click' text2 db 'Left Mouse Click ' PS dd 0,0,text2-text1, text1, PS-text2, text2 recs dd MAXRECTS dup (?) nextRect dd -1 ;--------------------------------------------------------- data import library KERNEL32, 'KERNEL32.DLL',\ user32, 'USER32.DLL',\ GDI32, 'GDI32.DLL' import KERNEL32,\ ExitProcess, 'ExitProcess' import user32,\ RegisterClass, 'RegisterClassA',\ CreateWindowEx, 'CreateWindowExA',\ DefWindowProc, 'DefWindowProcA',\ GetMessage, 'GetMessageA',\ BeginPaint, 'BeginPaint',\ EndPaint, 'EndPaint',\ DispatchMessage, 'DispatchMessageA',\ InvalidateRect, 'InvalidateRect',\ MessageBeep, 'MessageBeep' import GDI32,\ TextOut, 'TextOutA',\ SetBkMode, 'SetBkMode' end data Code: format PE GUI include 'win32ax.inc' ; import data in the same section xor ebx,ebx mov edi,wTitle mov esi,400000h invoke LoadCursorFromFile,"Images\cursor.cur",COLOR_WINDOW+1,ebx,edi ; +------------------------------+ ; | registering the window class | ; +------------------------------+ invoke RegisterClass,esp,ebx,window_procedure,\ ebx,ebx,esi,eax,eax ; +--------------------------+ ; | creating the main window | ; +--------------------------+ push ebx push esi shl esi,9 invoke CreateWindowEx,ebx,edi,edi,WS_OVERLAPPEDWINDOW+WS_VISIBLE,\ esi,esi,esi,esi,ebx,ebx mov ebp,esp ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ message_loop: invoke GetMessage,ebp,ebx,ebx,ebx invoke DispatchMessage,ebp jmp message_loop ; +----------------------+ ; | the window procedure | ; +----------------------+ window_procedure: cmp dword[esp+0x08],WM_DESTROY je wmDESTROY jmp dword [DefWindowProc] wmDESTROY: invoke ExitProcess,ebx ;--------------------------------------------------------------------------------- wTitle db 'Iczelion Tutorial #7-1:Creating a cursor and icons from file in FASM',0 ;name of our window ;-------------------------------------------------------------------------------- data import library KERNEL32, 'KERNEL32.DLL',\ user32, 'USER32.DLL' import KERNEL32,\ ExitProcess, 'ExitProcess' import user32,\ RegisterClass, 'RegisterClassA',\ CreateWindowEx, 'CreateWindowExA',\ DefWindowProc, 'DefWindowProcA',\ GetMessage, 'GetMessageA',\ DispatchMessage, 'DispatchMessageA',\ LoadCursorFromFile, 'LoadCursorFromFileA' end data #7-2: Creating a cursor and icons from resources Code: format PE GUI include 'win32ax.inc' ID_CURSOR = 18 ; import data in the same section xor ebx,ebx mov edi,wTitle mov esi,400000h invoke LoadCursor,esi, ID_CURSOR,COLOR_WINDOW+1,ebx,edi ; +------------------------------+ ; | registering the window class | ; +------------------------------+ invoke RegisterClass,esp,ebx,window_procedure,\ ebx,ebx,esi,eax,eax ; +--------------------------+ ; | creating the main window | ; +--------------------------+ push ebx esi ebx ebx shl esi,9 invoke CreateWindowEx,ebx,edi,edi,WS_OVERLAPPEDWINDOW+\ WS_VISIBLE,esi,esi,esi,esi mov ebp,esp ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ message_loop: invoke GetMessage,ebp,ebx,ebx,ebx invoke DispatchMessage,ebp jmp message_loop ; +----------------------+ ; | the window procedure | ; +----------------------+ window_procedure: cmp dword[esp+0x08],WM_DESTROY je wmDESTROY jmp dword [DefWindowProc] wmDESTROY: invoke ExitProcess,ebx ;------------------------------------------------------ wTitle db 'Iczelion Tutorial #7-2: Creating a cursor and icons from resources in FASM',0 ;name of our window ;--------------------------------------------------------- data import library KERNEL32, 'KERNEL32.DLL',\ user32, 'USER32.DLL' import KERNEL32,\ ExitProcess, 'ExitProcess' import user32,\ RegisterClass, 'RegisterClassA',\ CreateWindowEx, 'CreateWindowExA',\ DefWindowProc, 'DefWindowProcA',\ GetMessage, 'GetMessageA',\ DispatchMessage, 'DispatchMessageA',\ LoadCursor, 'LoadCursorA' end data ;-------------------------------------------------------------------------------- section '.rsrc' resource data readable directory RT_CURSOR,cursors,\ RT_GROUP_CURSOR,group_cursors resource cursors,\ 2,LANG_NEUTRAL,cursor1_data resource group_cursors,\ ID_CURSOR,LANG_NEUTRAL,cursor1 cursor cursor1,cursor1_data,'Images\cursor.cur' Icon binary datas Code: format PE GUI include 'win32ax.inc' ICON_SIZE = 744 ;taille de Icon.ico (header=22 Image=744) total=766 ; import data in the same section xor ebx,ebx mov edi,wTitle mov esi,400000h invoke LoadCursorFromFile,CursorFile,COLOR_WINDOW+1,ebx,edi ; +------------------------------+ ; | registering the window class | ; +------------------------------+ invoke RegisterClass,esp,ebx,WndProc,\ ebx,ebx,esi,eax,eax ; +--------------------------+ ; | creating the main window | ; +--------------------------+ push ebx esi ebx ebx shl esi,9 invoke CreateWindowEx,ebx,edi,edi,WS_OVERLAPPEDWINDOW+WS_VISIBLE,\ esi,esi,esi,esi invoke CreateIconFromResource,ptIcon,ICON_SIZE,-1,030000h mov [hIcon],eax mov ebp,esp ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ message_loop: invoke GetMessage,ebp,ebx,ebx,ebx invoke DispatchMessage,ebp jmp message_loop ; +----------------------+ ; | the window procedure | ; +----------------------+ proc WndProc hWnd, uMsg, wParam, lParam local ps:PAINTSTRUCT mov eax,[uMsg] mov edi,[hWnd] dec eax dec eax;cmp d[esp+0x08],WM_DESTROY jz .wmDESTROY sub eax,WM_PAINT-WM_DESTROY jz .wmPAINT leave jmp dword [DefWindowProc] .wmPAINT:invoke BeginPaint,edi,esp invoke DrawIcon,eax,134,68,[hIcon] invoke EndPaint,edi,esp ret .wmDESTROY: invoke ExitProcess,eax endp ;------------------------------------------ wTitle db 'Iczelion Tutorial #7-3:Icon binary datas in FASM',0 ;name of our window hIcon rd 1 ptIcon FILE 'Images\Cursor.cur':22 ;skip the header of the file icon CursorFile db 'Images\cursor.cur',0 ;--------------------------------------------- data import library KERNEL32, 'KERNEL32.DLL',\ user32, 'USER32.DLL' import KERNEL32,\ ExitProcess, 'ExitProcess' import user32,\ RegisterClass, 'RegisterClassA',\ CreateWindowEx, 'CreateWindowExA',\ DefWindowProc, 'DefWindowProcA',\ GetMessage, 'GetMessageA',\ DispatchMessage, 'DispatchMessageA',\ LoadCursorFromFile, 'LoadCursorFromFileA',\ BeginPaint, 'BeginPaint',\ EndPaint, 'EndPaint',\ DrawIcon, 'DrawIcon',\ CreateIconFromResource, 'CreateIconFromResource' end data
|
||||||||||||||||||||
12 Feb 2015, 02:43 |
|
Mikl___ 12 Feb 2015, 06:02
Menu in FASM
Create a menu via a resource file ASM file Code: format PE GUI include 'win32ax.inc' ; import data in the same section ZZZ_TEST equ 0 ZZZ_OPEN equ 1 ZZZ_SAVE equ 2 ZZZ_EXIT equ 3 xor ebx,ebx mov edi,wTitle mov esi,400000h ; +------------------------------+ ; | registering the window class | ; +------------------------------+ invoke RegisterClass,esp,ebx,WndProc,ebx,\ ebx,esi,ebx,10011h,COLOR_WINDOW+1,menu_name,edi ; +--------------------------+ ; | creating the main window | ; +--------------------------+ push ebx esi ebx ebx shl esi,9 invoke CreateWindowEx,ebx,edi,edi,WS_OVERLAPPEDWINDOW+\ WS_VISIBLE,esi,esi,esi,esi mov ebp,esp ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ message_loop: invoke GetMessage,ebp,ebx,ebx,ebx invoke DispatchMessage,ebp jmp message_loop ; +----------------------+ ; | the window procedure | ; +----------------------+ proc WndProc,hWnd,uMsg,wParam,lParam mov eax,[uMsg] dec eax; cmp uMsg,WM_DESTROY dec eax je wmDESTROY sub eax,WM_COMMAND-WM_DESTROY; cmp uMsg,WM_PAINT je wmCOMMAND leave jmp dword [DefWindowProc] wmCOMMAND: mov ebx,[wParam] cmp ebx,ZZZ_EXIT je wmDESTROY;menu_exit show_msg: invoke MessageBox,[hWnd],[menu_handlers+ebx*4],menu_name,eax ret wmDESTROY: invoke ExitProcess,ebx endp ;-------------------------------------------------------------------- ;exp = experiment wTitle db 'Iczelion Tutorial #8-1:Create a menu via a resource file in FASM',0 ;name of our window menu_name db 'ZZZ_Menu',0 test_msg db 'You select menu item TEST',0 open_msg db 'You select menu item OPEN',0 save_msg db 'You select menu item SAVE',0 menu_handlers dd test_msg, open_msg, save_msg ;--------------------------------------------------------------------- data import library KERNEL32, 'KERNEL32.DLL',\ user32, 'USER32.DLL' import KERNEL32,\ ExitProcess, 'ExitProcess' import user32,\ RegisterClass, 'RegisterClassA',\ CreateWindowEx, 'CreateWindowExA',\ DefWindowProc, 'DefWindowProcA',\ GetMessage, 'GetMessageA',\ DispatchMessage, 'DispatchMessageA',\ DestroyWindow, 'DestroyWindow',\ MessageBox, 'MessageBoxA' end data section '.rsrc' resource from 'ftut_08-01.res' data readable RC-file Code: #define ZZZ_TEST 0 #define ZZZ_OPEN 1 #define ZZZ_SAVE 2 #define ZZZ_EXIT 3 ZZZ_Menu MENU { POPUP "&File" { MENUITEM "&Test",ZZZ_TEST MENUITEM "&Open",ZZZ_OPEN MENUITEM "&Save",ZZZ_SAVE MENUITEM SEPARATOR MENUITEM "&Exit",ZZZ_EXIT } MENUITEM "&Exit",ZZZ_EXIT } Code: format PE GUI include 'win32ax.inc' ; import data in the same section ZZZ_TEST equ 0 ZZZ_OPEN equ 1 ZZZ_SAVE equ 2 ZZZ_EXIT equ 3 xor ebx,ebx mov edi,wTitle mov esi,400000h ; +------------------------------+ ; | registering the window class | ; +------------------------------+ invoke RegisterClass,esp,ebx,WndProc,ebx,\ ebx,esi,ebx,10011h,COLOR_WINDOW+1,30,edi ; +--------------------------+ ; | creating the main window | ; +--------------------------+ push ebx esi ebx ebx shl esi,9 invoke CreateWindowEx,ebx,edi,edi,WS_OVERLAPPEDWINDOW+WS_VISIBLE,\ esi,esi,esi,esi mov ebp,esp ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ message_loop: invoke GetMessage,ebp,ebx,ebx,ebx invoke DispatchMessage,ebp jmp message_loop ; +----------------------+ ; | the window procedure | ; +----------------------+ proc WndProc,hWnd,uMsg,wParam,lParam mov eax,[uMsg] dec eax; cmp uMsg,WM_DESTROY dec eax je wmDESTROY sub eax,WM_COMMAND-WM_DESTROY; cmp uMsg,WM_PAINT je wmCOMMAND wmDEFAULT: leave jmp dword [DefWindowProc] wmCOMMAND: mov ebx,[wParam] cmp ebx,ZZZ_EXIT;03 je wmDESTROY;menu_exit show_msg: invoke MessageBox,[hWnd],[menu_handlers+ebx*4],menu_name,eax wmBYE: ret wmDESTROY: invoke ExitProcess,ebx endp ;----------------------------------------------------- ;exp = experiment wTitle db 'Iczelion Tutorial #8-2:Create a menu function through LoadMenu in FASM',0 ;name of our window menu_name db 'ZZZ_Menu',0 test_msg db 'You select menu item TEST',0 open_msg db 'You select menu item OPEN',0 save_msg db 'You select menu item SAVE',0 menu_handlers dd test_msg, open_msg, save_msg ;----------------------------------------------------------- data import library KERNEL32, 'KERNEL32.DLL',\ user32, 'USER32.DLL' import KERNEL32,\ ExitProcess, 'ExitProcess' import user32,\ RegisterClass, 'RegisterClassA',\ CreateWindowEx, 'CreateWindowExA',\ DefWindowProc, 'DefWindowProcA',\ GetMessage, 'GetMessageA',\ DispatchMessage, 'DispatchMessageA',\ DestroyWindow, 'DestroyWindow',\ MessageBox, 'MessageBoxA' end data ;----------------------------------------------- align 4 data resource directory RT_MENU,appMenu resource appMenu,\ 30,LANG_ENGLISH,menuMain menu menuMain menuitem '&File',0,MFR_POPUP menuitem '&Test',ZZZ_TEST,MFT_STRING menuitem '&Open',ZZZ_OPEN,MFT_STRING menuitem '&Save',ZZZ_SAVE,MFT_STRING menuseparator menuitem '&Exit',ZZZ_EXIT,MFR_END menuitem '&Exit',ZZZ_EXIT,MFR_END end data Code: format PE GUI include 'win32ax.inc' ; import data in the same section ZZZ_TEST equ 0 ZZZ_OPEN equ 1 ZZZ_SAVE equ 2 ZZZ_EXIT equ 3 MFR_END equ 80h MFR_POPUP equ 01h xor ebx,ebx mov edi,wTitle mov esi,400000h ; +------------------------------+ ; | registering the window class | ; +------------------------------+ invoke RegisterClass,esp,ebx,WndProc,ebx,\ ebx,esi,ebx,10011h,COLOR_WINDOW+1,ebx,edi invoke LoadMenuIndirect,appMenuTemplate ; +--------------------------+ ; | creating the main window | ; +--------------------------+ push ebx esi eax ebx shl esi,9 invoke CreateWindowEx,ebx,edi,edi,WS_OVERLAPPEDWINDOW+WS_VISIBLE,\ esi,esi,esi,esi mov ebp,esp ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ message_loop: invoke GetMessage,ebp,ebx,ebx,ebx invoke DispatchMessage,ebp jmp message_loop ; +----------------------+ ; | the window procedure | ; +----------------------+ proc WndProc,hWnd,uMsg,wParam,lParam mov eax,[uMsg] dec eax; cmp uMsg,WM_DESTROY dec eax je .wmDESTROY sub eax,WM_COMMAND-WM_DESTROY; cmp uMsg,WM_PAINT je .wmCOMMAND .wmDEFAULT: leave jmp dword [DefWindowProc] .wmCOMMAND: mov ebx,[wParam] cmp ebx,ZZZ_EXIT;03 je .wmDESTROY;menu_exit invoke MessageBox,[hWnd],[menu_handlers+ebx*4],menu_name,eax .wmBYE: ret .wmDESTROY: invoke ExitProcess,ebx endp ;----------------------------------------------------------- ;exp = experiment wTitle db 'Iczelion Tutorial #8-3: Creating menus via Template-structure in FASM',0 ;name of our window menu_name db 'ZZZ_Menu',0 test_msg db 'You select menu item TEST',0 open_msg db 'You select menu item OPEN',0 save_msg db 'You select menu item SAVE',0 menu_handlers dd test_msg, open_msg, save_msg appMenuTemplate dw 1 ; menu template version dw 4 ; offset from end of this word to menu item list dd 0 ; menu bar help ID dd MFT_STRING,MFS_ENABLED,0 dw MFR_POPUP ; first column du '&File',0,0 ; pad to align 4 dd 0 ; popup help ID dd MFT_STRING,MFS_ENABLED,ZZZ_TEST du 0,'&Test',0,0 dd MFT_STRING,MFS_ENABLED,ZZZ_OPEN du 0,'&Open',0,0 dd MFT_STRING,MFS_ENABLED,ZZZ_SAVE du 0,'&Save',0,0 dd MFT_SEPARATOR,0,0 dw 0,0 ; pad to align 4 dd MFT_STRING,MFS_ENABLED,ZZZ_EXIT dw MFR_END ; bottom of column du '&Exit',0,0 ; pad to align 4 dd MFT_STRING,MFS_ENABLED,ZZZ_EXIT dw MFR_END ; second column, last one du '&Exit',0,0 ; pad to align 4 dd 0 ; popup help ID ;-------------------------------------------------------- data import library KERNEL32, 'KERNEL32.DLL',\ user32, 'USER32.DLL' import KERNEL32,\ ExitProcess, 'ExitProcess' import user32,\ RegisterClass, 'RegisterClassA',\ CreateWindowEx, 'CreateWindowExA',\ DefWindowProc, 'DefWindowProcA',\ GetMessage, 'GetMessageA',\ DispatchMessage, 'DispatchMessageA',\ DestroyWindow, 'DestroyWindow',\ MessageBox, 'MessageBoxA',\ LoadMenuIndirect, 'LoadMenuIndirectA' end data Code: format PE GUI include 'win32ax.inc' ; import data in the same section ZZZ_TEST equ 0 ZZZ_OPEN equ 1 ZZZ_SAVE equ 2 ZZZ_EXIT equ 3 xor ebx,ebx mov edi,wTitle mov esi,400000h ; +------------------------------+ ; | registering the window class | ; +------------------------------+ invoke RegisterClass,esp,ebx,WndProc,ebx,\ ebx,esi,ebx,10011h,COLOR_WINDOW+1,ebx,edi ; +--------------------------+ ; | creating the main window | ; +--------------------------+ push ebx esi ebx ebx shl esi,9 invoke CreateWindowEx,ebx,edi,edi,WS_OVERLAPPEDWINDOW+\ WS_VISIBLE,esi,esi,esi,esi mov ebp,esp ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ message_loop: invoke GetMessage,ebp,ebx,ebx,ebx invoke DispatchMessage,ebp jmp message_loop ; +----------------------+ ; | the window procedure | ; +----------------------+ proc WndProc,hWnd,uMsg,wParam,lParam mov eax,[uMsg] dec eax; cmp uMsg,WM_CREATE je wmCREATE dec eax; cmp uMsg,WM_DESTROY je wmDESTROY sub eax,WM_COMMAND-WM_DESTROY; cmp uMsg,WM_PAINT je wmCOMMAND leave jmp dword [DefWindowProc] wmCREATE: invoke CreatePopupMenu mov edi,eax; mov hPopupMenu,eax lea esi,[AppendMenu] push menu_test1 push ZZZ_TEST push MF_STRING push eax;hPopupMenu call dword [esi];_imp__AppendMenuA@16 push menu_open1 push ZZZ_OPEN push MF_STRING push edi;hPopupMenu call dword [esi];_imp__AppendMenuA@16 push menu_save1 push ZZZ_SAVE push MF_STRING push edi;hPopupMenu call dword [esi];_imp__AppendMenuA@16 push ebx;0 push ebx;0 push MF_SEPARATOR push edi;hPopupMenu call dword [esi];_imp__AppendMenuA@16 push menu_exit1 push ZZZ_EXIT push MF_STRING push edi;hPopupMenu call dword [esi];_imp__AppendMenuA@16 invoke CreateMenu,MF_POPUP,edi,menu_file mov edi,eax;mov edi,hMenu push edi;hMenu call dword [esi];_imp__AppendMenuA@16 push menu_exit1 push ZZZ_EXIT push MF_STRING push edi;hMenu call dword [esi];_imp__AppendMenuA@16 invoke SetMenu,[hWnd],edi jmp wmBYE wmCOMMAND: mov ebx,[wParam] cmp ebx,ZZZ_EXIT;03 je wmDESTROY;menu_exit show_msg: invoke MessageBox,[hWnd],[menu_handlers+ebx*4],menu_name,eax wmBYE: ret wmDESTROY: invoke ExitProcess,ebx endp ;--------------------------------------------------------------- ;exp = experiment wTitle db 'Iczelion Tutorial #8-4: Software creation menu in FASM',0 ;name of our window menu_file db 'File',0 menu_test1 db 'Test',0 menu_open1 db 'Open',0 menu_save1 db 'Save',0 menu_exit1 db 'Exit',0 menu_name db 'ZZZ_Menu',0 test_msg db 'You select menu item TEST',0 open_msg db 'You select menu item OPEN',0 save_msg db 'You select menu item SAVE',0 menu_handlers dd test_msg, open_msg, save_msg ;---------------------------------------------------------------- data import library KERNEL32, 'KERNEL32.DLL',\ user32, 'USER32.DLL' import KERNEL32,\ ExitProcess, 'ExitProcess' import user32,\ RegisterClass, 'RegisterClassA',\ CreateWindowEx, 'CreateWindowExA',\ DefWindowProc, 'DefWindowProcA',\ GetMessage, 'GetMessageA',\ DispatchMessage, 'DispatchMessageA',\ DestroyWindow, 'DestroyWindow',\ MessageBox, 'MessageBoxA',\ AppendMenu, 'AppendMenuA',\ CreatePopupMenu, 'CreatePopupMenu',\ CreateMenu, 'CreateMenu',\ SetMenu, 'SetMenu' end data Code: format PE GUI include 'win32ax.inc' ; import data in the same section STYLBTN equ BS_DEFPUSHBUTTON+WS_VISIBLE+WS_CHILD xor ebx,ebx mov edi,wTitle mov esi,400000h ; +------------------------------+ ; | registering the window class | ; +------------------------------+ invoke RegisterClass,esp,CS_VREDRAW+CS_HREDRAW,\ WndProc,ebx,ebx,esi,ebx,10011h,COLOR_WINDOW+1,ebx,edi ; +--------------------------+ ; | creating the main window | ; +--------------------------+ push ebx esi ebx ebx shl esi,9 invoke CreateWindowEx,ebx,edi,SPACE,WS_OVERLAPPEDWINDOW+\ WS_VISIBLE,esi,esi,esi,esi mov ebp,esp ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ message_loop: invoke GetMessage,ebp,ebx,ebx,ebx invoke DispatchMessage,ebp jmp message_loop ; +----------------------+ ; | the window procedure | ; +----------------------+ proc WndProc,hWnd,uMsg,wParam,lParam local MENI:MENUITEMINFO local buffer[100]:BYTE mov eax,[uMsg] mov edi,[hWnd] dec eax; cmp uMsg,WM_CREATE je wmCREATE dec eax; cmp uMsg,WM_DESTROY je wmDESTROY sub eax,WM_COMMAND-WM_DESTROY; cmp uMsg,WM_PAINT je wmCOMMAND sub eax,WM_MENUSELECT-WM_COMMAND je wmMENUSELECT wmDEFAULT: leave jmp dword [DefWindowProc] wmCOMMAND: mov eax,[HWNDBTN];check to see if you pressed cmp [lParam],eax je YES_BUT cmp word [wParam],5;check to see whether the selected menu item MENUC - exit je wmDESTROY cmp word [wParam],4;check to see whether the selected menu item with ID 5 jne FINISH YES_BUT:;Processing pressing. first delete the text in the title invoke SendMessage,edi,WM_SETTEXT,ebx,SPACE dec [PRIZN] jns l5 add [PRIZN],3;if (PRIZN < 0) PRIZN=2 jmp l5 wmCREATE: invoke CreateWindowEx,ebx,CLSBUTN,CPBUT,STYLBTN,\ 10,10,120,25,edi,ebx,esi,ebx mov [HWNDBTN],eax;Remember handle button l5: ;download the desired menu invoke LoadMenu,400000h,[PRIZN] invoke SetMenu,edi,eax;set menu jmp FINISH wmMENUSELECT: mov ecx,[lParam] jecxz FINISH;skip the first message when accessing the menu test word [wParam+2],MF_POPUP;check that activated - menu item or heading drop down menu setne al ;filling structure for function call GetMenuItemInfo lea esi,[MENI] mov [esi+MENUITEMINFO.cbSize],sizeof.MENUITEMINFO mov [esi+MENUITEMINFO.fMask],MIIM_TYPE mov [esi+MENUITEMINFO.hSubMenu],ecx;MENI.hSubMenu:=lParam mov [esi+MENUITEMINFO.dwTypeData],esp;Pointer to a buffer that receives the desired line mov [esi+MENUITEMINFO.cch],100;sizeof.buffer;buffer length push esi;receive information about the selected menu item push eax ;if 0, then lword wParam menu item identifier ;if 1, the title number lword wParam drop-down menu movzx eax,word [wParam] invoke GetMenuItemInfo,ecx,eax ;check the function result or eax,eax;cmp eax,0 jz FINISH ;display the name of the menu item as the title of all windows invoke SendMessage,edi,WM_SETTEXT,ebx,[esi+MENUITEMINFO.dwTypeData] FINISH: leave retn 0x10 wmDESTROY: invoke ExitProcess,ebx endp ;----------------------------------------------------------- ;exp = experiment wTitle db 'Iczelion Tutorial #8-5: Creating dynamic menu in FASM',0 ;name of our window SPACE db 30 dup(32),0 CLASSNAME db 'CLASS32',0 CPBUT db 'Change menu',0 CLSBUTN db 'BUTTON',0 HWNDBTN dd 0 PRIZN dd 2 ;------------------------------------------------------------- data import library KERNEL32, 'KERNEL32.DLL',\ user32, 'USER32.DLL' import KERNEL32,\ ExitProcess, 'ExitProcess' import user32,\ RegisterClass, 'RegisterClassA',\ CreateWindowEx, 'CreateWindowExA',\ DefWindowProc, 'DefWindowProcA',\ GetMessage, 'GetMessageA',\ DispatchMessage, 'DispatchMessageA',\ MessageBox, 'MessageBoxA',\ LoadMenu, 'LoadMenuA',\ SetMenu, 'SetMenu',\ SendMessage, 'SendMessageA',\ GetMenuItemInfo, 'GetMenuItemInfoA' end data ;----------------------------------------------------- align 4 data resource directory RT_MENU,appMenu resource appMenu,\ 2,LANG_ENGLISH+SUBLANG_ENGLISH_US,MENUN,\ 1,LANG_ENGLISH+SUBLANG_ENGLISH_US,MENUP,\ 0,LANG_ENGLISH+SUBLANG_ENGLISH_US,MENUC menu MENUP menuitem 'First point',10,MFR_POPUP menuitem 'First',1,MFT_STRING menuitem 'Second',2,MFR_END menuitem 'Second point',20,MFR_POPUP+MFR_END menuitem 'Third',3,MFT_STRING menuitem 'Fourth',4,MFT_STRING menuseparator menuitem 'Else submenu',30,MFR_POPUP menuitem 'Additional point',6,MFT_STRING+MFR_END menuitem 'Exit',5,MFR_END menu MENUC menuitem 'First set',10,MFR_POPUP menuitem 'White',101,MFT_STRING menuitem 'Grey',102,MFT_STRING menuitem 'Black',103,MFR_END menuitem 'Second set',30,MFR_POPUP+MFR_END menuitem 'Red',104,MFT_STRING menuitem 'Blue',105,MFT_STRING menuitem 'Green',106,MFR_END menu MENUN menuitem '',2,MFR_END end data Code: format PE GUI include 'win32ax.inc' ; import data in the same section ZZZ_TEST equ 0 ZZZ_OPEN equ 1 ZZZ_SAVE equ 2 ZZZ_EXIT equ 3 xor ebx,ebx mov edi,wTitle mov esi,400000h ; +------------------------------+ ; | registering the window class | ; +------------------------------+ invoke RegisterClass,esp,ebx,WndProc,ebx,\ ebx,esi,ebx,10011h,COLOR_WINDOW+1,ebx,edi ; +--------------------------+ ; | creating the main window | ; +--------------------------+ push ebx esi ebx ebx shl esi,9 invoke CreateWindowEx,ebx,edi,edi,WS_OVERLAPPEDWINDOW+\ WS_VISIBLE,esi,esi,esi,esi mov ebp,msg ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ message_loop: invoke GetMessage,ebp,ebx,ebx,ebx invoke DispatchMessage,ebp jmp message_loop ; +----------------------+ ; | the window procedure | ; +----------------------+ proc WndProc hWnd, uMsg, wParam, lParam local hMenu:DWORD local rect:RECT mov eax,[uMsg] dec eax; cmp uMsg,WM_DESTROY dec eax je wmDESTROY sub eax,WM_COMMAND-WM_DESTROY; cmp uMsg,WM_PAINT je wmCOMMAND sub eax,WM_RBUTTONDOWN-WM_COMMAND;cmp uMsg,WM_RBUTTONDOWN je wmRBUTTONDOWN leave jmp dword [DefWindowProc] wmRBUTTONDOWN: invoke CreatePopupMenu mov edi,eax;hPopupMenu,eax invoke CreateMenu mov [hMenu],eax lea esi,[AppendMenu] push menu_test1 ZZZ_TEST MF_STRING edi;hPopupMenu call dword [esi];_imp__AppendMenuA@16 push menu_open1 ZZZ_OPEN MF_STRING edi;hPopupMenu call dword [esi];_imp__AppendMenuA@16 push menu_save1 ZZZ_SAVE MF_STRING edi;hPopupMenu call dword [esi];_imp__AppendMenuA@16 push ebx ebx MF_SEPARATOR edi;hPopupMenu call dword [esi];_imp__AppendMenuA@16 push menu_exit1 ZZZ_EXIT MF_STRING edi;hPopupMenu call dword [esi];_imp__AppendMenuA@16 push menu_file edi MF_POPUP [hMenu] call dword [esi];_imp__AppendMenuA@16 push menu_exit1 ZZZ_EXIT MF_STRING [hMenu] call dword [esi];_imp__AppendMenuA@16 invoke TrackPopupMenu,edi,TPM_LEFTALIGN+TPM_LEFTBUTTON,[msg.pt.x],[msg.pt.y],\ ebx,dword [hWnd],ebx invoke GetWindowRect,dword [hWnd],esp;push offset rect jmp end_wm_check wmCOMMAND: mov ebx,[wParam] cmp ebx,ZZZ_EXIT je wmDESTROY;menu_exit show_msg: invoke MessageBox,dword [hWnd],[menu_handlers+ebx*4],menu_name,eax end_wm_check: ret wmDESTROY: invoke ExitProcess,ebx endp ;------------------------------------------------------- wTitle db 'Iczelion Tutorial #8-6: Creating a floating menu',0 ;name of our window menu_file db 'File',0 menu_test1 db 'Test',0 menu_open1 db 'Open',0 menu_save1 db 'Save',0 menu_exit1 db 'Exit',0 menu_name db 'ZZZ_Menu',0 test_msg db 'You select menu item TEST',0 open_msg db 'You select menu item OPEN',0 save_msg db 'You select menu item SAVE',0 menu_handlers dd test_msg, open_msg, save_msg msg MSG ;--------------------------------------------------- data import library KERNEL32, 'KERNEL32.DLL',\ user32, 'USER32.DLL' import KERNEL32,\ ExitProcess, 'ExitProcess' import user32,\ RegisterClass, 'RegisterClassA',\ CreateWindowEx, 'CreateWindowExA',\ DefWindowProc, 'DefWindowProcA',\ GetMessage, 'GetMessageA',\ DispatchMessage, 'DispatchMessageA',\ CreateMenu, 'CreateMenu',\ AppendMenu, 'AppendMenuA',\ TrackPopupMenu, 'TrackPopupMenu',\ GetWindowRect, 'GetWindowRect',\ CreatePopupMenu, 'CreatePopupMenu',\ MessageBox, 'MessageBoxA' end data align 4 data resource directory RT_MENU,appMenu resource appMenu,\ 30,LANG_ENGLISH,Menu menu Menu menuitem '&File',10,MFR_POPUP menuitem '&Test',ZZZ_TEST,MFT_STRING menuitem '&Open',ZZZ_OPEN,MFT_STRING menuitem '&Save',ZZZ_SAVE,MFT_STRING menuseparator menuitem '&Exit',ZZZ_EXIT,MFR_END menuitem '&Exit',ZZZ_EXIT,MFR_END end data Code: format PE GUI 4.0 include 'win32ax.inc' ; import data in the same section ZZZ_TEST equ 0 ZZZ_OPEN equ 1 ZZZ_SAVE equ 2 ZZZ_EXIT equ 3 TBSTYLE_BUTTON equ 00h TBSTYLE_SEP equ 01h TBSTYLE_CHECK equ 02h TBSTYLE_GROUP equ 04h TBSTYLE_CHECKGROUP equ TBSTYLE_GROUP OR TBSTYLE_CHECK TBSTYLE_TOOLTIPS equ 0100h TBSTYLE_WRAPABLE equ 0200h TBSTYLE_ALTDRAG equ 0400h TBSTYLE_FLAT equ 0800h TBSTYLE_LIST equ 1000h TBSTYLE_CUSTOMERASE equ 2000h TBSTYLE_REGISTERDROP equ 4000h TBSTYLE_TRANSPARENT equ 8000h TBSTYLE_DROPDOWN equ 0008h TBSTYLE_NOPREFIX equ 0020h TBSTYLE_EX_DRAWDDARROWS equ 00000001h TBSTYLE_EX_MIXEDBUTTONS equ 00000008h TBSTYLE_EX_HIDECLIPPEDBUTTONS equ 00000010h TBSTYLE_AUTOSIZE equ 10h BTNS_BUTTON equ TBSTYLE_BUTTON BTNS_SEP equ TBSTYLE_SEP BTNS_CHECK equ TBSTYLE_CHECK BTNS_GROUP equ TBSTYLE_GROUP BTNS_CHECKGROUP equ TBSTYLE_CHECKGROUP BTNS_DROPDOWN equ TBSTYLE_DROPDOWN BTNS_AUTOSIZE equ TBSTYLE_AUTOSIZE BTNS_NOPREFIX equ TBSTYLE_NOPREFIX BTNS_WHOLEDROPDOWN equ 0080h ; draw drop-down arrow, but without split arrow section I_IMAGENONE equ -2 ;========================================================= xor ebx,ebx sub esp,sizeof.INITCOMMONCONTROLSEX mov [esp+INITCOMMONCONTROLSEX.dwSize],sizeof.INITCOMMONCONTROLSEX mov [esp+INITCOMMONCONTROLSEX.dwICC],ICC_BAR_CLASSES invoke InitCommonControlsEx,esp add esp,sizeof.INITCOMMONCONTROLSEX invoke GlobalAlloc,40h,\ ; uFlags 1024 ; memory buffer size xchg esi,eax mov edi, esi mov dword [edi],WS_OVERLAPPED+WS_SYSMENU+DS_CENTER+40h mov word [edi+8],1 ; number of controls mov word [edi+0Ah],50 ; x y co-ordinates mov word [edi+0Ch],50 mov word [edi+0Eh],230 mov word [edi+10h],100 add edi, 16h invoke MultiByteToWideChar,ebx,\ ;CodePage=0 1,\ ;dwFlags wTitle,\ ;caption -1,\ ;cchMultiByte edi,\ ;lpWideCharStr aMsSansSerif-wTitle ;cchWideChar add edi,(aMsSansSerif-wTitle)*2; 1Ah mov word [edi],10 ;pointsize inc edi;add edi, 2 inc edi invoke MultiByteToWideChar,ebx,\ ; CodePage=0 1,\ ; dwFlags aMsSansSerif,\ ; font -1,\ ; cchMultiByte edi,\ ; lpWideCharStr aMsctls_statusb-aMsSansSerif; cchWideChar add edi,(aMsctls_statusb-aMsSansSerif)*2+4-1 and edi,-4 ;align 4 = add edi,4-1 /and edi,-4 mov dword [edi], 50000000h mov word [edi+10h],150 ;DlgStatus=150 add edi, 12h invoke MultiByteToWideChar,ebx,\ ; CodePage=0 1,\ ; dwFlags aMsctls_statusb,\; lpMultiByteStr -1,\ ; cchMultiByte edi,\ ; lpWideCharStr aToolbarwindow3-aMsctls_statusb ; cchWideChar invoke DialogBoxIndirectParam,400000h,\ ; hInstance esi,\ ; hDialogTemplate ebx,\ ; hWndParent= 0 DialogFunc,\ ; lpDialogFunc ebx ; dwInitParam=0 invoke GlobalFree,esi ; hMem ret;invoke ExitProcess,ebx ;================================================================== proc DialogFunc hDlg:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD xor ebx,ebx mov eax,[uMsg] mov edi,[hDlg] sub eax,WM_CLOSE ;cmp uMsg,10h jz wmCLOSE sub eax,WM_INITDIALOG-WM_CLOSE;cmp uMsg,110h jz wmINITDIALOG dec eax ;cmp uMsg,111h jnz wmBye wmCOMMAND: mov ebx,[wParam] cmp ebx,ZZZ_EXIT;03 je wmCLOSE;menu_exit show_msg: invoke MessageBox,edi,[menu_handlers+ebx*4],menu_name,eax jmp wmBye wmINITDIALOG: lea esi,dword [SendMessage] push ebx ;hIcon push 1 push -128;WM_SETICON push edi; ; hDlg call dword [esi];SendMessageA invoke GetStockObject,SYSTEM_FIXED_FONT push TRUE;1 push eax ;hFont push WM_SETFONT;30h push edi ; hWndParent call text_bar push eax ;hToolbar call dword [esi];SendMessageA jmp wmBye ;--------------------------------------------------------------------------- wmCLOSE: invoke EndDialog,edi,ebx wmBye: xor eax,eax ret endp ;------------------------------------------------------------- text_bar: invoke CreateWindowEx,ebx,aToolbarwindow3,ebx,WS_CHILD+WS_VISIBLE+\ TBSTYLE_TOOLTIPS+TBSTYLE_FLAT+TBSTYLE_LIST+TBSTYLE_TRANSPARENT,ebx,ebx,\ 500,20,dword [esp+10h],ebx,400000h,ebx mov edi,eax;edi:=[TBhWnd] push ebx sizeof.TBBUTTON TB_BUTTONSTRUCTSIZE eax;TBhWnd call dword [esi] push ebx 5 TB_SETINDENT edi call dword [esi] ;esp=&tbb sub esp,sizeof.TBBUTTON;create a buffer for the structure TBBUTTON mov [esp+TBBUTTON.iBitmap],I_IMAGENONE;dword [edi],-2 mov [esp+TBBUTTON.dwData],ebx mov [esp+TBBUTTON.iString],ebx mov [esp+TBBUTTON.fsStyle],BTNS_BUTTON or BTNS_AUTOSIZE;byte [edi+9],10h; mov [esp+TBBUTTON.fsState],TBSTATE_ENABLED ;TxtItem 0, 0, "Test" mov [esp+TBBUTTON.idCommand],ebx ;0 push esp 1 TB_ADDBUTTONS edi ; hWnd call dword [esi] push aTest ebx TB_ADDSTRING edi call dword [esi] ;TxtItem 1, 1, "Open" inc [esp+TBBUTTON.idCommand] inc [esp+TBBUTTON.iString] push esp 1 TB_ADDBUTTONS edi ; hWnd call dword [esi] push aOpen ebx TB_ADDSTRING edi ; hWnd call dword [esi] ;TxtItem 2, 2, "Save" inc [esp+TBBUTTON.idCommand] inc [esp+TBBUTTON.iString] push esp 1 TB_ADDBUTTONS edi ; hWnd call dword [esi] push aSave ebx TB_ADDSTRING edi ; hWnd call dword [esi] ;TxtSeperator mov [esp+TBBUTTON.idCommand],ebx; 0 mov [esp+TBBUTTON.fsStyle],BTNS_SEP;byte [edi+9],1; push esp 1 TB_ADDBUTTONS edi ; hWnd call dword [esi] ;TxtItem 4, 3, "Exit" add [esp+TBBUTTON.idCommand], 3h mov [esp+TBBUTTON.fsStyle],BTNS_BUTTON or BTNS_AUTOSIZE inc [esp+TBBUTTON.iString] push esp 1 TB_ADDBUTTONS edi ; hWnd call dword [esi] push aExit ebx TB_ADDSTRING edi ; hWnd call dword [esi] mov eax,edi add esp,sizeof.TBBUTTON;destroy buffer retn 4 ;---------------------------------------- wTitle db 'Iczelion Tutorial #8-7: Imitation through the menu toolbar in FASM',0 ;name of our window aMsSansSerif db 'MS Sans Serif',0 aMsctls_statusb db 'msctls_statusbar32',0 aToolbarwindow3 db 'ToolbarWindow32',0 aTest db 'Test',0 aOpen db 'Open',0 aSave db 'Save',0 aExit db 'Exit',0 ;exp = experiment menu_name db 'ZZZ_Menu',0 test_msg db 'You select menu item TEST',0 open_msg db 'You select menu item OPEN',0 save_msg db 'You select menu item SAVE',0 menu_handlers dd test_msg, open_msg, save_msg ;-------------------------------------------- data import library KERNEL32, 'KERNEL32.DLL',\ user32, 'USER32.DLL',\ gdi32, 'gdi32.dll',\ comctl32, 'comctl32.dll' import KERNEL32,\ GlobalAlloc, 'GlobalAlloc',\ MultiByteToWideChar,'MultiByteToWideChar',\ GlobalFree, 'GlobalFree' import user32,\ DialogBoxIndirectParam,'DialogBoxIndirectParamA',\ LoadIcon, 'LoadIconA',\ EndDialog, 'EndDialog',\ SendMessage, 'SendMessageA',\ CreateWindowEx, 'CreateWindowExA',\ MessageBox, 'MessageBoxA' import gdi32,\ GetStockObject, 'GetStockObject' import comctl32,\ InitCommonControlsEx, 'InitCommonControlsEx' end data Code: format PE GUI include 'win32ax.inc' ; import data in the same section ZZZ_TEST equ 0 ZZZ_OPEN equ 1 ZZZ_SAVE equ 2 ZZZ_EXIT equ 3 IDM_MENU equ 37 IDM_FILE equ 100 ;menu 1 IDM_EXIT equ 200 ;menu 2 IDR_MAINACCEL equ 105 xor ebx,ebx mov edi,wTitle mov esi,400000h ; +------------------------------+ ; | registering the window class | ; +------------------------------+ invoke RegisterClass,esp,ebx,WndProc,ebx,\ ebx,esi,ebx,10011h,COLOR_WINDOW+1,IDM_MENU,edi ; +--------------------------+ ; | creating the main window | ; +--------------------------+ push ebx esi ebx ebx shl esi,9 invoke CreateWindowEx,ebx,edi,edi,WS_OVERLAPPEDWINDOW+WS_VISIBLE,\ esi,esi,esi,esi mov [hwnd],eax invoke LoadAccelerators,400000h,IDR_MAINACCEL mov [ACC],eax mov ebp,esp ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ message_loop: invoke GetMessage,ebp,ebx,ebx,ebx invoke DispatchMessage,ebp invoke TranslateAccelerator,[hwnd],[ACC],ebp or eax,eax jne message_loop invoke TranslateMessage,ebp jmp message_loop ; +----------------------+ ; | the window procedure | ; +----------------------+ proc WndProc hWnd, uMsg, wParam, lParam mov eax,[uMsg] dec eax dec eax; cmp uMsg,WM_DESTROY je wmDESTROY sub eax,WM_COMMAND-WM_DESTROY; cmp uMsg,WM_COMMAND je wmCOMMAND leave jmp dword [DefWindowProc] wmCOMMAND: mov ax,word[wParam] cmp eax,ZZZ_EXIT je wmDESTROY;menu_exit show_msg: invoke MessageBox,[hWnd],[menu_handlers+eax*4],menu_name,ebx;MB_OK ret wmDESTROY: invoke ExitProcess,eax endp ;----------------------------------------------------------- ;exp = experiment wTitle db 'Iczelion Tutorial #8-8: Working with tables accelerators in FASM',0 ;name of our window menu_name db 'ZZZ_Menu',0 test_msg db 'You select menu item TEST',0 open_msg db 'You select menu item OPEN',0 save_msg db 'You select menu item SAVE',0 menu_handlers dd test_msg, open_msg, save_msg ACC rd 1 hwnd rd 1 ;---------------------------------------------------------- data import library KERNEL32, 'KERNEL32.DLL',\ user32, 'USER32.DLL' import KERNEL32,\ ExitProcess, 'ExitProcess' import user32,\ RegisterClass, 'RegisterClassA',\ CreateWindowEx, 'CreateWindowExA',\ DefWindowProc, 'DefWindowProcA',\ GetMessage, 'GetMessageA',\ DispatchMessage, 'DispatchMessageA',\ DestroyWindow, 'DestroyWindow',\ MessageBox, 'MessageBoxA',\ TranslateAccelerator,'TranslateAcceleratorA',\ LoadAccelerators, 'LoadAcceleratorsA',\ TranslateMessage, 'TranslateMessage' end data align 4 data resource directory RT_MENU,menus,\ RT_ACCELERATOR,accelerators resource menus,\ IDM_MENU,LANG_ENGLISH+SUBLANG_DEFAULT,main_menu resource accelerators,\ IDR_MAINACCEL,LANG_ENGLISH+SUBLANG_DEFAULT,main_keys _ equ ,09h, ;tab menu main_menu menuitem '&File',IDM_FILE,MFR_POPUP menuitem '&Test' _ 'Ctrl+T',ZZZ_TEST menuitem '&Open' _ 'Ctrl+O',ZZZ_OPEN menuitem '&Save' _ 'Ctrl+S',ZZZ_SAVE menuseparator menuitem '&Exit' _ 'Ctrl+X',ZZZ_EXIT,MFR_END menuitem '&Exit',IDM_EXIT,MFR_POPUP + MFR_END menuitem '&Exit',ZZZ_EXIT,MFR_END accelerator main_keys,\ FVIRTKEY+FNOINVERT+FCONTROL,'T',ZZZ_TEST,\ FVIRTKEY+FNOINVERT+FCONTROL,'O',ZZZ_OPEN,\ FVIRTKEY+FNOINVERT+FCONTROL,'S',ZZZ_SAVE,\ FVIRTKEY+FNOINVERT+FCONTROL,'X',ZZZ_EXIT end data |
|||
12 Feb 2015, 06:02 |
|
Mikl___ 13 Feb 2015, 08:44
Toolbar
Code: format PE GUI include 'win32ax.inc' ; import data in the same section ID_1 equ 0 ID_2 equ 1 ID_3 equ 2 xor ebx,ebx mov edi,wTitle mov esi,400000h ; +------------------------------+ ; | registering the window class | ; +------------------------------+ invoke RegisterClass,esp,ebx,WndProc,ebx,\ ebx,esi,ebx,10011h,COLOR_WINDOW+1,ebx,edi ; +--------------------------+ ; | creating the main window | ; +--------------------------+ push ebx esi ebx ebx shl esi,9 invoke CreateWindowEx,ebx,edi,edi,WS_OVERLAPPEDWINDOW+\ WS_VISIBLE,esi,esi,esi,esi mov edi,eax ;hWnd push LR_LOADFROMFILE push ebx ;0 push ebx ;0 push ebx ;IMAGE_BITMAP push aMybp1 push 400000h ;hInstance call [LoadImage] mov edx,sizeof.TBBUTTON mov bl,2 lea ecx,[tbb+edx*2] @@: mov [ecx+TBBUTTON.iBitmap],ebx mov [ecx+TBBUTTON.idCommand],ebx mov [ecx+TBBUTTON.fsState],TBSTATE_ENABLED or ebx,ebx jz @f sub ecx,edx dec ebx jmp @b @@: push edx;size TBBUTTON ;size of structure TBBUTTON push 16 ;width and height push 16 ;of the image on each button push 16 ;width and height push 16 ;of each button push 3 ;number of buttons push ecx;offset tbb ;address of an array-type structure TBBUTTON push eax ;resource ID with the picture buttons push ebx ;0 push 3 ;number of images for buttons in the bmp-file push -1 ;ID entire dashboard which is not used in the program and may be equal -1 push WS_CHILD+WS_BORDER+WS_VISIBLE;style toolbar push edi ;handle to the main window call [CreateToolbarEx] lea esi,[hBlueBrush] lea edi,[CreateSolidBrush] mov ebp,0FF0000h push ebp;blue=0FF0000h call dword[edi] mov [esi],eax;hBlueBrush shr ebp,8 push ebp;green=0FF00h call dword[edi] mov [esi+4],eax;hGreenBrush mov ebp,esp ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ message_loop: invoke GetMessage,ebp,ebx,ebx,ebx invoke DispatchMessage,ebp jmp message_loop ; +----------------------+ ; | the window procedure | ; +----------------------+ proc WndProc hWnd, uMsg, wParam, lParam local paint:PAINTSTRUCT mov eax,[uMsg] mov edi,[hWnd] dec eax; cmp uMsg,WM_DESTROY dec eax je .wmDESTROY sub eax,WM_SIZE-WM_DESTROY;cmp eax,WM_SIZE je .wmSIZE sub eax,WM_PAINT-WM_SIZE;cmp eax,WM_PAINT je .wmPAINT sub eax,WM_COMMAND-WM_PAINT; cmp uMsg,WM_COMMAND je .wmCOMMAND leave jmp dword [DefWindowProc] .wmPAINT: invoke BeginPaint,edi,esp mov ecx,[sw] or ecx,ecx jz @f invoke FillRect,eax,Rect,dword[hBlueBrush+ecx*4-4];hBlueBrush @@: invoke EndPaint,edi,esp ;Free the context display jmp .wmBye .wmSIZE: mov eax,[lParam] mov word [Rect.right],ax shr eax,16 mov [Rect.bottom],eax jmp .wmBye .wmCOMMAND: mov eax,[wParam] jmp [handler+eax*4] .0: inc eax mov [sw],eax invoke InvalidateRect,edi,ebx,1 .wmBye: ret .wmDESTROY: invoke ExitProcess,ebx;completion of the program handler dd WndProc.0,WndProc.0,WndProc.wmDESTROY endp ;================================================== wTitle db 'Iczelion Tutorial #8-9: toolbar in FASM',0 ;name of our window hBlueBrush rd 2 sw dd 0 tbb TBBUTTON 0 TBBUTTON 0 TBBUTTON 0 aMybp1 db "Images\btns.bmp",0 Rect RECT ;---------------------------------------- data import library KERNEL32, 'KERNEL32.DLL',\ user32, 'USER32.DLL',\ comctl32, 'comctl32.dll',\ gdi32, 'gdi32.dll' import KERNEL32,\ ExitProcess, 'ExitProcess' import user32,\ RegisterClass, 'RegisterClassA',\ CreateWindowEx, 'CreateWindowExA',\ DefWindowProc, 'DefWindowProcA',\ GetMessage, 'GetMessageA',\ DispatchMessage, 'DispatchMessageA',\ LoadImage, 'LoadImageA',\ BeginPaint, 'BeginPaint',\ EndPaint, 'EndPaint',\ InvalidateRect, 'InvalidateRect',\ FillRect, 'FillRect' import gdi32,\ CreateSolidBrush, 'CreateSolidBrush' import comctl32,\ CreateToolbarEx, 'CreateToolbarEx' end data Code: format PE GUI include 'win32ax.inc' ; import data in the same section ID_1 equ 0 ID_2 equ 1 ID_3 equ 2 xor ebx,ebx mov edi,wTitle mov esi,400000h;hInstance ; +------------------------------+ ; | registering the window class | ; +------------------------------+ invoke RegisterClass,esp,ebx,WndProc,ebx,\ ebx,esi,ebx,10011h,COLOR_WINDOW+1,ebx,edi ; +--------------------------+ ; | creating the main window | ; +--------------------------+ push ebx esi ebx ebx shl esi,9 invoke CreateWindowEx,ebx,edi,edi,WS_OVERLAPPEDWINDOW+WS_VISIBLE,\ esi,esi,esi,esi mov edi,eax ;hWnd invoke LoadImage,400000h,aMybp1,ebx,ebx,ebx,LR_LOADFROMFILE mov edx,sizeof.TBBUTTON mov bl,2 lea ecx,[tbb+edx*2] @@: mov [ecx+TBBUTTON.iBitmap],ebx mov [ecx+TBBUTTON.idCommand],ebx;ID_1 ID_2 ID_3 mov [ecx+TBBUTTON.fsState],TBSTATE_ENABLED or ebx,ebx jz @f sub ecx,edx dec ebx jmp @b @@: invoke CreateToolbarEx,edi,WS_CHILD+WS_BORDER+WS_VISIBLE+TBSTYLE_TOOLTIPS,\ -1,3,ebx,eax,ecx,3,16,16,16,16,edx lea esi,[hBlueBrush] lea edi,[CreateSolidBrush] mov ebp,0FF0000h push ebp;blue=0FF0000h call dword[edi] mov [esi],eax;hBlueBrush shr ebp,8 push ebp;green=0FF00h call dword[edi] mov [esi+4],eax;hGreenBrush mov ebp,esp ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ message_loop: invoke GetMessage,ebp,ebx,ebx,ebx invoke DispatchMessage,ebp jmp message_loop ; +----------------------+ ; | the window procedure | ; +----------------------+ proc WndProc hWnd, uMsg, wParam, lParam local paint:PAINTSTRUCT local lpttt:DWORD mov eax,[uMsg] mov edi,[hWnd] dec eax; cmp uMsg,WM_DESTROY dec eax je .wmDESTROY sub eax,WM_SIZE-WM_DESTROY;cmp eax,WM_SIZE je .wmSIZE sub eax,WM_PAINT-WM_SIZE;cmp eax,WM_PAINT je .wmPAINT sub eax,WM_NOTIFY-WM_PAINT;cmp eax,WM_NOTIFY=4Eh je .wmNOTIFY sub eax,WM_COMMAND-WM_NOTIFY; cmp uMsg,WM_COMMAND je .wmCOMMAND leave jmp dword [DefWindowProc] .wmPAINT: invoke BeginPaint,edi,esp;&Paint mov ecx,[sw] or ecx,ecx jz @f invoke FillRect,eax,Rect,dword[hBlueBrush+ecx*4-4];hBlueBrush @@: invoke EndPaint,edi,esp ;Free the context display jmp .wmBye .wmNOTIFY: mov edx,[lParam] ;if( LPNMHDR(lParam)->code ==TTN_NEEDTEXT) cmp [edx+NMHDR.code],TTN_NEEDTEXTA;dword ptr [edx+8],TTN_NEEDTEXTA jnz .wmBye mov [lpttt],edx ;LPTOOLTIPTEXT lpttt = (LPTOOLTIPTEXT) lParam; mov eax,[edx+NMHDR.idFrom];[edx+4] ;switch (lpttt->hdr.idFrom) { cmp eax,ID_3 ;case ID_1:strcpy(lpttt->szText,"blue");break; ja .wmBye ;case ID_2:strcpy(lpttt->szText,"green");break; ;case ID_3:strcpy(lpttt->szText,"exit"); lea edx,[edx+TOOLTIPTEXT.szText] invoke lstrcpy,edx,dword[ps+eax*4] jmp .wmBye .wmSIZE: mov eax,[lParam] mov word [Rect.right],ax shr eax,16 mov [Rect.bottom],eax jmp .wmBye .wmCOMMAND: mov eax,[wParam] jmp [handler+eax*4] .0: inc eax mov [sw],eax invoke InvalidateRect,edi,ebx,1 .wmBye: ret .wmDESTROY: invoke ExitProcess,ebx;completion of the program handler dd WndProc.0,WndProc.0,WndProc.wmDESTROY endp ;================================================= wTitle db 'Iczelion Tutorial #8-10: toolbar and tooltips in FASM',0 ;name of our window hBlueBrush rd 2 sw dd 0 tbb TBBUTTON 0 TBBUTTON 0 TBBUTTON 0 aMybp1 db "Images\btns.bmp",0 Rect RECT 0 szText1 db 'Fill blue',0 szText2 db 'Fill green',0 szText3 db 'Exit',0 ps dd szText1,szText2,szText3 ;------------------------------------------------ data import library KERNEL32, 'KERNEL32.DLL',\ user32, 'USER32.DLL',\ comctl32, 'comctl32.dll',\ gdi32, 'gdi32.dll' import KERNEL32,\ ExitProcess, 'ExitProcess',\ lstrcpy, 'lstrcpyA' import user32,\ RegisterClass, 'RegisterClassA',\ CreateWindowEx, 'CreateWindowExA',\ DefWindowProc, 'DefWindowProcA',\ GetMessage, 'GetMessageA',\ DispatchMessage, 'DispatchMessageA',\ LoadImage, 'LoadImageA',\ BeginPaint, 'BeginPaint',\ EndPaint, 'EndPaint',\ InvalidateRect, 'InvalidateRect',\ FillRect, 'FillRect' import gdi32,\ CreateSolidBrush, 'CreateSolidBrush' import comctl32,\ CreateToolbarEx, 'CreateToolbarEx' end data Code: format PE GUI include 'win32ax.inc' ; import data in the same section xor ebx,ebx mov edi,wTitle mov esi,400000h call [InitCommonControls] invoke RegisterClass,esp,ebx,WndProc,ebx,\ ebx,esi,ebx,10011h,COLOR_BTNFACE+1,600,edi ; +--------------------------+ ; | creating the main window | ; +--------------------------+ push ebx esi ebx ebx shl esi,9 invoke CreateWindowEx,WS_EX_LEFT,edi,edi,WS_OVERLAPPEDWINDOW+WS_VISIBLE,\ esi,esi,esi,esi mov ebp,esp ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ message_loop: invoke GetMessage,ebp,ebx,ebx,ebx invoke DispatchMessage,ebp jmp message_loop ; +----------------------+ ; | the window procedure | ; +----------------------+ proc WndProc hWnd, uMsg, wParam, lParam local paint:PAINTSTRUCT local Tba:TBADDBITMAP local tbb:TBBUTTON local Rct:RECT local caH:DWORD local caW:DWORD xor ebx,ebx lea esi,[SendMessage] mov eax,[uMsg] dec eax;cmp eax,WM_CREATE=1 je wmCREATE dec eax;cmp eax,WM_DESTROY=2 je wmDESTROY sub eax,WM_SIZE-WM_DESTROY;cmp eax,WM_SIZE=5 je wmSIZE sub eax,WM_PAINT-WM_SIZE;cmp eax,WM_PAINT=0Fh je wmPAINT dec eax;cmp eax,WM_CLOSE=10h je wmCLOSE sub eax,WM_COMMAND-WM_CLOSE;cmp eax,WM_COMMAND=111h je wmCOMMAND ;All messages are not processed in the function WndProc, ;are sent to the default handling default:leave jmp [DefWindowProc] wmCLOSE: invoke MessageBox,[hWnd],aPleaseConfirmE,wTitle,MB_YESNO cmp eax,IDNO; 7 jnz default wmBye: ret wmPAINT: invoke BeginPaint,[hWnd],esp;&Paint push eax [hWnd] call Paint_Proc invoke EndPaint,[hWnd],esp ;Free the context display jmp wmBye wmCREATE: lea edi,[tbb] mov [edi+TBBUTTON.iBitmap],ebx mov [edi+TBBUTTON.idCommand],ebx mov [edi+TBBUTTON.fsState],TBSTATE_ENABLED mov [edi+TBBUTTON.fsStyle],TBSTYLE_SEP mov [edi+TBBUTTON.dwData],ebx mov [edi+TBBUTTON.iString],ebx push sizeof.TBBUTTON ;size of structure TBBUTTON push ebx ;width and height push ebx;0 ;of the image on each button push 10h ;width and height of each button push 10h push 1 ;number of buttons push edi ;address of an array-type structure TBBUTTON push ebx; 0 ;resource ID with the picture buttons push ebx; 0 push 1 ;number of images on buttons in the bmp-file push 300; ID entire dashboard which is not used in the program and may be -1 push WS_CHILD or WS_CLIPSIBLINGS or WS_VISIBLE;style toolbar push [hWnd] ;handle to the main window call [CreateToolbarEx] mov [hToolBar],eax lea ecx,[Tba] mov [ecx+TBADDBITMAP.hInst],HINST_COMMCTRL; 0FFFFFFFFh mov [ecx+TBADDBITMAP.nID], 1; btnsize 1=big 2=small push ecx 1 TB_ADDBITMAP eax;hToolBar call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_FILENEW; 6 mov [edi+TBBUTTON.fsStyle],TBSTYLE_BUTTON; 0 mov [edi+TBBUTTON.idCommand],50 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_FILEOPEN; 7 inc [edi+TBBUTTON.idCommand] push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_FILESAVE; 8 inc [edi+TBBUTTON.idCommand];52 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.idCommand],ebx ;0 mov [edi+TBBUTTON.fsStyle],TBSTYLE_SEP; 1 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_REDOW; 0Eh mov [edi+TBBUTTON.idCommand],53 mov [edi+TBBUTTON.fsStyle],TBSTYLE_BUTTON push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_DELETE; 0Eh inc [edi+TBBUTTON.idCommand];54 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],ebx;STD_CUT; 0 inc [edi+TBBUTTON.idCommand];55 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_COPY; 1 inc [edi+TBBUTTON.idCommand];56 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_PASTE; 2 inc [edi+TBBUTTON.idCommand];57 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_UNDO; 3 inc [edi+TBBUTTON.idCommand];58 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],ebx; 0 mov [edi+TBBUTTON.idCommand],ebx; 0 mov [edi+TBBUTTON.fsStyle],TBSTYLE_SEP; 1 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_FIND; 0Ch mov [edi+TBBUTTON.idCommand],59 mov [edi+TBBUTTON.fsStyle],TBSTYLE_BUTTON; 0 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_REPLACE; 0Dh inc [edi+TBBUTTON.idCommand];60 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],ebx; 0 mov [edi+TBBUTTON.idCommand],ebx; 0 mov [edi+TBBUTTON.fsStyle],TBSTYLE_SEP; 1 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_PRINT; 0Eh mov [edi+TBBUTTON.idCommand],61 mov [edi+TBBUTTON.fsStyle],TBSTYLE_BUTTON push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_PRINTPRE; 0Eh inc [edi+TBBUTTON.idCommand];62 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_PROPERTIES; 0Eh inc [edi+TBBUTTON.idCommand];63 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_HELP; 0Eh inc [edi+TBBUTTON.idCommand];64 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] ; Create the status bar invoke CreateStatusWindow,WS_CHILD or WS_VISIBLE or SBS_SIZEGRIP,ebx,[hWnd],200 mov [hStatus], eax jmp default wmSIZE: push ebx ebx TB_AUTOSIZE [hToolBar] call dword [esi] push [caW] pop [lParam] push [caH] pop dword[lParam+2] lea edi,[Rct] invoke GetWindowRect,[hStatus],edi mov eax,[edi+RECT.bottom] sub eax,[edi+RECT.top] sub [caH],eax invoke MoveWindow,[hStatus],ebx,[caH],[caW],[caH],TRUE jmp default wmCOMMAND: mov edi,[wParam] sub edi,50 cmp edi,14 ja @f push [handler+edi*4] ebx SB_SETTEXT [hStatus] ; hWnd call dword [esi]; SendMessageA invoke MessageBox,[hWnd],[handler+edi*4],aYouHaveSelecte,ebx jmp default @@: cmp edi,15 jnz @f push ebx SC_CLOSE WM_SYSCOMMAND [hWnd] call dword [esi]; SendMessageA jmp default @@: invoke MessageBox,[hWnd],aAssemblerPureS,wTitle,ebx jmp default wmDESTROY: invoke ExitProcess,ebx;completion of the program endp ;================================================= Paint_Proc: hWin equ esp+sizeof.RECT+14h;ebp+8 hDC equ esp+sizeof.RECT+18h;ebp+0Ch caW equ esp+sizeof.RECT+8;ebp-4 caH equ caW-4 tbH equ caH-4 sbH equ tbH-4 sub esp,sizeof.RECT+10h;place in the RECT structure and variables caW, caH, tbH, sbH mov edi,esp;&Rct lea esi,[GetWindowRect] push edi ; lpRect push dword[hWin] ; hWnd call [GetClientRect] push [edi+RECT.right] pop dword[caW] push [edi+RECT.bottom] pop dword[caH] push edi ; lpRect push [hToolBar] ; hWnd call dword[esi];[GetWindowRect] mov eax,[edi+RECT.bottom] sub eax,[edi+RECT.top] mov [tbH], eax push edi ; lpRect push [hStatus] ; hWnd call dword[esi];[GetWindowRect] mov eax,[edi+RECT.bottom] sub eax,[edi+RECT.top] mov [sbH], eax sub [caH], eax mov [edi+RECT.left],ebx;0 push dword[tbH] pop [edi+RECT.top] push dword[caW] pop [edi+RECT.right] push dword[caH] pop [edi+RECT.bottom] push BF_RECT; 0Fh ; grfFlags push EDGE_SUNKEN; 0Ah ; edge push edi ; qrc push dword[hDC] ; hdc call [DrawEdge] add esp,sizeof.RECT+10h;free the buffer retn 8 ;================================================================= wTitle db 'Iczelion Tutorial #8-11:toolbar in FASM',0 aYouHaveSelecte db 'You have selected',0 aNewFile db 'New File',0 aOpenFile db 'Open File',0 aSaveFile db 'Save File',0 aRedow db 'Redow',0 aDelete db 'Delete',0 aCut db 'Cut',0 aCopy db 'Copy',0 aPaste db 'Paste',0 aUndo db 'Undo',0 aSearch db 'Search',0 aReplace db 'Replace',0 aPrint db 'Print',0 aPreview db 'Previw',0 aProperties db 'Properties',0 aHelp db 'Help',0 aAssemblerPureS db 'Assembler, Pure & Simple',0 aPleaseConfirmE db 'Please Confirm Exit',0 hStatus dd 0 hToolBar dd 0 handler dd aNewFile,aOpenFile,aSaveFile,aRedow,aDelete,aCut,aCopy dd aPaste,aUndo,aSearch,aReplace,aPrint,aPreview,aProperties,aHelp ;-------------------------------------------------------- data import library KERNEL32, 'KERNEL32.DLL',\ user32, 'USER32.DLL',\ comctl32, 'comctl32.dll' import KERNEL32,\ ExitProcess, 'ExitProcess' import user32,\ RegisterClass, 'RegisterClassA',\ CreateWindowEx, 'CreateWindowExA',\ DispatchMessage, 'DispatchMessageA',\ DefWindowProc, 'DefWindowProcA',\ GetMessage, 'GetMessageA',\ SendMessage, 'SendMessageA',\ BeginPaint, 'BeginPaint',\ EndPaint, 'EndPaint',\ GetWindowRect, 'GetWindowRect',\ MoveWindow, 'MoveWindow',\ GetClientRect, 'GetClientRect',\ DrawEdge, 'DrawEdge',\ MessageBox, 'MessageBoxA' import comctl32,\ InitCommonControls, 'InitCommonControls',\ CreateToolbarEx, 'CreateToolbarEx',\ CreateStatusWindow, 'CreateStatusWindowA' end data ;-------------------------------------------------------------- align 4 data resource directory RT_MENU,menus IDM_MENU = 600 ID_EXIT = 65 ID_ABOUT = 66 resource menus,\ IDM_MENU,LANG_ENGLISH+SUBLANG_DEFAULT,main_menu menu main_menu menuitem '&File',0,MFR_POPUP menuitem '&Exit',ID_EXIT,MFR_END menuitem '&Help',0,MFR_POPUP + MFR_END menuitem '&About',ID_ABOUT,MFR_END end data Code: format PE GUI include 'win32ax.inc' ; import data in the same section xor ebx,ebx mov edi,wTitle mov esi,400000h invoke InitCommonControls invoke RegisterClassEx,esp,sizeof.WNDCLASSEX,ebx,WndProc,\ ebx,ebx,esi,ebx,10011h,COLOR_BTNFACE+1,600,edi ; +--------------------------+ ; | creating the main window | ; +--------------------------+ push ebx esi ebx ebx shl esi,9 invoke CreateWindowEx,WS_EX_LEFT,edi,edi,WS_OVERLAPPEDWINDOW+WS_VISIBLE,\ esi,esi,500,300 mov ebp,esp ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ message_loop: invoke GetMessage,ebp,ebx,ebx,ebx invoke DispatchMessage,ebp jmp message_loop ; +----------------------+ ; | the window procedure | ; +----------------------+ proc WndProc hWnd, uMsg, wParam, lParam local paint:PAINTSTRUCT local pd:PRINTDLG local psd:PAGESETUPDLG local buffer[256]:BYTE local ofn:OPENFILENAME local Tba:TBADDBITMAP local tbb:TBBUTTON local Rct:RECT local caH:DWORD local caW:DWORD lea esi,[SendMessage] mov eax,[uMsg] dec eax;cmp eax,WM_CREATE=1 je wmCREATE dec eax;cmp eax,WM_DESTROY=2 je wmDESTROY sub eax,WM_SIZE-WM_DESTROY;cmp eax,WM_SIZE=5 je wmSIZE sub eax,WM_PAINT-WM_SIZE;cmp eax,WM_PAINT=0Fh je wmPAINT dec eax;cmp eax,WM_CLOSE=10h je wmCLOSE sub eax,WM_COMMAND-WM_CLOSE;cmp eax,WM_COMMAND=111h je wmCOMMAND default:leave jmp [DefWindowProc] wmCLOSE: invoke MessageBox,[hWnd],aPleaseConfirmE,wTitle,MB_YESNO cmp eax,IDNO; 7 jnz default wmBye: ret wmPAINT: invoke BeginPaint,[hWnd],esp push eax [hWnd] call Paint_Proc invoke EndPaint,[hWnd],esp jmp wmBye wmCREATE: lea edi,[tbb] mov [edi+TBBUTTON.iBitmap],ebx mov [edi+TBBUTTON.idCommand],ebx mov [edi+TBBUTTON.fsState],TBSTATE_ENABLED mov [edi+TBBUTTON.fsStyle],TBSTYLE_SEP mov [edi+TBBUTTON.dwData],ebx mov [edi+TBBUTTON.iString],ebx push sizeof.TBBUTTON push ebx push ebx;0 push 10h push 10h push 1 push edi push ebx; 0 push ebx; 0 push 1 push 300 push WS_CHILD or WS_CLIPSIBLINGS or WS_VISIBLE push [hWnd] call [CreateToolbarEx] mov [hToolBar],eax lea ecx,[Tba] mov [ecx+TBADDBITMAP.hInst],HINST_COMMCTRL; 0FFFFFFFFh mov [ecx+TBADDBITMAP.nID], 1; btnsize 1=big 2=small push ecx 1 TB_ADDBITMAP eax;hToolBar call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_FILENEW ; 6 mov [edi+TBBUTTON.fsStyle],bl;TBSTYLE_BUTTON=0 mov [edi+TBBUTTON.idCommand],50 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_FILEOPEN; 7 inc [edi+TBBUTTON.idCommand];51 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_FILESAVE; 8 inc [edi+TBBUTTON.idCommand];52 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.idCommand],ebx ;0 mov [edi+TBBUTTON.fsStyle],TBSTYLE_SEP; 1 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],ebx;STD_CUT; 0 mov [edi+TBBUTTON.idCommand],53 mov [edi+TBBUTTON.fsStyle],bl;TBSTYLE_BUTTON=0 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_COPY; 1 inc [edi+TBBUTTON.idCommand];54 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_PASTE; 2 inc [edi+TBBUTTON.idCommand];55 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_UNDO; 3 inc [edi+TBBUTTON.idCommand];56 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],ebx; 0 mov [edi+TBBUTTON.idCommand],ebx; 0 mov [edi+TBBUTTON.fsStyle],TBSTYLE_SEP; 1 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_FIND; 0Ch mov [edi+TBBUTTON.idCommand],57 mov [edi+TBBUTTON.fsStyle],bl;TBSTYLE_BUTTON; 0 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_PRINTPRE; 0Dh inc [edi+TBBUTTON.idCommand];58 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],ebx; 0 mov [edi+TBBUTTON.idCommand],ebx; 0 mov [edi+TBBUTTON.fsStyle],TBSTYLE_SEP; 1 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] mov [edi+TBBUTTON.iBitmap],STD_PRINT; 0Eh mov [edi+TBBUTTON.idCommand],59 mov [edi+TBBUTTON.fsStyle],bl;TBSTYLE_BUTTON=0 push edi 1 TB_ADDBUTTONS [hToolBar] call dword [esi] ; Create the status bar invoke CreateStatusWindow,WS_CHILD or WS_VISIBLE or SBS_SIZEGRIP,ebx,[hWnd],200 mov [hStatus], eax jmp default wmDESTROY: invoke ExitProcess,ebx;completion of the program wmSIZE: push ebx ebx TB_AUTOSIZE [hToolBar] call dword [esi] push dword[caW] pop dword[lParam+0] push dword[caH] pop dword[lParam+2] lea edi,[Rct] push edi push [hStatus] call [GetWindowRect] mov eax,[edi+RECT.bottom] sub eax,[edi+RECT.top] sub [caH],eax invoke MoveWindow,[hStatus],ebx,[caH],[caW],[caH],TRUE jmp default wmCOMMAND: mov edi,[wParam] sub edi,50 push [handlers+edi*4] ebx SB_SETTEXT [hStatus] ; hWnd call dword [esi]; SendMessageA jmp [handler+edi*4] NewFile: jmp default OpenFile: SaveFile: lea edi,[ofn] mov ecx,(sizeof.OPENFILENAME)/4 xor eax,eax rep stosd lea edi,[ofn] mov [ofn+OPENFILENAME.lStructSize],sizeof.OPENFILENAME push [hWnd] pop [edi+OPENFILENAME.hwndOwner] mov [edi+OPENFILENAME.hInstance],400000h mov [edi+OPENFILENAME.lpstrFilter],ASMFilterString mov [edi+OPENFILENAME.lpstrFile],FileName mov byte [FileName],0 mov [edi+OPENFILENAME.nMaxFile],100h;sizeof.FileName mov [edi+OPENFILENAME.Flags],OFN_FILEMUSTEXIST or OFN_HIDEREADONLY or OFN_PATHMUSTEXIST push edi cmp dword[wParam],52 jnz @f invoke GetSaveFileName jmp default @@: invoke GetOpenFileName Cut: Copy: Paste: Undo: Search: jmp default Preview: lea eax,[psd] push 750 1000 750 1000 ebx eax [hWnd] call PageSetupDialog jmp default Print: lea eax,[pd] push PD_SHOWHELP eax [hWnd] ; hWnd call PrintDialog jmp default About: invoke ShellAbout,[hWnd],wTitle,aAssemblerPureS,10003h jmp default endp ;================================================= Paint_Proc: hWin equ esp+sizeof.RECT+14h;ebp+8 hDC equ esp+sizeof.RECT+18h;ebp+0Ch caW equ esp+sizeof.RECT+8;ebp-4 caH equ caW-4 tbH equ caH-4 sbH equ tbH-4 sub esp,sizeof.RECT+10h;place in the RECT structure and variables caW, caH, tbH, sbH mov edi,esp;&Rct lea esi,[GetWindowRect] invoke GetClientRect,dword[hWin],edi push [edi+RECT.right] pop dword[caW] push [edi+RECT.bottom] pop dword[caH] push edi [hToolBar] ; hWnd call dword[esi];[GetWindowRect] mov eax,[edi+RECT.bottom] sub eax,[edi+RECT.top] mov dword[tbH], eax push edi [hStatus] ; hWnd call dword[esi];[GetWindowRect] mov eax,[edi+RECT.bottom] sub eax,[edi+RECT.top] mov [sbH], eax sub [caH], eax mov [edi+RECT.left],ebx;0 push dword[tbH] pop [edi+RECT.top] push dword[caW] pop [edi+RECT.right] push dword[caH] pop [edi+RECT.bottom] invoke DrawEdge,dword[hDC],edi,EDGE_SUNKEN,BF_RECT add esp,sizeof.RECT+10h;delete buffer retn 8 ;================================================================= PrintDialog: hWin equ esp+sizeof.PRINTDLG+6 lppd equ esp+sizeof.PRINTDLG+0Ah flags equ esp+sizeof.PRINTDLG+0Eh pd equ esp+2 ; ------------------------------------------------------------------ ; Parameters ; 1. hWin = parent handle ; 2. lppd = address of PRINTDLG to receive info ; 3. flags = additional styes from the PRINTDLG reference material ; ; EXAMPLE: invoke PrintDialog,hWin,ADDR pd,PD_SHOWHELP ; ------------------------------------------------------------------ sub esp,sizeof.PRINTDLG+2;place under PRINTDLG structure and pd mov [pd+PRINTDLG.lStructSize],sizeof.PRINTDLG push dword[hWin] pop [pd+PRINTDLG.hwndOwner] mov [pd+PRINTDLG.hDevMode], ebx mov [pd+PRINTDLG.hDevNames],ebx mov [pd+PRINTDLG.hDC],ebx mov eax, [flags] or eax, PD_PAGENUMS ; "or" default value with extra flags mov [pd+PRINTDLG.Flags], eax mov [pd+PRINTDLG.nFromPage],1 mov [pd+PRINTDLG.nToPage],1 mov [pd+PRINTDLG.nMinPage],bx;0 mov [pd+PRINTDLG.nMaxPage],65535 mov [pd+PRINTDLG.nCopies],1 mov [pd+PRINTDLG.hInstance],ebx;0 mov [pd+PRINTDLG.lCustData],ebx;0 mov [pd+PRINTDLG.lpfnPrintHook],ebx;0 mov [pd+PRINTDLG.lpfnSetupHook],ebx;0 mov [pd+PRINTDLG.lpPrintTemplateName],ebx;0 mov [pd+PRINTDLG.lpSetupTemplateName],ebx;0 mov [pd+PRINTDLG.hPrintTemplate],ebx;0 mov [pd+PRINTDLG.hSetupTemplate],ebx;0 lea eax,[pd+PRINTDLG.lStructSize] push eax call [PrintDlg] mov ecx, sizeof.PRINTDLG lea esi, [pd] mov edi, [lppd]; rep movsb add esp,sizeof.PRINTDLG+2;delete buffer retn 0Ch ; endp PrintDialog PageSetupDialog: hWin equ esp+sizeof.PAGESETUPDLG+4;ebp+8 lppsd equ esp+sizeof.PAGESETUPDLG+8;ebp+0Ch style equ esp+sizeof.PAGESETUPDLG+0Ch;ebp+10h lMargin equ esp+sizeof.PAGESETUPDLG+10h;ebp+14h tMargin equ esp+sizeof.PAGESETUPDLG+14h;ebp+18h rMargin equ esp+sizeof.PAGESETUPDLG+18h;ebp+1Ch bMargin equ esp+sizeof.PAGESETUPDLG+1Ch;ebp+20h ; Parameters. ; ~~~~~~~~~~ ; 1. hWin = Parent window handle. ; 2. lppsd = address of PAGESETUPDLG structure for return parameters ; 3. style = Default is 0, else styles from PAGESETUPDLG reference. ; 4. lMargin = 0 defaults to 500, inch = 1000 ; 4. tMargin = 0 defaults to 500, inch = 1000 ; 4. rMargin = 0 defaults to 500, inch = 1000 ; 4. bMargin = 0 defaults to 500, inch = 1000 ; EXAMPLE : invoke PageSetupDialog,hWin,ADDR psd,0,1000,750,1000,750 ;psd equ ebp-sizeof.PAGESETUPDLG sub esp,sizeof.PAGESETUPDLG lea esi,[style] lodsd;mov eax,[style] test eax,eax jnz @f or dword[style], PSD_DEFAULTMINMARGINS or PSD_MARGINS or \ PSD_INTHOUSANDTHSOFINCHES ; default styles @@: lodsd;mov eax,[lMargin] test eax,eax jnz @f mov dword[lMargin],500 @@: lodsd;mov eax, [tMargin] test eax,eax jnz @f mov dword[tMargin],500 @@: lodsd;mov eax, [rMargin] test eax,eax jnz @f mov dword[rMargin],500 @@: lodsd;mov eax, [bMargin] test eax,eax jnz @f mov dword[bMargin],500 @@: mov esi,esp;lea esi,[psd] mov [esi+PAGESETUPDLG.lStructSize],sizeof.PAGESETUPDLG push dword[hWin] pop [esi+PAGESETUPDLG.hwndOwner] mov [esi+PAGESETUPDLG.hDevMode],ebx mov [esi+PAGESETUPDLG.hDevNames],ebx mov eax, [style] mov [esi+PAGESETUPDLG.Flags],eax mov [esi+PAGESETUPDLG.ptPaperSize.x],ebx mov [esi+PAGESETUPDLG.ptPaperSize.y],ebx mov [esi+PAGESETUPDLG.rtMinMargin.left],ebx mov [esi+PAGESETUPDLG.rtMinMargin.top],ebx mov [esi+PAGESETUPDLG.rtMinMargin.right],ebx mov [esi+PAGESETUPDLG.rtMinMargin.bottom],ebx push dword[lMargin] pop [esi+PAGESETUPDLG.rtMargin.left] push dword[tMargin] pop [esi+PAGESETUPDLG.rtMargin.top] push dword[rMargin] pop [esi+PAGESETUPDLG.rtMargin.right] push dword[bMargin] pop [esi+PAGESETUPDLG.rtMargin.bottom] mov [esi+PAGESETUPDLG.hInstance],ebx mov [esi+PAGESETUPDLG.lCustData],ebx mov [esi+PAGESETUPDLG.lpfnPageSetupHook],ebx mov [esi+PAGESETUPDLG.lpfnPagePaintHook],ebx mov [esi+PAGESETUPDLG.lpPageSetupTemplateName],ebx mov [esi+PAGESETUPDLG.hPageSetupTemplate],ebx push esi call [PageSetupDlg] mov ecx,sizeof.PAGESETUPDLG mov edi,[lppsd] rep movsb add esp,sizeof.PAGESETUPDLG;delete buffer retn 1Ch ;=============================================================== wTitle db 'Iczelion Tutorial #8-12: toolbar in FASM',0 aYouHaveSelecte db 'You have selected',0 aNewFile db 'New File',0 aOpenFile db 'Open File',0 aSaveFile db 'Save File',0 aCut db 'Cut',0 aCopy db 'Copy',0 aPaste db 'Paste',0 aUndo db 'Undo',0 aSearch db 'Search',0 aProperties db 'Properties',0 aPrint db 'Print',0 aAbout db ' ?@>3@0<<5',0 aAssemblerPureS db 'Assembler, Pure & Simple',0 aPleaseConfirmE db 'Please Confirm Exit',0 hStatus dd 0 hToolBar dd 0 handlers dd aNewFile,aOpenFile,aSaveFile,aCut,aCopy,aPaste,aUndo,aSearch,aProperties,aPrint,0,aAbout handler dd NewFile, OpenFile, SaveFile, Cut, Copy, Paste, Undo, Search, Preview, Print, wmDESTROY, About ASMFilterString db "ASM Source code (*.asm)",0,"*.asm",0 db "All Files (*.*)",0,"*.*",0,0 FileName rb 256 ;----------------------------------------------------------- data import library KERNEL32, 'KERNEL32.DLL',\ user32, 'USER32.DLL',\ comctl32, 'comctl32.dll',\ shell32, 'shell32.dll',\ ole32, 'ole32.dll',\ comdlg32, 'comdlg32.dll' import KERNEL32,\ ExitProcess, 'ExitProcess' import user32,\ RegisterClassEx, 'RegisterClassExA',\ CreateWindowEx, 'CreateWindowExA',\ DispatchMessage, 'DispatchMessageA',\ DefWindowProc, 'DefWindowProcA',\ BeginPaint, 'BeginPaint',\ EndPaint, 'EndPaint',\ GetMessage, 'GetMessageA',\ SendMessage, 'SendMessageA',\ GetWindowRect, 'GetWindowRect',\ MoveWindow, 'MoveWindow',\ GetClientRect, 'GetClientRect',\ DrawEdge, 'DrawEdge',\ ShowWindow, 'ShowWindow',\ UpdateWindow, 'UpdateWindow',\ MessageBox, 'MessageBoxA' import comdlg32,\ GetSaveFileName, 'GetSaveFileNameA',\ GetOpenFileName, 'GetOpenFileNameA',\ PrintDlg, 'PrintDlgA',\ PageSetupDlg, 'PageSetupDlgA',\ ChooseColor, 'ChooseColorA',\ ChooseFont, 'ChooseFontA' import comctl32,\ InitCommonControls, 'InitCommonControls',\ CreateToolbarEx, 'CreateToolbarEx',\ CreateStatusWindow, 'CreateStatusWindowA' import shell32,\ ShellAbout, 'ShellAboutA',\ SHBrowseForFolder, 'SHBrowseForFolderA',\ SHGetPathFromDList, 'SHGetPathFromDListA' import ole32,\ CoTaskMemFree, 'CoTaskMemFree' end data ;-------------------------------------------------------------- align 4 data resource directory RT_MENU,menus IDM_MENU = 600 ID_EXIT = 60 ID_ABOUT = 61 resource menus,\ IDM_MENU,LANG_ENGLISH+SUBLANG_DEFAULT,main_menu menu main_menu menuitem '&File',0,MFR_POPUP menuitem '&Exit',ID_EXIT,MFR_END menuitem '&Help',0,MFR_POPUP + MFR_END menuitem '&About',ID_ABOUT,MFR_END end data
|
|||||||||||
13 Feb 2015, 08:44 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.