;-scroll.asm----------------------------------------------------------------- ; 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 : 21-1-2001 ; ; Purpose : How to use the vertical scrollbar (things are very similar for; ; the horizontal scrollbar).Illustrates procedure calls ; ; ShowScrollBar and SetScrollInfo. ; ; ; ;---------------------------------------------------------------------------- ; Compile with nmake .386 .MODEL FLAT , STDCALL include windows.inc include user32.inc include kernel32.inc include gdi32.inc includelib user32.lib includelib kernel32.lib includelib gdi32.lib EXTRN wsprintfA:PROC .data ClassName db "SimpleWinClass",0 AppName db "Vertical Scrollbar",0 hInstance HINSTANCE ? CommandLine LPSTR ? hwnd HWND ? scrollpos DWORD ? counter DWORD ? buff db 200 dup(0) num db "%lu ",0 hdc DWORD ? .code WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:SDWORD LOCAL wc:WNDCLASSEX LOCAL msg:MSG LOCAL scr:SCROLLINFO ;typedef struct tagSCROLLINFO { // si ; ; UINT cbSize; ; UINT fMask; ; int nMin; ; int nMax; ; UINT nPage; ; int nPos; ; int nTrackPos; ;} SCROLLINFO; 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,NULL push hInstance pop wc.hInstance mov wc.hbrBackground,COLOR_WINDOW+1 mov wc.lpszMenuName,NULL mov wc.lpszClassName,OFFSET ClassName invoke LoadIcon,NULL,IDI_APPLICATION mov wc.hIcon,eax mov wc.hIconSm,0 invoke LoadCursor,NULL,IDC_ARROW mov wc.hCursor,eax invoke RegisterClassEx, addr wc INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\ WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT, 300,168, ;size NULL,NULL,\ hInst,NULL mov hwnd,eax invoke ShowScrollBar,hwnd,SB_VERT,TRUE mov scr.cbSize,SIZEOF scr ; mov scr.fMask,SIF_POS ;SIF_RANGE mov scr.fMask,SIF_POS + SIF_RANGE + SIF_PAGE mov scr.nMin,0 mov scr.nMax,100 mov scr.nPos,5 mov scrollpos,5 mov scr.nPage,10 invoke SetScrollInfo,hwnd,SB_VERT,addr scr,TRUE INVOKE ShowWindow, hwnd,SW_SHOWNORMAL INVOKE UpdateWindow, hwnd .WHILE TRUE INVOKE GetMessage, ADDR msg,NULL,0,0 .BREAK .IF (!eax) INVOKE TranslateMessage, ADDR msg INVOKE DispatchMessage, ADDR msg .ENDW mov eax,msg.wParam ret WinMain endp WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM LOCAL ps:PAINTSTRUCT mov eax,uMsg .IF eax==WM_DESTROY invoke PostQuitMessage,NULL .ELSEIF eax==WM_PAINT invoke BeginPaint,hWnd, ADDR ps mov hdc,eax ; invoke TextOut,hdc,0,0,ADDR TestString,(SIZEOF TestString) -1 call shownum invoke EndPaint,hWnd, ADDR ps .ELSEIF eax==WM_VSCROLL invoke GetDC,hWnd mov hdc,eax mov eax,wParam and eax,0ffffh mov ebx,wParam shr ebx,16 mov ecx,scrollpos .IF eax==SB_THUMBTRACK mov scrollpos,ebx call updatescroll .ELSEIF eax==SB_THUMBPOSITION .ELSEIF eax==SB_LINEUP mov ebx,scrollpos cmp ebx,0 je nosr1 dec ebx mov scrollpos,ebx call updatescroll .ELSEIF eax==SB_LINEUP cmp ecx,0 je nosr1 dec ecx mov scrollpos,ecx call updatescroll .ELSEIF eax==SB_LINEDOWN cmp ecx,91 jae nosr1 inc ecx mov scrollpos,ecx call updatescroll .ELSEIF eax==SB_PAGEUP cmp ecx,0 je nosr1 cmp ecx,10 ja sub1 mov ecx,0 jmp sub1a sub1: sub ecx,10 sub1a: mov scrollpos,ecx call updatescroll .ELSEIF eax==SB_PAGEDOWN cmp ecx,91 jae nosr1 cmp ecx,81 jb sub2 mov ecx,91 jmp sub2a sub2: add ecx,10 sub2a: mov scrollpos,ecx call updatescroll .ENDIF nosr1: call shownum invoke EndPaint,hWnd, ADDR ps .ELSE invoke DefWindowProc,hWnd,uMsg,wParam,lParam ret .ENDIF xor eax,eax ret WndProc endp count proc push esi mov eax,0 noc2: cmp [esi],byte ptr 0 je noc1 inc esi inc eax jmp noc2 noc1: mov [counter],eax pop esi ret count endp shownum proc push edi mov eax,scrollpos mov ecx,10 mov edi,0 listo: push eax push ecx push edi push eax push offset num push offset buff call wsprintfA add esp,0ch lea esi,buff call count invoke TextOut,hdc,0,edi,esi,counter pop edi pop ecx pop eax inc eax add edi,14 loop listo pop edi ret shownum endp updatescroll proc LOCAL scr:SCROLLINFO mov ebx,scrollpos mov scr.cbSize,SIZEOF scr mov scr.fMask,SIF_POS mov scr.nPos,ebx invoke SetScrollInfo,hwnd,SB_VERT,addr scr,TRUE ret updatescroll endp start: invoke GetModuleHandle, NULL mov hInstance,eax invoke GetCommandLine invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT invoke ExitProcess,eax end start