⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 见招拆招《windows程序设计》(九) .txt

📁 会变语言实现的一些程序
💻 TXT
📖 第 1 页 / 共 5 页
字号:
	xor	edx,edx
	mov	eax,sizeof szCaption
	mov	ecx,sizeof TCHAR
	div	ecx
	mov	ebx,eax
	invoke	LoadString,hInstance,IDS_CAPTION,addr szCaption,ebx
	
	mov wndclass.cbSize,sizeof WNDCLASSEX	
	mov wndclass.style,CS_HREDRAW or CS_VREDRAW	
	mov wndclass.lpfnWndProc,offset WndProc

	mov wndclass.cbClsExtra,0
	mov wndclass.cbWndExtra,0
	
	push hInstance
	pop wndclass.hInstance
	
	invoke LoadIcon,hInstance,addr szAppName
	mov wndclass.hIcon,eax	
	
	invoke LoadCursor,NULL,IDC_ARROW
	mov wndclass.hCursor,eax	
	
	invoke GetStockObject,WHITE_BRUSH
	mov wndclass.hbrBackground,EAX
	
	mov wndclass.lpszMenuName,NULL
	lea eax,szAppName
	mov wndclass.lpszClassName,eax

	mov wndclass.hIconSm,0
	
	invoke RegisterClassEx, ADDR wndclass
	.if (eax==0)
	   mov		ebx,sizeof szAppName
           invoke	LoadString,hInstance, IDS_APPNAME, addr szAppName,ebx
           mov		ebx,sizeof szErrMsg
           invoke	LoadString,hInstance, IDS_ERRMSG, addr szErrMsg,ebx
           invoke	MessageBox,NULL, addr szErrMsg,addr szAppName, MB_ICONERROR
           ret
	.endif
        
	invoke CreateWindowEx,NULL,
			ADDR szAppName, 					;window class name
			ADDR szAppName, 
			WS_OVERLAPPEDWINDOW or WS_CLIPCHILDREN,			;window style
			CW_USEDEFAULT,						;initial x position
			CW_USEDEFAULT,						;initial y position
			CW_USEDEFAULT, 						;initial x size
			CW_USEDEFAULT,						;initial y size
			NULL,							;parent window handle
			NULL,							;window menu handle
			hInstance,						;program instance handle
			NULL							;creation parameters
	mov hWnd,eax
	
	invoke ShowWindow,hWnd,iCmdShow
	invoke UpdateWindow,hWnd
	
	StartLoop:
		invoke GetMessage,ADDR msg,NULL,0,0
			cmp eax, 0
			je ExitLoop
				invoke TranslateMessage, ADDR msg
				invoke DispatchMessage,  ADDR msg
			jmp StartLoop
	ExitLoop:
	
	mov eax,msg.wParam
	ret

WinMain endp

WndProc proc hwnd:DWORD,uMsg:DWORD,wParam :DWORD,lParam :DWORD
	LOCAL	hdc:HDC
        LOCAL   ps:PAINTSTRUCT
        LOCAL	rect:RECT
        LOCAL	tm:TEXTMETRIC

	.if uMsg==WM_CREATE
		invoke	GetDC,hwnd
		mov	hdc,eax
		invoke	GetTextMetrics,hdc,addr tm
		mov	eax,tm.tmAveCharWidth
		mov	cxChar,eax
		mov	eax,tm.tmHeight
		add	eax,tm.tmExternalLeading
		mov	cyChar,eax
		invoke	ReleaseDC,hwnd,hdc
                invoke	  GetSystemMetrics,SM_CXVSCROLL
                mov	xScroll,eax
		invoke	CreateWindowEx,
					NULL,
					CTXT("scrollbar"), 
					NULL,
                                	WS_CHILD or WS_VISIBLE or SBS_VERT,
                                	0, 0, 0, 0,
               				hwnd, 1, hInst, NULL		
		mov	hScroll,eax

		invoke	FindResource,hInst,CTEXT("AnnabelLee"),CTEXT ("TEXT")
		mov	ebx,eax
                invoke	LoadResource,hInst,ebx
		mov	hResource,eax
                invoke	LockResource,hResource
                mov	pText,eax
		
		xor	eax,eax        
	        mov	iNumLines,eax
	        
                mov	esi,pText
                mov	ax,[esi]
                .while	(al!='\')&&(ax!=0)
                	.if	al==10
                		inc	iNumLines
                	.endif
                	inc	pText
                	inc	esi
                	mov	ax,[esi]
                .endw
                mov	BYTE ptr [esi],0
        	invoke  SetScrollRange,hScroll, SB_CTL, 0, iNumLines, FALSE
		invoke	SetScrollPos,hScroll, SB_CTL, 0, FALSE
                  
	        xor	eax,eax
	        ret
	.elseif uMsg == WM_SIZE
        	push	TRUE
        	mov	eax,lParam
        	shr	eax,16
        	push	eax
        	mov	cyClient,eax
        	push	xScroll
        	push	0
        	mov	eax,lParam
        	and	eax,0FFFFh
        	sub	eax,xScroll
        	push	eax
        	push	hScroll
        	call	MoveWindow
        	
                invoke  SetFocus,hwnd

	        xor	eax,eax
	        ret
	.elseif uMsg == WM_SETFOCUS
                invoke	SetFocus,hScroll
	        xor	eax,eax
	        ret
	.elseif uMsg == WM_VSCROLL
		mov	eax,wParam
		.if	eax == SB_TOP
			xor	eax,eax
			mov	iPosition,eax
		.elseif	eax == SB_BOTTOM
			mov	eax,iNumLines
			mov	iPosition,eax
		.elseif	eax == SB_LINEUP 
			dec	iPosition
		.elseif	eax == SB_LINEDOWN 
			inc	iPosition
		.elseif	eax == SB_PAGEUP
			xor	edx,edx
			mov	eax,cyClient
			mov	ecx,cyChar
			div	ecx
			mov	ebx,iPosition
			sub	ebx,eax
			mov	iPosition,eax
		.elseif	eax == SB_PAGEDOWN 	
			xor	edx,edx
			mov	eax,cyClient
			mov	ecx,cyChar
			div	ecx
			mov	ebx,iPosition
			add	ebx,eax
			mov	iPosition,eax			
		.elseif	eax == SB_THUMBPOSITION 	
			mov	eax,lParam
			and	eax,0FFFFh
			mov	iPosition,eax
		.endif	
		mov	eax,iPosition
		cmp	eax,iNumLines
		jl	@f
		mov	eax,iNumLines
	@@:	
		cmp	eax,0
		jg	@f
		xor	eax,eax
	@@:	
		mov	iPosition,eax
		invoke	GetScrollPos,hScroll, SB_CTL
		.if	eax!=iPosition
                        invoke	SetScrollPos,hScroll, SB_CTL, iPosition, TRUE
                       	invoke	InvalidateRect,hwnd, NULL, TRUE
		.endif			
		
	        xor	eax,eax
	        ret	        
	.elseif uMsg == WM_PAINT
		invoke	BeginPaint,hwnd, addr ps
		mov	hdc,eax
 		invoke	LockResource,hResource
 		mov	pText,eax
 		invoke	GetClientRect,hwnd,addr rect
 		mov	eax,cxChar
 		add	rect.left,eax
 		mov	eax,1
 		sub	eax,iPosition
 		mov	ecx,cyChar
 		mul	ecx
 		add	rect.top,eax
 		invoke	DrawText,hdc, pText, -1,addr rect, DT_EXTERNALLEADING
 		invoke	EndPaint,hwnd,addr ps

	        xor	eax,eax
	        ret		
	.elseif uMsg == WM_DESTROY

		invoke	FreeResource,hResource
	        invoke 	PostQuitMessage,NULL
	        xor	eax,eax
	        ret
	.endif

	invoke DefWindowProc,hwnd,uMsg,wParam,lParam
	ret
WndProc endp
END START
POEPOEM.RC
#define IDM_FILE_NEW                    40001
#define IDM_FILE_OPEN                   40002
#define IDM_FILE_SAVE                   40003
#define IDM_FILE_SAVE_AS                40004
#define IDM_APP_EXIT                    40005
#define IDM_EDIT_UNDO                   40006
#define IDM_EDIT_CUT                    40007
#define IDM_EDIT_COPY                   40008
#define IDM_EDIT_PASTE                  40009
#define IDM_EDIT_CLEAR                  40010
#define IDM_BKGND_WHITE                 40011
#define IDM_BKGND_LTGRAY                40012
#define IDM_BKGND_GRAY                  40013
#define IDM_BKGND_DKGRAY                40014
#define IDM_BKGND_BLACK                 40015
#define IDM_TIMER_START                 40016
#define IDM_TIMER_STOP                  40017
#define IDM_APP_HELP                    40018
#define IDM_APP_ABOUT                   40019
#define ID_MENUITEM40020                40020

POPMENU MENU DISCARDABLE 
BEGIN
    POPUP "MyMenu"
    BEGIN
        POPUP "&File"
        BEGIN
            MENUITEM "&New",                        IDM_FILE_NEW
            MENUITEM "&Open",                       IDM_FILE_OPEN
            MENUITEM "&Save",                       IDM_FILE_SAVE
            MENUITEM "Save &As",                    IDM_FILE_SAVE_AS
            MENUITEM SEPARATOR
            MENUITEM "E&xit",                       IDM_APP_EXIT
        END
        POPUP "&Edit"
        BEGIN
            MENUITEM "&Undo",                       IDM_EDIT_UNDO
            MENUITEM SEPARATOR
            MENUITEM "Cu&t",                        IDM_EDIT_CUT
            MENUITEM "&Copy",                       IDM_EDIT_COPY
            MENUITEM "&Paste",                      IDM_EDIT_PASTE
            MENUITEM "De&lete",                     IDM_EDIT_CLEAR
        END
        POPUP "&Background"
        BEGIN
            MENUITEM "&White",                      IDM_BKGND_WHITE, CHECKED
            MENUITEM "&Light Gray",                 IDM_BKGND_LTGRAY
            MENUITEM "&Gray",                       IDM_BKGND_GRAY
            MENUITEM "&Dark Gray",                  IDM_BKGND_DKGRAY
            MENUITEM "&Black",                      IDM_BKGND_BLACK
        END
        POPUP "&Help"
        BEGIN
            MENUITEM "&Help...",                    IDM_APP_HELP
            MENUITEM "&About PopMenu...",           IDM_APP_ABOUT
        END
    END
END

POEPOEM.TXT
        
It was many and many a year ago,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -