读书人

请教大家一个关于对话框方面的有关问题

发布时间: 2012-02-17 17:50:42 作者: rapoo

请问大家一个关于对话框方面的问题
这样的。。我用这个文件DlgBaseAppWizard.awx(本插件是一个VC开发Win32SDK对话框程序用的向导插件,这个插件是好的。我经常用)在vc下建立了一个win32 DialogBased Application,这是一个Win32SDK对话框程序。他建立的对话框如图:,工程目录如下:,);main.cpp如下:
#include "stdafx.h"
#include "resource.h"
#include "MainDlg.h"
#include <COMMCTRL.H>

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
//Enable IPAddress、Calendar.etc
InitCommonControls();
DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, Main_Proc);
return 0;
}
maindlg.cpp如下:
#include "stdafx.h"
#include <windows.h>
#include <windowsx.h>
#include "resource.h"
#include "MainDlg.h"

/*
Template designed by RuPeng.com. Please visit http://www.rupeng.com for more information
如鹏网(http://www.rupeng.com)大学生计算机学习社区,提供大量免费视频学习教程,提供个性化一对一学习指导
*/
BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog);
HANDLE_MSG(hWnd, WM_COMMAND, Main_OnCommand);
HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose);
}

return FALSE;
}

BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
return TRUE;
}

void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch(id)
{
case IDC_OK:
{
MessageBox(hwnd,TEXT("欢迎访问如鹏网 www.RuPeng.com 大学生计算机学习社区"),TEXT("问好"),MB_OK);
}
break;
default:
break;
}
}

void Main_OnClose(HWND hwnd)
{
EndDialog(hwnd, 0);
}
然后我想在拷一段计算器的代码去maindlg.cpp里面(我删了一部分。。因为里面有些知识点我现今没接触),这段代码如下:
#include <windows.h>
#include <windowsx.h>
#include "main.h"
#include "dialogs.h"
#include "resource.h"
#include "rsrc.inc"

BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
//BEGIN MESSAGE CRACK
HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog);
HANDLE_MSG(hWnd, WM_COMMAND, Main_OnCommand);
HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose);
//END MESSAGE CRACK
}

return FALSE;
}

////////////////////////////////////////////////////////////////////////////////
// Main_OnInitDialog
BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
// Set app icons
SetDlgItemText(hwnd,IDC_EDTNUM,"0.");
SetWindowText(hwnd,TEXT("专用计算器3.0")); //标题名.
return TRUE;
}
// Main_OnCommand
double iFlg=0;//数字累加变量.
double iHalf=0;//保存前输入数字变量.
int r=0; //当前的控件字符的长度.
char iOperator=' '; //标记操作符号 xz
BOOL bResult=FALSE; //判断当前是否有输入操作符变量.
void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch(id)
{
case IDC_BTN0: //1-9按键累加输出.
ShowNumber(hwnd,0);
break;
case IDC_BTN1:
ShowNumber(hwnd,1);
break;
case IDC_BTN2:
ShowNumber(hwnd,2);
break;
case IDC_BTN3:
ShowNumber(hwnd,3);
break;
case IDC_BTN4:
ShowNumber(hwnd,4);
break;
case IDC_BTN5:


ShowNumber(hwnd,5);
break;
case IDC_BTN6:
ShowNumber(hwnd,6);
break;
case IDC_BTN7:
ShowNumber(hwnd,7);
break;
case IDC_BTN8:
ShowNumber(hwnd,8);
break;
case IDC_BTN9:
ShowNumber(hwnd,9);
break;
case IDC_BTNA: //操作符函数.
operatorChar(hwnd,'+');
break;
case IDC_BTNB:
operatorChar(hwnd,'-');
break;
case IDC_BTNC:
operatorChar(hwnd,'*');
break;
case IDC_BTND:
operatorChar(hwnd,'/');
bResult=TRUE;
break;
case IDC_BTNADD:
operatorNum(hwnd);
break;
case IDC_BTNCLEAR: //清除控件内容.
{
iFlg=iHalf=0; //标记重新开始计算.
SetDlgItemText(hwnd,IDC_EDTNUM,"0.");
break;
}
case IDC_BTNBS:
BackSpace(hwnd); //实行退格操作函数.
break;
case IDC_BTNQUIT:
int r=MessageBox(hwnd,TEXT("要退出程序吗?"),TEXT("选择"),MB_OKCANCEL);
if(r==IDOK)
{
EndDialog(hwnd, 0);
}
break;
case IDC_BTNT:
changeTSE(hwnd,2);//二进制转换.
break;
case IDC_BTNE:
changeTSE(hwnd,8);//八进制转换
break;
case IDC_BTNS:
changeTSE(hwnd,16);//十六进制转换.
break;
default:break;
}

}
//数累加,输出.
void ShowNumber(HWND hwnd,int iNum)
{
TCHAR cResult[256];

GetDlgItemText(hwnd,IDC_EDTNUM,cResult,sizeof(cResult)/sizeof(TCHAR));
iFlg=atof(cResult);
if(bResult!=FALSE) //判断是否有前面有四则操作符.
{
iFlg=0; //有就重新累.
bResult=FALSE; //只进行一次判断.重新加数后恢复操作判别符.
}
iFlg=iFlg*10+iNum; //进行累加
gcvt(iFlg,10,cResult);
SetDlgItemText(hwnd,IDC_EDTNUM,cResult);//累加后重新输出.

}
void BackSpace(HWND hwnd)
{

TCHAR cResult[256];

GetDlgItemText(hwnd,IDC_EDTNUM,cResult,sizeof(cResult)/sizeof(TCHAR));
r=strlen(cResult);//求出字符串的长度.
if(r<=2)
{
SetDlgItemText(hwnd,IDC_EDTNUM,"0.");//当前数小于1个数后重新初始化.
}
else
{
cResult[--r]='\0'; //去掉最后一位数字. 再输出.
SetDlgItemText(hwnd,IDC_EDTNUM,cResult);
}
}
//赋操作符函数.
void operatorChar(HWND hwnd,char ch)
{

TCHAR cResult[256];
GetDlgItemText(hwnd,IDC_EDTNUM,cResult,sizeof(cResult)/sizeof(TCHAR));
iHalf=atof(cResult); //取出第一个操作数.
iOperator=ch;
bResult=TRUE;
}

//根据操作符号做相应的运算.
void operatorNum(HWND hwnd)
{
BOOL bJust=FALSE;
double iSum=0;
if(iOperator=='+')
{
TCHAR cResultA[256];
iSum=iHalf+iFlg;//第一个操作数和第二个操作数的运算.
gcvt(iSum,10,cResultA); //double转字符串.
SetDlgItemText(hwnd,IDC_EDTNUM,cResultA);//将结果输出.
iSum=iFlg=iHalf=0; //运算后归零.
iOperator=' ';
}
if(iOperator=='-')
{
TCHAR cResultB[256];
iSum=iHalf-iFlg;
gcvt(iSum,10,cResultB);
SetDlgItemText(hwnd,IDC_EDTNUM,cResultB);
iSum=iFlg=iHalf=0;
iOperator=' ';
}
if(iOperator=='*')


{
TCHAR cResultC[256];
iSum=iHalf*iFlg;
gcvt(iSum,10,cResultC);
SetDlgItemText(hwnd,IDC_EDTNUM,cResultC);
iSum=iFlg=iHalf=0;
iOperator=' ';
}
if(iOperator=='/')
{
TCHAR cResultD[256];
//除数不为零的判断.
if(0==iFlg)
{
MessageBox(hwnd,TEXT("除数不能为零"),TEXT("错误"),MB_OK);
bJust=TRUE;

}
if(FALSE == bJust)
{
iSum=iHalf/iFlg;
gcvt(iSum,10,cResultD);
SetDlgItemText(hwnd,IDC_EDTNUM,cResultD);
iSum=iFlg=iHalf=0;
iOperator=' ';
}
}

}

//十进制转换.
void changeTSE(HWND hwnd,int i)
{
TCHAR iResultA[256];

GetDlgItemText(hwnd,IDC_EDTNUM,iResultA,sizeof(iResultA)/sizeof(TCHAR));
int iA = atoi(iResultA);//转换为整数。
itoa(iA,iResultA,i);//再将整数转换为其他进制。
SetDlgItemText(hwnd,IDC_EDTNUM,iResultA);
}
////////////////////////////////////////////////////////////////////////////////
// Main_OnClose
void Main_OnClose(HWND hwnd)
{
EndDialog(hwnd, 0);
}
我还在maindlg.h里面加上了那些函数;
然后我想实现的对话框如图:;
可是执行之后。出现的信息如下:Compiling...
MainDlg.cpp
E:\Microsoft Visual Studio\MyProjects\test28\MainDlg.cpp(15) : error C2065: 'HANDLE_MSG' : undeclared identifier
E:\Microsoft Visual Studio\MyProjects\test28\MainDlg.cpp(15) : error C2065: 'Main_OnInitDialog' : undeclared identifier
E:\Microsoft Visual Studio\MyProjects\test28\MainDlg.cpp(16) : error C2065: 'Main_OnCommand' : undeclared identifier
E:\Microsoft Visual Studio\MyProjects\test28\MainDlg.cpp(17) : error C2065: 'Main_OnClose' : undeclared identifier
E:\Microsoft Visual Studio\MyProjects\test28\MainDlg.cpp(19) : warning C4060: switch statement contains no 'case' or 'default' labels
E:\Microsoft Visual Studio\MyProjects\test28\MainDlg.cpp(27) : error C2373: 'Main_OnInitDialog' : redefinition; different type modifiers
E:\Microsoft Visual Studio\MyProjects\test28\MainDlg.cpp(43) : error C2373: 'Main_OnCommand' : redefinition; different type modifiers
E:\Microsoft Visual Studio\MyProjects\test28\MainDlg.cpp(47) : error C2065: 'ShowNumber' : undeclared identifier
E:\Microsoft Visual Studio\MyProjects\test28\MainDlg.cpp(77) : error C2065: 'operatorChar' : undeclared identifier
E:\Microsoft Visual Studio\MyProjects\test28\MainDlg.cpp(90) : error C2065: 'operatorNum' : undeclared identifier
E:\Microsoft Visual Studio\MyProjects\test28\MainDlg.cpp(99) : error C2065: 'BackSpace' : undeclared identifier
E:\Microsoft Visual Studio\MyProjects\test28\MainDlg.cpp(102) : error C2065: 'changeTSE' : undeclared identifier
E:\Microsoft Visual Studio\MyProjects\test28\MainDlg.cpp(116) : error C2373: 'ShowNumber' : redefinition; different type modifiers
E:\Microsoft Visual Studio\MyProjects\test28\MainDlg.cpp(132) : error C2373: 'BackSpace' : redefinition; different type modifiers
E:\Microsoft Visual Studio\MyProjects\test28\MainDlg.cpp(150) : error C2373: 'operatorChar' : redefinition; different type modifiers
E:\Microsoft Visual Studio\MyProjects\test28\MainDlg.cpp(161) : error C2373: 'operatorNum' : redefinition; different type modifiers
E:\Microsoft Visual Studio\MyProjects\test28\MainDlg.cpp(215) : error C2373: 'changeTSE' : redefinition; different type modifiers
E:\Microsoft Visual Studio\MyProjects\test28\MainDlg.cpp(226) : error C2373: 'Main_OnClose' : redefinition; different type modifiers
执行 cl.exe 时出错.
我问了一些群里面的人。他们也高不清楚。。说我未定义。缺少头文件。我想应该不是的。。头文件我就基本没动过额。结果很长时间没找到问题的所在。虽然这个问题对大家来说应该很简单。但是对我来说很重要。希望能得到大牛的帮助额!!在此谢了!!

[解决办法]
帮顶!
[解决办法]
script.rc你有吗?没更新吧?resource.h你有更新吗?没有吧?你那些控件都没定义!想用控件就不能只拷代码
------解决方案--------------------


建议做一点,编译一下,然后保存。再做一点。出现这么多错误很难调的。。。

读书人网 >C语言

热点推荐