#include #grid.asm #an example of creating a generic grid control using EP. a window class # 'The grid' (for want of a better name) is registered in winmain. #the event handler (window procedure) is (you wouldn't guess) is # GridProc (surprised!). here memory is allocated in the wm_create event #to keep the state info of each grid created so that events can be #routed to the appropriate one #AddToGrid1 and AddToGrid2 add items to the respective grid. #these may be ok for an example but a real life app will require better #ways of doing this #this example also doesn't do much error checking which a real app will need #Please drop me an email for any clarifications,suggestions,comments begin imports [Kernel32.dll] GetModuleHandleA GetCommandLineA LoadLibraryA ExitProcess GlobalAlloc GlobalSize GlobalFree GlobalReAlloc Sleep CreateFileA ReadFile WriteFile CloseHandle GetFileSize CreateThread CreateProcessA SuspendThread ResumeThread ExitThread TerminateThread [user32.dll] SetCaretPos SetScrollInfo FillRect GetDC 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 [gdi32.dll] LineTo MoveToEx ExtFloodFill FloodFill CreateCompatibleBitmap BitBlt CreateCompatibleDC TextOutA 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 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 ES_MULTILINE 4 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 WS_SYSMENU 524288 LB_ADDSTRING 384 LB_RESETCONTENT 388 LBS_HASSTRINGS 64 LB_SELECTSTRING 396 LB_SETTOPINDEX 407 DT_SINGLELINE 32 DT_CENTER 1 DT_VCENTER 4 DT_BOTTOM 8 IDI_APPLICATION 32512 IDC_CROSS 32515 GMEM_ZEROINIT 64 ES_AUTOVSCROLL 64 ES_AUTOHSCROLL 128 EN_MSGFILTER 1792 EM_SETEVENTMASK 1093 EN_CHANGE 768 ENM_MOUSEEVENTS 131072 ENM_SELCHANGE 524288 ENM_PROTECTED 2097152 ENM_KEYEVENTS 65536 ENM_UPDATE 2 ENM_SCROLL 4 ENM_CHANGE 1 ES_NOHIDESEL 256 EM_GETFIRSTVISIBLELINE 206 EM_FINDTEXTEX 1103 EM_LINEFROMCHAR 201 EM_LINESCROLL 182 EM_SETLIMITTEXT 197 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 EM_STREAMIN 1097 EM_STREAMOUT 1098 ES_WANTRETURN 4096 ES_LEFT 0 SF_RTF 2 SFF_SELECTION 32768 SFF_PLAINRTF 16384 SF_TEXT 1 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 CBN_DROPDOWN 7 CBS_DROPDOWN 2 CBS_DROPDOWNLIST 3 CBS_HASSTRINGS 512 CBN_SELENDOK 9 CBN_SELCHANGE 1 CBS_SIMPLE 1 CBN_CLOSEUP 8 CB_FINDSTRINGEXACT 344 CBS_SORT 256 OFN_EXPLORER 524288 OFN_HIDEREADONLY 4 OFN_LONGNAMES 2097152 OFN_PATHMUSTEXIST 2048 MB_ICONASTERISK 64 IDC_ARROW 32512 SRCCOPY 13369376 WM_VSCROLL 277 WM_HSCROLL 276 SIF_RANGE 1 SIF_POS 4 SB_LINEUP 0 SB_LINEDOWN 1 SB_LINELEFT 0 SB_LINERIGHT 1 SB_PAGEUP 2 SB_PAGEDOWN 3 SB_PAGELEFT 2 SB_PAGERIGHT 3 GR_INIT 1025 GR_ADDITEM 1026 GR_REMOVEITEM 1027 GR_COLARRAY 1028 GR_DATARRAY 1029 GR_REFRESH 1030 GR_RESET 1031 GR_GETITEM 1032 WS_CLIENTEDGE 512 WS_MINIMIZEBOX 131072 end const #-----------------Data Section------------------------------------------- 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 colon : dword quit 0 dword sno 0 dword sno2 0 string thisis This is string the the string aditem AddItem string method method 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 dword DataType 0 string read r string write w string readb rb string writeb wb string WindowCaption Basic Windows Template ! string ab About ... string ab1 MyApp Version 1.0 string ab2 by .... string ab3 This message is also sent to the owner of a horizontal scroll bar control when a scroll event occurs in the control. 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 pmenu &Help string about &About ... sequence buffer 256 #sequence buf 48 sequence ibuf 24 sequence listbuf 48 sequence icobuf 24 sequence pt 8 sequence ofnfname 256 sequence astart 208 sequence begin 8 dword hbtn1 0 dword hbtn2 0 sequence blank 1 dword CommandLine 0 dword hmem 0 sequence wndclass 16 sequence msg 28 sequence asci 16 dword mem 0 string word1 Empowered string word2 programming string word3 in string word4 Windows dword htex1 0 dword htex2 0 dword htex3 0 dword htex4 0 string enter <- AddItem string Windowtitle The Grid Control Demo string pip | string til ~ dword ed 0 string GridClass The grid sequence gTable 8 string colwidths 30 150 150 150 150 150 string colwidths1 30 100 100 100 100 100 dword rowheight 18 #sequence col 8 #dword start 0 dword hwndGrid1 0 dword gridData 0 dword dataend 4294967295 dword grid1 0 dword grid2 0 end data #------------------------------------------------------------------- begin code proc loword dword n push ebp mov ebp esp eax=n and eax 65535 leave ret 4 endp #------------------------------------------------------------------------ proc strlen dword q push ebp mov ebp esp mov edi [q] mov eax 0 mov ecx 0 cld search_loop: inc ecx scasb jne search_loop dec ecx mov eax ecx leave ret 4 endp #------------------------------------------------------------------------ proc strcat dword s1 dword s2 dword len1 0 dword len2 0 dword addr 0 dword len 0 push ebp mov ebp esp add esp -48 invoke strlen [s1] mov [len1] eax invoke strlen [s2] mov [len2] eax add eax [len1] inc eax len = eax invoke [malloc] eax invoke memset eax 0 len mov [addr] eax mov edi eax mov ecx [len1] mov esi [s1] rep_movsb mov ecx [len2] mov esi [s2] rep_movsb mov eax [addr] leave ret 8 endp #------------------------------------------------------------------------ proc left dword s dword n dword slen 0 push ebp mov ebp esp add esp -16 cld eax = n inc eax slen = eax invoke malloc eax edi = eax invoke memset eax 0 slen esi = s ecx = n rep_movsb leave ret 8 endp #------------------------------------------------------------------------ proc right dword s dword n dword slen 0 dword addr 0 push ebp mov ebp esp add esp -16 eax = n inc eax slen = eax invoke [malloc] eax invoke [memset] eax 0 slen add eax n [ed] = eax invoke strlen s edi = [ed] ebx = s add ebx eax esi = ebx ecx = n inc ecx std rep_movsb inc edi eax = edi cld leave ret 8 endp #------------------------------------------------------------------------ proc ltrim dword s dword len 0 push ebp mov ebp esp add esp -4 invoke strlen [s] mov [len] eax mov edi [s] mov eax 32 mov ecx 0 cld lspace_loop: inc ecx scasb je lspace_loop dec ecx mov eax [len] sub eax ecx invoke right [s] eax leave ret 4 endp #------------------------------------------------------------------------ proc rtrim dword s dword len 0 push ebp mov ebp esp add esp -4 invoke strlen [s] mov [len] eax add eax [s] mov edi eax dec edi mov eax 32 mov ecx 0 std rspace_loop: inc ecx scasb je rspace_loop dec ecx mov eax [len] sub eax ecx invoke left [s] eax leave ret 4 endp #------------------------------------------------------------------------ proc trim dword s dword temp1 0 dword temp2 0 push ebp mov ebp esp add esp -8 invoke rtrim [s] mov [temp1] eax invoke ltrim eax mov [temp2] eax invoke [free] [temp1] mov eax [temp2] leave ret 4 endp #------------------------------------------------------------------------ proc strcmp dword s1 dword s2 dword temp1 0 push ebp mov ebp esp add esp -4 invoke strlen [s1] mov [temp1] eax invoke strlen [s2] cmp eax [temp1] jne strcmp_ne mov edi [s1] mov esi [s2] repe_cmpsb je strcmp_e strcmp_ne: mov eax 1 jmp strcmp_exit strcmp_e: mov eax 0 strcmp_exit: leave ret 8 endp #------------------------------------------------------------------------ proc addmem dword addr dword addition dword n 0 dword length 0 push ebp mov ebp esp add esp -48 eax =[addr] add eax 4 ebx = [eax] add ebx [addition] [length] = ebx eax =[addr] invoke [realloc] [eax] [length] ecx =[addr] [ecx] = eax ebx = [length] add ecx 4 [ecx] =ebx ebx = [length] sub ebx [addition] ecx =[addr] edx =[ecx] add edx ebx invoke [memset] edx 0 [addition] leave ret 8 endp #------------------------------------------------------------------------ proc writemem dword addr dword disp dword vartype dword val push ebp mov ebp esp add esp -48 eax = [addr] add eax [disp] if [vartype] = 1 ebx = [val] [eax] = ebx endif if [vartype] = 2 ebx = [val] invoke [strcpy] eax ebx endif #write byte if [vartype] = 3 ebx = [val] [eax] = bl endif eax = [addr] leave ret 16 endp #------------------------------------------------------------------------ proc readmem dword addr dword disp dword typ push ebp mov ebp esp add esp -48 ebx = [addr] add ebx [disp] if typ = 0 eax = [ebx] endif if typ = 1 eax=0 al=[ebx] endif leave ret 12 endp #------------------------------------------------------------------------ proc getlength dword addr push ebp mov ebp esp ebx = [addr] add ebx 4 eax = [ebx] leave ret 4 endp #------------------------------------------------------------------------ proc clearlength dword addr push ebp mov ebp esp eax=addr [eax]=0 add eax 4 [eax]=0 leave ret 4 endp #------------------------------------------------------------------------ proc GetDelim dword st dword delim dword slen 0 dword n 0 push ebp mov ebp esp add esp -16 invoke strlen [st] mov [slen] eax mov ecx eax mov eax delim mov edi [st] cld repne_scasb mov eax [slen] sub eax ecx n=ecx if n <> 0 dec eax endif leave ret 8 endp #------------------------------------------------------------------------ proc GetText dword hwnd dword buf dword n 0 push ebp mov ebp esp add esp -12 n=SendMessageA hwnd {WM_GETTEXTLENGTH} 0 0 inc n invoke SendMessageA hwnd {WM_GETTEXT} n buf eax=n leave ret 8 endp #------------------------------------------------------------------------ proc GridPaint dword hwnd dword n 0 sequence rect 16 sequence pt 8 dword m 0 dword p 0 dword c 0 dword len 0 dword x 0 dword y 0 dword hMemdc 0 dword hdc 0 dword colws 0 dword hpos 0 dword xpos 0 dword colarray 0 dword datastart 0 dword addr 0 dword count 0 dword start 0 dword buf 0 dword col 0 push ebp mov ebp esp add esp -180 buf=malloc 48 col=malloc 8 m=getlength gTable ebx=0 n=0 while ebx < m eax=[gTable] add eax n edx=[eax] if edx=hwnd add eax 4 edx=[eax] hdc=edx add eax 4 edx=[eax] hMemdc=edx add eax 4 edx=[eax] colws=edx add eax 4 edx=[eax] colarray=edx add eax 4 edx=[eax] hpos=edx add eax 4 add eax 4 edx=[eax] start=edx add eax 4 edx=[eax] datastart=edx jmp gloop_out endif add n 96 ebx=n endw gloop_out: [rect]=0 [rect+4]=0 [rect+8]=780 [rect+12]=1216 lea eax rect invoke FillRect hMemdc eax 10 m=1216 ebx=0 n=0 while ebx< m #draw horizontal lines lea eax pt invoke MoveToEx hMemdc 0 n eax invoke LineTo hMemdc 780 n eax=rowheight add n eax ebx=n endw m=strlen colws #vertical lines ebx=0 n=0 #asci byte write position c=0 #counter p=0 #col position invoke memset col 0 8 while ebx< m edi=colws add edi c eax=0 al=[edi] if eax=32 #space is the delimiter eax=atoi col add p eax lea eax pt invoke MoveToEx hMemdc p 0 eax invoke LineTo hMemdc p 1216 n=0 #reset invoke memset col 0 8 jmp pg_loop endif invoke writemem col n 3 eax #if not space write byte to position n ln col inc n pg_loop: inc c ebx=c endw eax=atoi col add p eax lea eax pt invoke MoveToEx hMemdc p 0 eax invoke LineTo hMemdc p 300 if datastart=0 jmp gout endif m=1216 ebx=0 n=0 x=0 y=2 count=0 gpbegin: eax=datastart ebx=start if count >= ebx count=0 jmp gstart endif add eax 4 if [eax]=0 jmp gstart endif eax=[eax] datastart=eax inc count jmp gpbegin gstart: ebx=[eax] addr=ebx m=strlen addr invoke memset buf 0 48 ebx=0 n=0 c=0 xpos=0 while ebx < m edi=addr add edi c eax=0 al=[edi] if eax=124 #pipe | character ebx=colarray add ebx xpos eax=[ebx] add x eax add x 2 len=strlen buf invoke TextOutA hMemdc x y buf len invoke memset buf 0 48 n=0 add xpos 4 jmp settexnext endif invoke writemem buf n 3 eax inc n settexnext: inc c ebx=c endw ebx=colarray add ebx xpos eax=[ebx] add x eax add x 2 len=strlen buf invoke TextOutA hMemdc x y buf len add y 18 x=0 inc count eax=datastart add eax 4 if [eax]=0 jmp gout endif eax=[eax] datastart=eax if count > 10 jmp gout endif jmp gstart gout: invoke BitBlt hdc 0 0 500 300 hMemdc hpos 0 {SRCCOPY} invoke free buf invoke free col leave ret 4 endp #------------------------------------------------------------------------ proc AddToGrid1 dword hwnd dword n 0 dword m 0 dword addr 0 dword st 0 push ebp mov ebp esp add esp -48 invoke _itoa sno ibuf 10 st=strcat ibuf pip invoke memset buffer 0 256 invoke SendMessageA htex1 {WM_GETTEXT} 256 buffer st=strcat st buffer st=strcat st pip invoke memset buffer 0 256 invoke SendMessageA htex2 {WM_GETTEXT} 256 buffer st=strcat st buffer st=strcat st pip invoke memset buffer 0 256 invoke SendMessageA htex3 {WM_GETTEXT} 256 buffer st=strcat st buffer st=strcat st pip invoke memset buffer 0 256 invoke SendMessageA htex4 {WM_GETTEXT} 256 buffer st=strcat st buffer invoke SendMessageA hwnd {GR_ADDITEM} 0 st invoke GridPaint hwnd leave ret 4 endp #------------------------------------------------------------------------ proc AddToGrid2 dword hwnd dword n 0 dword m 0 dword addr 0 dword st 0 push ebp mov ebp esp add esp -48 invoke _itoa sno2 ibuf 10 st=strcat ibuf pip invoke memset buffer 0 256 invoke SendMessageA htex1 {WM_GETTEXT} 256 buffer st=strcat st buffer st=strcat st pip invoke memset buffer 0 256 invoke SendMessageA htex2 {WM_GETTEXT} 256 buffer st=strcat st buffer st=strcat st pip invoke memset buffer 0 256 invoke SendMessageA htex3 {WM_GETTEXT} 256 buffer st=strcat st buffer st=strcat st pip invoke memset buffer 0 256 invoke SendMessageA htex4 {WM_GETTEXT} 256 buffer st=strcat st buffer invoke SendMessageA hwnd {GR_ADDITEM} 0 st invoke GridPaint hwnd leave ret 4 endp #------------------------------------------------------------------------ proc GridAddItem dword hwnd dword str dword n 0 dword datstart 0 dword m 0 dword p 0 dword addr 0 dword linkaddr 0 dword posd 0 dword postotrows 0 dword totrows 0 push ebp mov ebp esp add esp -48 m=getlength gTable ebx=0 n=0 while ebx < m eax=[gTable] add eax n edx=[eax] if edx=hwnd add eax 32 edx=[eax] datstart=edx posd=eax add eax 36 edx=[eax] totrows=edx postotrows=eax jmp gad_out endif add n 96 ebx=n endw gad_out: m=strlen str inc m addr=malloc m invoke memset addr 0 m dec m invoke memcpy addr str m linkaddr=malloc 8 invoke memset linkaddr 0 8 invoke writemem linkaddr 0 1 addr if datstart = 0 eax=posd ebx=linkaddr [eax]=ebx jmp gad_exit endif m=1 while m <> 0 eax=datstart add eax 4 ebx=[eax] if ebx=0 ebx=linkaddr [eax]=ebx m=0 jmp gad_exit endif if ebx <> 0 datstart=ebx endif endw gad_exit: inc totrows eax = postotrows ebx=totrows [eax]=ebx leave ret 8 endp #------------------------------------------------------------------------ proc GridSetColWidth dword hwnd dword lparam dword n 0 dword c 0 dword p 0 dword m 0 dword addr 0 dword sp 0 dword col 0 push ebp mov ebp esp add esp -48 col=malloc 8 m=getlength gTable ebx=0 n=0 while ebx < m eax=[gTable] add eax n edx=[eax] if edx=hwnd add eax 12 edx=lparam [eax]=edx jmp gsw1 endif add n 96 ebx=n endw gsw1: m=strlen lparam #vertical lines ebx=0 n=0 #asci byte write position c=0 #counter p=0 #col position invoke memset col 0 8 sp=2 addr=malloc 4 invoke memset addr 0 4 ebx=0 eax=addr [eax]=ebx while ebx < m edi=lparam add edi c eax=0 al=[edi] if eax=32 #space is the delimiter n=atoi col eax=sp ecx=4 mul ecx p=eax addr=realloc addr eax sub p 4 eax=addr add eax p ebx=n [eax]=ebx inc sp n=0 #reset invoke memset col 0 8 jmp gsw_loop endif invoke writemem col n 3 eax #if not space write byte to position n ln col inc n gsw_loop: inc c ebx=c endw n=atoi col eax=sp ecx=4 mul ecx p=eax addr=realloc addr eax sub p 4 eax=addr add eax p ebx=n [eax]=ebx m=getlength gTable ebx=0 n=0 while ebx < m eax=[gTable] add eax n edx=[eax] if edx=hwnd add eax 16 edx=addr [eax]=edx jmp gsw2 endif add n 96 ebx=n endw gsw2: invoke free col leave ret 8 endp #------------------------------------------------------------------------ proc GridVscroll dword hwnd dword wparam dword n 0 dword m 0 dword addr 0 sequence vinfo 28 dword vpos 0 dword posv 0 dword postart 0 dword start 0 dword totrows 0 push ebp mov ebp esp add esp -96 m=getlength gTable ebx=0 n=0 while ebx < m eax=[gTable] add eax n edx=[eax] if edx=hwnd add eax 24 edx=[eax] vpos=edx posv=eax add eax 4 edx=[eax] start=edx postart=eax add eax 40 edx=[eax] totrows=edx jmp gpvs_out endif add n 96 ebx=n endw gpvs_out: invoke loword wparam if eax={SB_LINEUP} sub vpos 18 if vpos < 0 vpos=0 endif dec start if start < 0 start=0 endif endif if eax={SB_LINEDOWN} add vpos 18 eax= totrows ecx=18 mul ecx sub eax 162 if vpos > eax vpos=eax endif inc start eax=totrows sub eax 16 if start > eax start=eax endif endif if eax={SB_PAGEUP} sub vpos 54 if vpos < 0 vpos=0 endif sub start 3 if start < 0 start=0 endif endif if eax={SB_PAGEDOWN} add vpos 54 eax=totrows ecx=18 mul ecx sub eax 162 if vpos > eax vpos=eax endif add start 3 eax=totrows sub eax 16 if start > eax start=eax endif endif eax = posv ebx=vpos [eax]=ebx eax = postart ebx=start [eax]=ebx [vinfo]=28 mov eax {SIF_RANGE} or eax {SIF_POS} [vinfo+4]=eax [vinfo+8]=0 eax=totrows ecx=18 mul ecx sub eax 162 [vinfo+12]=eax eax = vpos [vinfo+20]=eax lea eax vinfo invoke SetScrollInfo hwnd 1 eax 1 invoke GridPaint hwnd leave ret 8 endp #------------------------------------------------------------------------ proc GridHscroll dword hwnd dword wparam dword n 0 dword m 0 sequence hinfo 28 dword hpos 0 dword posh 0 push ebp mov ebp esp add esp -48 m=getlength gTable ebx=0 n=0 while ebx < m eax=[gTable] add eax n edx=[eax] if edx=hwnd add eax 20 edx=[eax] hpos=edx posh=eax jmp gphs_out endif add n 96 ebx=n endw gphs_out: invoke loword wparam if eax={SB_LINELEFT} sub hpos 10 if hpos < 0 hpos=0 endif endif if eax={SB_LINERIGHT} add hpos 10 if hpos > 500 hpos=500 endif endif if eax={SB_PAGELEFT} sub hpos 20 if hpos < 0 hpos=0 endif endif if eax={SB_PAGERIGHT} add hpos 20 if hpos > 500 hpos=500 endif endif eax = posh ebx=hpos [eax]=ebx [hinfo]=28 mov eax {SIF_RANGE} or eax {SIF_POS} [hinfo+4]=eax [hinfo+8]=0 [hinfo+12]=500 eax = hpos [hinfo+20]=eax lea eax hinfo invoke SetScrollInfo hwnd 0 eax 1 invoke GridPaint hwnd leave ret 8 endp #------------------------------------------------------------------------ proc GridInit dword hwnd dword n 0 dword hwndGrid 0 dword gridDC 0 dword gridMemDC 0 dword hbmp 0 dword addr 0 push ebp mov ebp esp add esp -48 addr = addmem gTable 96 invoke writemem addr 0 1 hwnd gridDC=GetDC hwnd invoke writemem addr 4 1 gridDC gridMemDC=CreateCompatibleDC gridDC invoke writemem addr 8 1 gridMemDC hbmp=CreateCompatibleBitmap gridDC 780 1216 invoke SelectObject gridMemDC hbmp invoke SelectObject gridMemDC hfont1 invoke SetTextColor gridMemDC 8455444 leave ret 4 endp #------------------------------------------------------------------------ proc GridProc dword hwnd dword msg dword wparam dword lparam dword fn 0 dword hdc 0 dword hbr 0 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 gridcreate cmp [msg] {WM_PAINT} je gridpaint cmp [msg] {WM_COMMAND} je gridcommand cmp [msg] {WM_HSCROLL} je gridhscroll cmp [msg] {WM_VSCROLL} je gridvscroll cmp [msg] {GR_COLARRAY} je gridcolarray cmp [msg] {GR_ADDITEM} je gridadditem jmp griddefault gridcreate: invoke GridInit hwnd jmp gridexit gridcolarray: invoke GridSetColWidth hwnd lparam jmp gridexit gridpaint: lea eax ps invoke BeginPaint hwnd eax mov hdc eax invoke GridPaint hwnd lea eax ps invoke EndPaint hwnd eax jmp gridexit gridcommand: jmp gridexit gridhscroll: invoke GridHscroll hwnd wparam jmp gridexit gridvscroll: invoke GridVscroll hwnd wparam jmp gridexit gridadditem: invoke GridAddItem hwnd lparam jmp gridexit griddefault: invoke DefWindowProcA hwnd msg wparam lparam leave ret 16 gridexit: xor eax eax leave ret 16 endp #------------------------------------------------------------------------ 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 sequence hinfo 28 dword hwndGrid 0 dword n 0 dword m 0 dword x 0 dword y 0 push ebp mov ebp esp add esp -180 n = 0 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_BORDER} or eax {WS_VISIBLE} ordata= eax invoke CreateWindowExA 0 btn enter ordata 520 120 100 25 hwnd 0 hInstance 0 mov hbtn1 eax invoke SendMessageA hbtn1 {WM_SETFONT} hfont1 0 invoke CreateWindowExA 0 btn enter ordata 520 300 100 25 hwnd 0 hInstance 0 mov hbtn2 eax invoke SendMessageA hbtn2 {WM_SETFONT} hfont1 0 mov eax {WS_CHILD} or eax {WS_BORDER} or eax {WS_VISIBLE} ordata= eax invoke CreateWindowExA 0 text thisis ordata 10 20 100 20 hwnd 0 hInstance 0 mov htex1 eax invoke SendMessageA htex1 {WM_SETFONT} hfont1 0 invoke CreateWindowExA 0 text the ordata 120 20 100 20 hwnd 0 hInstance 0 mov htex2 eax invoke SendMessageA htex2 {WM_SETFONT} hfont1 0 invoke CreateWindowExA 0 text aditem ordata 230 20 100 20 hwnd 0 hInstance 0 mov htex3 eax invoke SendMessageA htex3 {WM_SETFONT} hfont1 0 invoke CreateWindowExA 0 text method ordata 340 20 100 20 hwnd 0 hInstance 0 mov htex4 eax invoke SendMessageA htex4 {WM_SETFONT} hfont1 0 mov eax {WS_BORDER} or eax {WS_CHILD} or eax {WS_VSCROLL} or eax {WS_HSCROLL} or eax {WS_VISIBLE} ordata= eax invoke CreateWindowExA 0 GridClass blank ordata 10 60 500 162 hwnd 0 hInstance 0 grid1=eax invoke SendMessageA eax {GR_COLARRAY} 0 colwidths invoke CreateWindowExA 0 GridClass blank ordata 10 240 500 162 hwnd 0 hInstance 0 grid2=eax invoke SendMessageA eax {GR_COLARRAY} 0 colwidths1 sno=1 sno2=1 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 btn1: mov eax hbtn1 cmp lparam eax jne btn2 invoke AddToGrid1 grid1 inc sno jmp exit btn2: mov eax hbtn2 cmp lparam eax jne default invoke AddToGrid2 grid2 inc sno2 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 [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 104 exit 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]= GridProc [wc+12]= 0 [wc+16] =0 eax =[hInstance] [wc+20]= eax push 17 push [hInstance] call [LoadIconA] [wc+24]= eax [wc+44]= eax push {IDC_ARROW} push 0 call [LoadCursorA] [wc+28] =eax [wc+32]= 6 [wc+36]= 0 [wc+40]= GridClass lea eax [wc] invoke [RegisterClassExA] eax #the grid class should be registered first because we want to create it #in the wm_create of the main window. So windows should know it beforehand [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 eax={WS_VISIBLE} or eax {WS_CAPTION} or eax {WS_SYSMENU} or eax {WS_MINIMIZEBOX} ordata=eax invoke CreateWindowExA {WS_CLIENTEDGE} ClassName Windowtitle ordata 50 50 640 480 0 0 hInstance 0 hwndMain= eax 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 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