只能个位加,减,乘,除,不会文本连接所以只能写到这了,以后再做更新.只用了2个函数(SetDlgItemText,GetDlgItemInt)见笑了,高手勿喷,代码如下:
子窗口控件定义.rc:
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#include <resource.h>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#define ICO_MAIN 0x1000 //图标
#define DLG_MAIN 1
#define IDC_TEXT 1201 //文本框1
#define IDC_TEXT2 1202
#define IDC_A1 1201 //按钮1
#define IDC_A2 1002 //按钮2
#define IDC_A3 1003 //按钮3
#define IDC_A4 1004 //按钮4
#define IDC_A5 1005 //按钮5
#define IDC_A6 1006 //按钮6
#define IDC_A7 1007 //按钮7
#define IDC_A8 1008 //按钮8
#define IDC_A9 1009 //按钮9
#define IDC_A0 1010 //按钮0
#define IDC_ADD 1011 //按钮+
#define IDC_SUB 1012 //按钮-
#define IDC_MUL 1013 //按钮*
#define IDC_DIV 1014 //按钮/
#define IDC_C 1015 //按钮C
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ICO_MAIN ICON "Main.ico"
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
DLG_MAIN DIALOG 50, 50, 150, 150
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "计算器"
FONT 9, "宋体"
{
RTEXT "0", IDC_TEXT,3,30,30,10,WS_BORDER //文本框1
RTEXT "0",IDC_TEXT2,10,14,130,15,WS_BORDER //文本框2
PUSHBUTTON "1", IDC_A1, 0, 50, 30, 14, //按钮1
PUSHBUTTON "2", IDC_A2, 40, 50, 30, 14 //按钮2
PUSHBUTTON "3", IDC_A3, 80, 50, 30, 14 //按钮3
PUSHBUTTON "+", IDC_ADD, 120, 50, 30, 14 //按钮+
PUSHBUTTON "4", IDC_A4, 0, 70, 30, 14 //按钮4
PUSHBUTTON "5", IDC_A5, 40, 70, 30, 14 //按钮5
PUSHBUTTON "6", IDC_A6, 80, 70, 30, 14 //按钮6
PUSHBUTTON "-", IDC_SUB, 120, 70, 30, 14 //按钮-
PUSHBUTTON "7", IDC_A7, 0, 90, 30, 14 //按钮7
PUSHBUTTON "8", IDC_A8, 40, 90, 30, 14 //按钮8
PUSHBUTTON "9", IDC_A9, 80, 90, 30, 14 //按钮9
PUSHBUTTON "*", IDC_MUL, 120, 90, 30, 14 //按钮*
PUSHBUTTON "0", IDC_A0, 0, 110, 30, 14 //按钮0
PUSHBUTTON "/", IDC_DIV, 40, 110, 30, 14 //按钮/
DEFPUSHBUTTON "=", IDOK, 80, 110, 30, 14 //按钮等于
PUSHBUTTON "C", IDC_C, 120, 110, 30, 14 //按钮c
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.ASM文件:
.386
.model flat, stdcall
option casemap :none
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
ICO_MAIN equ 1000h ;图标
DLG_MAIN equ 1
IDC_TEXT equ 1201
IDC_TEXT2 equ 1202
IDC_A1 equ 1201 ;按钮1
IDC_A2 equ 1002 ;按钮2
IDC_A3 equ 1003 ;按钮3
IDC_A4 equ 1004 ;按钮4
IDC_A5 equ 1005 ;按钮5
IDC_A6 equ 1006 ;按钮6
IDC_A7 equ 1007 ;按钮7
IDC_A8 equ 1008 ;按钮8
IDC_A9 equ 1009 ;按钮9
IDC_A0 equ 1010 ;按钮0
IDC_ADD equ 1011 ;按钮+
IDC_SUB equ 1012 ;按钮-
IDC_MUL equ 1013 ;按钮*
IDC_DIV equ 1014 ;按钮/
IDC_C equ 1015 ;按钮C
.data?
hInstance dd ?
lpshuju dd 0
lpshuju1 dd 0
lpshuju2 dd 0
lpshuju3 dd 0
lpshuju4 dd 0
.code
_ProcDlgMain proc uses ebx edi esi hWnd,wMsg,wParam,lParam
local @szbuffer[128]:BYTE
mov eax,wMsg
.if eax == WM_CLOSE
invoke EndDialog,hWnd,NULL
.elseif eax == WM_INITDIALOG
invoke LoadIcon,hInstance,ICO_MAIN
invoke SendMessage,hWnd,WM_SETICON,ICON_BIG,eax
.elseif eax == WM_COMMAND
mov eax,wParam
.if ax == IDOK
invoke GetDlgItemInt,hWnd,IDC_TEXT,offset lpshuju3,FALSE
mov lpshuju3,eax
.if lpshuju3 == 1 ;加法
invoke GetDlgItemInt,hWnd,IDC_TEXT2,offset lpshuju1,FALSE
mov lpshuju2,eax
mov ecx,lpshuju2
ADD lpshuju,ecx
invoke SetDlgItemInt,hWnd,IDC_TEXT2,lpshuju,FALSE
.elseif lpshuju3 == 2 ;减法
invoke GetDlgItemInt,hWnd,IDC_TEXT2,offset lpshuju1,FALSE
mov lpshuju2,eax
mov ecx,lpshuju2
SBB lpshuju,ecx
invoke SetDlgItemInt,hWnd,IDC_TEXT2,lpshuju,FALSE
.elseif lpshuju3 == 3 ;乘法
invoke GetDlgItemInt,hWnd,IDC_TEXT2,offset lpshuju1,FALSE
MUL lpshuju
invoke SetDlgItemInt,hWnd,IDC_TEXT2,AX,FALSE
.elseif lpshuju3 == 4 ;除法
invoke GetDlgItemInt,hWnd,IDC_TEXT2,offset lpshuju1,FALSE
mov lpshuju4,eax
mov edx,0
mov eax,lpshuju
mov ecx,lpshuju4
DIV ecx
invoke SetDlgItemInt,hWnd,IDC_TEXT2,EAX,FALSE
.endif
.elseif ax == IDC_A1
invoke SetDlgItemInt,hWnd,IDC_TEXT2,1,FALSE
.elseif ax == IDC_A2
invoke SetDlgItemInt,hWnd,IDC_TEXT2,2,FALSE
.elseif ax == IDC_A3
invoke SetDlgItemInt,hWnd,IDC_TEXT2,3,FALSE
.elseif ax == IDC_A4
invoke SetDlgItemInt,hWnd,IDC_TEXT2,4,FALSE
.elseif ax == IDC_A5
invoke SetDlgItemInt,hWnd,IDC_TEXT2,5,FALSE
.elseif ax == IDC_A6
invoke SetDlgItemInt,hWnd,IDC_TEXT2,6,FALSE
.elseif ax == IDC_A7
invoke SetDlgItemInt,hWnd,IDC_TEXT2,7,FALSE
.elseif ax == IDC_A8
invoke SetDlgItemInt,hWnd,IDC_TEXT2,8,FALSE
.elseif ax == IDC_A9
invoke SetDlgItemInt,hWnd,IDC_TEXT2,9,FALSE
.elseif ax == IDC_ADD
invoke GetDlgItemInt,hWnd,IDC_TEXT2,offset lpshuju1,FALSE
mov lpshuju,eax
invoke SetDlgItemInt,hWnd,IDC_TEXT,1,FALSE
invoke SetDlgItemText,hWnd,IDC_TEXT2,addr @szbuffer
.elseif ax == IDC_SUB
invoke GetDlgItemInt,hWnd,IDC_TEXT2,offset lpshuju1,FALSE
mov lpshuju,eax
invoke SetDlgItemInt,hWnd,IDC_TEXT,2,FALSE
invoke SetDlgItemText,hWnd,IDC_TEXT2,addr @szbuffer
.elseif ax == IDC_MUL
invoke GetDlgItemInt,hWnd,IDC_TEXT2,offset lpshuju1,FALSE
mov lpshuju,eax
invoke SetDlgItemInt,hWnd,IDC_TEXT,3,FALSE
invoke SetDlgItemText,hWnd,IDC_TEXT2,addr @szbuffer
.elseif ax == IDC_DIV
invoke GetDlgItemInt,hWnd,IDC_TEXT2,offset lpshuju1,FALSE
mov lpshuju,eax
invoke SetDlgItemInt,hWnd,IDC_TEXT,4,FALSE
invoke SetDlgItemText,hWnd,IDC_TEXT2,addr @szbuffer
.elseif ax == IDC_C
invoke SetDlgItemText,hWnd,IDC_TEXT,addr @szbuffer
invoke SetDlgItemText,hWnd,IDC_TEXT2,addr @szbuffer
.endif
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
_ProcDlgMain endp
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,DLG_MAIN,NULL,offset _ProcDlgMain,NULL
invoke ExitProcess,NULL
end start
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
成品软件图:
源码和文件下载:
计算器.rar
(3.35 KB, 下载次数: 30)
|