之前书上有一个win32 asm 的odbc例子,它有一个窗体,可以执行sql;下面看一下弹出一个录入数据的对话框;
之前它在.code段包含2个单独的asm文件,增加第三个,增加的这个里面是弹出对话框的窗口过程,
include _ListView.asm
include _RecordSet.asm
include input.asm
input.asm,
cpp
_InputDlg proc uses ebx edi esi,hWnd,uMsg,wParam,lParam
mov eax,uMsg
.if eax == WM_INITDIALOG
.elseif eax == WM_CLOSE
invoke EndDialog,hWnd,NULL
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
_InputDlg endp
资源文件odbc.rc里面增加一段,
cpp
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#include <resource.h>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#define ICO_MAIN 1000
#define DLG_MAIN 2000
#define IDC_CONN_STR 2001
#define IDC_CONN 2002
#define IDC_DISCONN 2003
#define IDC_SQL 2004
#define IDC_EXEC 2005
#define IDC_LIST 2006
#define IDC_INFO 2007
#define IDC_COMMIT 2008
#define IDC_ROLLBACK 2009
#define IDC_INPUT 2010
#define DLG_INPUT 3000
#define IDC_GRPID 3000
#define IDC_NAME 3001
#define IDC_MOBILE 3002
#define IDC_SEX 3003
#define IDC_COMPANY 3004
#define IDC_ADDR 3005
#define IDC_PHONE 3006
#define IDC_POST 3007
#define IDC_MEMO 3008
#define IDC_INPUTOK 3009
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ICO_MAIN icon "Main.ico"
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
DLG_MAIN DIALOG 51, 78, 465, 237
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "ODBC数据库操作例子"
FONT 9, "宋体"
{
EDITTEXT IDC_CONN_STR, 65, 5, 290, 12, ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP
PUSHBUTTON "连接(&C)", IDC_CONN, 359, 4, 50, 14
PUSHBUTTON "断开(&D)", IDC_DISCONN, 412, 4, 50, 14, WS_DISABLED | WS_TABSTOP
EDITTEXT IDC_SQL, 40, 22, 261, 12, ES_AUTOHSCROLL | WS_DISABLED | WS_BORDER | WS_TABSTOP
DEFPUSHBUTTON "执行(&E)", IDC_EXEC, 306, 21, 50, 14, BS_DEFPUSHBUTTON | WS_DISABLED | WS_TABSTOP
PUSHBUTTON "提交(&M)", IDC_COMMIT, 359, 21, 50, 14, WS_DISABLED | WS_TABSTOP
PUSHBUTTON "回滚(&R)", IDC_ROLLBACK, 412, 21, 50, 14, WS_DISABLED | WS_TABSTOP
PUSHBUTTON "录入(&I)", IDC_INPUT, 412, 51, 50, 14, WS_TABSTOP
CONTROL "", IDC_LIST, "SysListView32", 13 | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 2, 56, 460, 179
LTEXT "SQL语句", -1, 5, 24, 34, 8
LTEXT "ODBC连接字符串", -1, 5, 8, 60, 8
LTEXT "", IDC_INFO, 5, 38, 455, 18
}
DLG_INPUT DIALOG 51, 78, 465, 237
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "录入数据"
FONT 9, "宋体"
{
LTEXT "组id", -1, 5, 5, 34, 8
LTEXT "姓名:", -1, 5, 35, 34, 8
LTEXT "手机:", -1, 5, 65, 34, 8
LTEXT "性别:", -1, 5, 95, 34, 8
LTEXT "单位:", -1, 5, 125, 34, 8
LTEXT "地址:", -1, 5, 155, 34, 18
LTEXT "座机:", -1, 5, 185, 34, 8
LTEXT "邮编:", -1, 5, 215, 34, 8
LTEXT "备注:", -1, 5, 245, 34, 18
EDITTEXT IDC_GRPID, 65, 5, 290, 12, WS_BORDER | WS_TABSTOP
EDITTEXT IDC_NAME, 65, 35, 290, 12, WS_BORDER | WS_TABSTOP
EDITTEXT IDC_MOBILE, 65, 65, 261, 12, WS_BORDER | WS_TABSTOP
EDITTEXT IDC_SEX, 65, 95, 290, 12, WS_BORDER | WS_TABSTOP
EDITTEXT IDC_COMPANY, 65, 125, 290, 12, WS_BORDER | WS_TABSTOP
EDITTEXT IDC_ADDR, 65, 155, 261, 12, WS_BORDER | WS_TABSTOP
EDITTEXT IDC_PHONE, 65, 185, 290, 12, WS_BORDER | WS_TABSTOP
EDITTEXT IDC_POST, 65, 215, 290, 12, WS_BORDER | WS_TABSTOP
EDITTEXT IDC_MEMO, 65, 245, 261, 12, ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP
PUSHBUTTON "确定(&Q)", IDC_INPUTOK, 412, 21, 50, 14, WS_TABSTOP
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
DLG_MAIN DIALOG 51, 78, 465, 237,这是原来的主对话框的资源描述;DLG_INPUT DIALOG 51, 78, 465, 237,这是弹出的对话框的资源描述,这是新加的;
主对话框上增加一个按钮,
PUSHBUTTON "录入(&I)", IDC_INPUT, 412, 51, 50, 14, WS_TABSTOP
点击时弹出input对话框;
资源文件里增加,
#define IDC_INPUT 2010
#define DLG_INPUT 3000
odbc.asm的等值定义里增加,
DLG_INPUT equ 3000
IDC_INPUT equ 2010
这是之前程序的弹出主对话框的语句,
invoke DialogBoxParam,eax,DLG_MAIN,NULL,offset _ProcDlgMain,0
DLG_MAIN,是对话框资源标识,_ProcDlgMain是对话框的窗口过程;
在之前的主对话框窗口过程的消息处理分支的WM_COMMAND处理分支下面增加IDC_INPUT按钮的处理,
.if eax == WM_COMMAND
mov eax,wParam
.if ax == IDC_CONN_STR
。。。。。。
.elseif ax == IDC_SQL
。。。。。。
.elseif ax == IDC_CONN
。。。。。。
.elseif ax == IDC_DISCONN
。。。。。。
.elseif ax == IDC_INPUT
invoke DialogBoxParam,hInstance,DLG_INPUT,NULL,offset _InputDlg,NULL
.endif
当点击IDC_INPUT按钮时,执行
invoke DialogBoxParam,hInstance,DLG_INPUT,NULL,offset _InputDlg,NULL
_InputDlg是弹出对话框的窗口过程;
如果不小心加或写错.endif,如下图有2个.endif, 就会出现下图错误,
odbc.asm(286) : fatal error A1011: directive must be in control block
指令必须在控制块中; .if ...... .endif ,是一个控制块;
点击新加的按钮后弹出如下界面,
有时间继续;