|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.386
.model flat,stdcall
option casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include 文件定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include gdi32.inc
includelib gdi32.lib
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; equ等值
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ICO_BIG equ 1000h
ICO_SMALL equ 1001h
CUR_2 equ 1000h
IDM_MAIN equ 2000h
IDM_EXIT equ 2101h
IDM_BIG equ 2201h
IDM_SMALL equ 2202h
IDM_CUR1 equ 2203h
IDM_CUR2 equ 2204h
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 数据段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
hInstance dd ?
hWinMain dd ?
hMenu dd ?
hIconB dd ?
hIconM dd ?
hCur1 dd ?
hCur2 dd ?
.const
szClassName db 'Icon and Cursor Example',0 ;窗口类名称
szCursorFile db '1.ani',0
szCaptionMain db '图标和光标切换',0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 代码段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 退出程序
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_Quit proc
invoke DestroyWindow,hWinMain ;摧毁窗口
invoke PostQuitMessage,NULL ;退出消息循环
ret
_Quit endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 窗口过程
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcWinMain proc uses ebx edi esi hWnd,uMsg,wParam,lParam ;窗口过程开始
mov eax,uMsg
;********************************************************************
;.if eax == WM_CREATE
;移动获取句柄函数到主函数成功
; invoke LoadIcon,hInstance,ICO_BIG
; mov hIconB,eax
; invoke LoadIcon,hInstance,ICO_SMALL
; mov hIconM,eax
; invoke LoadCursorFromFile,addr szCursorFile
; mov hCur1,eax
; invoke LoadCursor,hInstance,CUR_2
; mov hCur2,eax
;********************************************************************
;成功移植至建立窗口后的代码
;invoke SendMessage,hWnd,WM_COMMAND,IDM_BIG,NULL
;invoke SendMessage,hWnd,WM_COMMAND,IDM_CUR1,NULL
;********************************************************************
.if eax == WM_COMMAND
mov eax,wParam
movzx eax,ax
.if eax == IDM_EXIT
call _Quit
.elseif eax == IDM_BIG
invoke SetClassLong,hWnd,GCL_HICON,hIconB ;有效函数
;invoke SendMessage,hWnd,WM_SETICON,ICON_BIG,hIconB
;ICON_BIG是在程序切换的图标,ICON_SMALL是菜单栏的图标
invoke CheckMenuRadioItem,hMenu,IDM_BIG,IDM_SMALL,IDM_BIG,MF_BYCOMMAND
;函数简介:撤销一组菜单的状态并指定一个菜单为选定状态
.elseif eax == IDM_SMALL
invoke SetClassLong,hWnd,GCL_HICON,hIconM ;有效函数
;invoke SendMessage,hWnd,WM_SETICON,ICON_BIG,hIconM
invoke CheckMenuRadioItem,hMenu,IDM_BIG,IDM_SMALL,IDM_SMALL,MF_BYCOMMAND
.elseif eax == IDM_CUR1
invoke SetClassLong,hWnd,GCL_HCURSOR,hCur1
;替换CLASS结构体成员HCURSOR是光标
;invoke SendMessage,hWnd,WM_SETICON,hIconB,hIconB 无效函数
invoke CheckMenuRadioItem,hMenu,IDM_CUR1,IDM_CUR2,IDM_CUR1,MF_BYCOMMAND
.elseif eax == IDM_CUR2
invoke SetClassLong,hWnd,GCL_HCURSOR,hCur2
;invoke SendMessage,hWnd,WM_SETCURSOR,hIconM,hIconM 无效函数
invoke CheckMenuRadioItem,hMenu,IDM_CUR1,IDM_CUR2,IDM_CUR2,MF_BYCOMMAND
.endif
;********************************************************************
.elseif eax == WM_CLOSE ;处理关闭消息
call _Quit
;********************************************************************
.else
invoke DefWindowProc,hWnd,uMsg,wParam,lParam ;将剩下的消息交给WINDOWS处理
ret ;直接返回
.endif
;********************************************************************
xor eax,eax ;将EAX寄存器致零。
ret ;直接返回
_ProcWinMain endp ;窗口过程结束
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_WinMain proc ;主模块执行
local @stWndClass:WNDCLASSEX ;申请注册窗口类的结构体@stWndClass
local @stMsg:MSG ;申请消息结构体@stMsg
invoke GetModuleHandle,NULL ;获取本程序句柄
mov hInstance,eax ;保存句柄到hInstance变量
invoke LoadMenu,hInstance,IDM_MAIN
mov hMenu,eax
invoke LoadIcon,hInstance,ICO_BIG
mov hIconB,eax
invoke LoadIcon,hInstance,ICO_SMALL
mov hIconM,eax
invoke LoadCursorFromFile,addr szCursorFile
mov hCur1,eax
invoke LoadCursor,hInstance,CUR_2
mov hCur2,eax
;********************************************************************
; 注册窗口类
;********************************************************************
invoke RtlZeroMemory,addr @stWndClass,sizeof @stWndClass ;将结构体@stWndClass全部清0
push hInstance ;将程序的实例句柄压栈
pop @stWndClass.hInstance ;将程序的实例句柄出栈存储到结构体中
mov @stWndClass.cbSize,sizeof WNDCLASSEX
mov @stWndClass.style,CS_HREDRAW or CS_VREDRAW ;类的风格 CS_HREDRAW当窗口水平方向的宽度变化时重绘整个窗口
; CS_VREDRAW 当窗口垂直方向的宽度变化时重绘整个窗口
mov @stWndClass.lpfnWndProc,offset _ProcWinMain ;窗口回调过程的地址存储到结构体中
mov @stWndClass.hbrBackground,COLOR_WINDOW + 1 ;画刷:颜色是白色..后面规定要+1
mov @stWndClass.lpszClassName,offset szClassName ;给定类名称
invoke RegisterClassEx,addr @stWndClass ;注册窗口类
;********************************************************************
; 建立并显示窗口
;********************************************************************
invoke CreateWindowEx,WS_EX_CLIENTEDGE,offset szClassName,\ ;建立窗口 窗口风格扩展client客户 + edge边缘,后面的是类名称
offset szCaptionMain,\ ;窗口标题
WS_OVERLAPPEDWINDOW,\ ;复合窗口风格
200,200,500,400,\
NULL,hMenu,hInstance,NULL
mov hWinMain,eax ;将返回句柄存储到hWinMain
invoke SendMessage,hWinMain,WM_COMMAND,IDM_BIG,NULL
invoke SendMessage,hWinMain,WM_COMMAND,IDM_CUR1,NULL
invoke ShowWindow,hWinMain,SW_SHOWNORMAL ;显示窗口 SW_SHOWNORMAL普通状态显示
invoke UpdateWindow,hWinMain ;更新窗口
;********************************************************************
; 消息循环
;********************************************************************
.while TRUE ;TRUE==1
invoke GetMessage,addr @stMsg,NULL,0,0 ;取得本程序所有的消息放入@stMsg
.break .if eax == 0 ;如果EAX返回0(收到退出函数就等于0)则立即中断并退出消息循环
invoke TranslateMessage,addr @stMsg ;转译@stMsg里面的消息到窗口过程
invoke DispatchMessage,addr @stMsg ;派发@stMsg里面的消息到窗口过程
.endw
ret
_WinMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
call _WinMain ;调用子程序_WinMain
invoke ExitProcess,NULL ;退出程序
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
end start ;程序从start开始执行
===============================================================
RC文件
#include <resource.h>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#define ICO_BIG 0x1000
#define ICO_SMALL 0x1001
#define CUR_2 0x1000
#define IDM_MAIN 0x2000
#define IDM_EXIT 0x2101
#define IDM_BIG 0x2201
#define IDM_SMALL 0x2202
#define IDM_CUR1 0x2203
#define IDM_CUR2 0x2204
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ICO_SMALL ICON "Small.ico"
ICO_BIG ICON "Big.ico"
CUR_2 cursor "2.cur"
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
IDM_MAIN menu discardable
BEGIN
popup "文件(&F)"
BEGIN
menuitem "退出(&X)", IDM_EXIT
END
popup "图标和光标(&I)"
BEGIN
menuitem "大图标(&G)", IDM_BIG
menuitem "小图标(&M)", IDM_SMALL
menuitem separator
menuitem "光标A(&A)", IDM_CUR1
menuitem "光标B(&b)", IDM_CUR2
END
END
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|