;-ini.asm v0.3--------------------------------------------------------------- ; x86 - Dos & Win32 - Assembly Language Programming ; ; ; ; Written by: John A Lyons ; ; Email : sysop@megablast.8k.com ; ; Page : http://www.asmsource.8k.com/ ; ; Compiler : Masm32 v6.13 Microsoft Macro Assembler ; ; Date : 19-Jul-2001 ; ; Purpose : Demonstrates how to use a .ini file, to access data that can ; ; be easily updated. This is an advantage over the registry, ; ; since the registry is incredibly slow. ; ; ; ; v0.1 : Setup window format, loads in .ini file, and displays first ; ; one. ; ; v0.2 : Add ability to move to next record. Also changed menu system ; ; to properly reflect the theme of the program. (19-jul-2001) ; ; v0.3 : Added record number, and index number. (20-jul-2001) ; ; ; ; ; ;---------------------------------------------------------------------------- .386 .MODEL FLAT , STDCALL option casemap:none include windows.inc include user32.inc include kernel32.inc include shell32.inc include gdi32.inc includelib user32.lib includelib kernel32.lib includelib shell32.lib includelib gdi32.lib include wsock32.inc includelib wsock32.lib ; external procedure EXTRN wsprintfA:PROC ; procedures declared later WinMain proto :DWORD,:DWORD,:DWORD,:DWORD AboutDlgProc proto hWnd:HWND,iMsg:DWORD,wParam:WPARAM, lParam:LPARAM iniscan proto hWnd:HWND openini proto hWnd:HWND .data ClassName db "DLGCLASS",0 MenuName db "MyMenu",0 DlgName db "MainDialog",0 AppName db "IP Number",0 AbtName db "AboutDialog",0 num1 db "%%" num2 db "%lu",0 hInstance HINSTANCE ? CommandLine LPSTR ? mem1 db "Load %" buff db 256 dup(?) menuhand DWORD ? first BOOL FALSE ;about data hwnd HWND ? hover BOOL ? hFinger dd ? orgStatic dd ? hwndDlg dd ? szOpen db "open",0 ;ini info filehand1 dword ? memhand dword ? filesize dword ? mem dword ? sizeread dword ? temp DWORD ? memdata dword ? parts dword ? memmax dword ? index dword ? .const ;buttons IDC_NEXT equ 3000 IDC_PREV equ 3001 IDC_EXIT equ 3002 ;menu IDM_UPDATE equ 32000 IDM_EXIT equ 32003 IDM_ABOUT equ 32002 ;dialog IDI_ICON1 equ 5 IDC_URL equ 9 IDI_CUR1 equ 101 ;ini info ininame db "test.ini",0 inidata db "acco" db "smtp" db "pop3" db "name" db "pass" ;inidata2 dword 502,504,505,507,508,509 .code start: invoke GetModuleHandle, NULL mov hInstance,eax invoke GetCommandLine invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT invoke ExitProcess,eax WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD LOCAL wc:WNDCLASSEX LOCAL msg:MSG LOCAL hDlg:HWND mov wc.cbSize,SIZEOF WNDCLASSEX mov wc.style, CS_HREDRAW or CS_VREDRAW mov wc.lpfnWndProc, OFFSET WndProc mov wc.cbClsExtra,NULL mov wc.cbWndExtra,DLGWINDOWEXTRA push hInst pop wc.hInstance mov wc.hbrBackground,COLOR_BTNFACE+1 mov wc.lpszMenuName,OFFSET MenuName mov wc.lpszClassName,OFFSET ClassName invoke LoadIcon, hInstance, IDI_ICON1 mov wc.hIcon,eax mov wc.hIconSm,eax invoke LoadCursor,NULL,IDC_ARROW mov wc.hCursor,eax invoke RegisterClassEx, addr wc invoke CreateDialogParam,hInstance,ADDR DlgName,NULL,NULL,NULL mov hDlg,eax INVOKE ShowWindow, hDlg,SW_SHOWNORMAL INVOKE UpdateWindow, hDlg .WHILE TRUE INVOKE GetMessage, ADDR msg,NULL,0,0 .BREAK .IF (!eax) invoke IsDialogMessage, hDlg, ADDR msg .if eax==FALSE INVOKE TranslateMessage, ADDR msg INVOKE DispatchMessage, ADDR msg .endif .ENDW mov eax,msg.wParam ret WinMain endp WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM mov eax,uMsg .if ax==WM_GETMINMAXINFO ; 24 cmp first,FALSE jne nob1 invoke GetMenu,hWnd mov menuhand,eax invoke DefWindowProc,hWnd,uMsg,wParam,lParam invoke openini,hWnd mov eax,mem mov memdata,eax mov index,1 ret .ELSEIF ax==WM_INITDIALOG ;call openini ;mov eax,mem ;mov memdata,eax ;push eax ;push offset num1 ;push offset buff ;call wsprintfA ; ;invoke SendDlgItemMessage, hWnd, 506, WM_SETTEXT, 0,ADDR buff .ELSEIF ax==WM_ACTIVATE cmp mem,0 jne okok2 mov eax,mem mov memdata,eax invoke openini,hWnd okok2: invoke iniscan,hWnd mov eax,parts push eax push offset num2 push offset buff call wsprintfA invoke SendDlgItemMessage, hWnd, 506, WM_SETTEXT, 0,ADDR buff ret .ELSEIF ax==WM_DESTROY invoke GlobalFree,memhand invoke PostQuitMessage,NULL ret .ELSEIF ax==WM_COMMAND mov eax,wParam .IF lParam==0 .IF ax==IDM_EXIT invoke DestroyWindow,hWnd ret .ELSEIF ax==IDC_NEXT jmp gonext .ELSEIF ax==IDC_PREV jmp goprev .ELSEIF ax==IDM_ABOUT invoke CreateDialogParam,hInstance, addr AbtName,hWnd,OFFSET AboutDlgProc,NULL mov hwndDlg,eax .ENDIF .ELSE .IF ax==IDC_EXIT invoke SendMessage,hWnd,WM_COMMAND,IDM_EXIT,0 ret .ELSEIF ax==IDC_NEXT gonext: mov ebx,index cmp ebx,parts jae toobig mov esi,memdata add esi,4 cmp esi,memmax jae toobig gosi: inc esi cmp esi,memmax je toobig cmp [esi],word ptr 0d0ah jne gosi add esi,3 mov memdata,esi inc index invoke iniscan,hWnd toobig: .ELSEIF ax==IDC_PREV goprev: mov ebx,index or ebx,ebx jz nodec mov esi,memdata cmp esi,mem je nodec sub esi,4 gosi2: dec esi cmp esi,mem je foundtop cmp [esi],word ptr 0d0ah jne gosi2 add esi,3 foundtop: mov memdata,esi dec index invoke iniscan,hWnd nodec: .ENDIF .ENDIF .ELSE invoke DefWindowProc,hWnd,uMsg,wParam,lParam ret .ENDIF nob1: xor eax,eax ret WndProc endp ;----------------------------------------------------ABOUT procedure HyperLinkWndProc PROC uses ebx, hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD LOCAL tmpFont :LOGFONT LOCAL rect:RECT LOCAL pt:POINT LOCAL ps:PAINTSTRUCT mov eax,uMsg .IF eax==WM_NCHITTEST mov eax, 1 ;We want to handle the non client hit test so we return true or 1 ret .ELSEIF eax == WM_CTLCOLORSTATIC push ebx push edx invoke SendMessage, hWnd, WM_GETFONT, 0, 0 mov edx,eax invoke GetObject, edx, sizeof LOGFONT, addr tmpFont mov tmpFont.lfUnderline, TRUE invoke CreateFontIndirect, addr tmpFont mov ebx,eax invoke SelectObject, wParam, ebx .if hover == FALSE invoke SetTextColor, wParam, Blue .else invoke SetTextColor, wParam,Red .endif invoke GetSysColor, COLOR_MENU invoke SetBkColor, wParam, eax invoke DeleteObject,ebx invoke GetStockObject, HOLLOW_BRUSH pop edx pop ebx ret .ELSEIF eax==WM_MOUSEMOVE invoke GetParent,hWnd push ebx mov ebx,eax invoke GetActiveWindow .if eax == ebx invoke GetCursorPos,addr pt invoke GetWindowRect,hWnd,addr rect invoke PtInRect,addr rect,pt.x,pt.y .if eax invoke GetCapture .if !eax invoke SetCapture,hWnd mov hover,TRUE invoke InvalidateRect,hWnd,FALSE,FALSE invoke SetCursor,hFinger .endif .else invoke GetCapture .if eax invoke ReleaseCapture mov hover,FALSE invoke InvalidateRect,hWnd,FALSE,FALSE .endif .endif .endif pop ebx xor eax,eax ret .ELSEIF eax==WM_LBUTTONDOWN invoke GetWindowText,hWnd,offset buff,sizeof buff ;change this for using a preset url invoke ShellExecute, NULL, offset szOpen, offset buff, NULL, NULL, SW_MAXIMIZE ;change this to represent your preset url mov hover,FALSE invoke InvalidateRect,hWnd,FALSE,FALSE invoke SendMessage, hWnd, WM_GETFONT, 0, 0 ;Get the defualt system font mov edx,eax ;store result invoke GetObject, edx, sizeof LOGFONT, addr tmpFont ;get our font into a logfont structure mov tmpFont.lfUnderline, TRUE ;under line the link invoke CreateFontIndirect, addr tmpFont ;Create the new font mov ebx,eax ;We need the return to free the memory later invoke SelectObject, wParam, ebx ;Select our control invoke SetTextColor, wParam, Blue ;change this to change the color of the link xor eax,eax ret .ENDIF invoke CallWindowProc, orgStatic, hWnd, uMsg, wParam, lParam ret HyperLinkWndProc endp AboutDlgProc PROC hWnd:HWND,iMsg:DWORD,wParam:WPARAM, lParam:LPARAM LOCAL hdc:DWORD LOCAL ps:PAINTSTRUCT LOCAL rect:RECT mov eax,iMsg .if eax==WM_INITDIALOG invoke GetDlgItem, hWnd, IDC_URL invoke SetWindowLong, eax, GWL_WNDPROC, ADDR HyperLinkWndProc mov orgStatic,eax invoke LoadCursor,hInstance,IDI_CUR1 mov hFinger,eax xor eax,eax ret .ELSEIF eax == WM_CTLCOLORSTATIC invoke SendMessage,lParam,iMsg,wParam,lParam ret .elseif eax==WM_CLOSE invoke EndDialog,hWnd,NULL mov hwndDlg,0 .elseif eax==WM_COMMAND push edx mov eax,wParam mov edx,eax shr edx,16 .if eax==IDC_EXIT invoke SendMessage,hWnd,WM_CLOSE,NULL,NULL invoke EndDialog,hWnd,NULL mov hwndDlg,0 .endif pop edx .else mov eax,FALSE ret .endif mov eax,TRUE ret AboutDlgProc endp ;----------------------------------------------------ABOUT procedure openini proc hWnd:HWND invoke CreateFile,ADDR ininame,\ GENERIC_READ ,0,\ NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,\ NULL cmp eax,INVALID_HANDLE_VALUE je notop1 mov filehand1,eax invoke GetFileSize,filehand1,addr temp mov filesize,eax invoke GlobalAlloc,GMEM_MOVEABLE + GMEM_ZEROINIT,filesize mov memhand,eax invoke GlobalLock,eax mov mem,eax mov esi,eax mov [esi],dword ptr 1 invoke ReadFile,filehand1,mem,filesize,addr sizeread,NULL mov esi,mem mov ecx,filesize mov ebx,ecx add ebx,esi mov memmax,ebx xor eax,eax notset: inc esi cmp [esi],dword ptr 06f636361h jne notset2 inc eax notset2: loop notset inc eax mov parts,eax notop1: ret openini endp iniscan proc hWnd:HWND mov esi,memdata bigtry: lea edi,inidata xor ecx,ecx retry: mov al,[esi] cmp al,[edi] jne notit xor ch,ch push esi push edi retry1: inc esi inc edi mov al,[esi] cmp al,[edi] jne notit2 inc ch cmp ch,3 jb retry1 xor eax,eax mov al,cl add eax,501 inc esi inc esi invoke SendDlgItemMessage, hWnd, eax, WM_SETTEXT, 0,esi notit2: pop edi pop esi notit: add edi,4 inc cl cmp cl,6 jb retry foundone: cmp esi,memmax jae overit inc esi cmp [esi],byte ptr 0ah jne foundone cmp esi,memmax jae overit inc esi cmp [esi],byte ptr 0dh jne bigtry overit: mov eax,index push eax push offset num2 push offset buff call wsprintfA invoke SendDlgItemMessage, hWnd, 507, WM_SETTEXT, 0,ADDR buff ret iniscan endp end start