高难度vc++开发工具问题。。有经验的高手来。。没能力的不要来。。

guankaifu 2003-10-10 02:39:30
按钮的单击事件OnOk为什么里面自动加入CDialog::OnOK();语句。。。
可是编程的时候不删除CDialog::OnOK();这句话的话就不能正常工作????
为什么他要加CDialog::OnOK();这个代码???有什么用???
有经验的人请来谈谈。。。我打了最新的补丁了。。
自动生成的代码如下。。。

void CFgdDlg::OnOK()
{
// TODO: Add extra validation here

CDialog::OnOK();
}
...全文
65 29 打赏 收藏 转发到动态 举报
写回复
用AI写文章
29 条回复
切换为时间正序
请发表友善的回复…
发表回复
my9471 2003-10-11
  • 打赏
  • 举报
回复
这个问题很简单,不过往往让很多程序员忽略它,如果不处理它,CDialog类会接收esc和回车及alt+f4等,这时你的对话框会关闭,删除CDialog::OnOK();你对话框不会关闭,即使你向对话框发送WM_CLOSE消息,要退出程对话框时必须在其它地方调用CDialog::OnOK();
zjg751206 2003-10-11
  • 打赏
  • 举报
回复
不必删除,void CFgdDlg::OnOK()
{
// TODO: Add extra validation here

CDialog::OnOK();
}
如果你不想关闭对话框,注视掉CDialog::OnOK();这一行即可
void CFgdDlg::OnOK()
{
// TODO: Add extra validation here

//CDialog::OnOK();
}
这样就可以了
牧马回答于2003年10月


0uhuang 2003-10-11
  • 打赏
  • 举报
回复
~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~
虽然楼主的态度有问题,但他所提的问题我也遇到过。当时不解,后删除之,才解决。至今不解啊
~~~~~~~~~~~~~~~~~~~~~~~~~~~
big_2000_bird 2003-10-11
  • 打赏
  • 举报
回复
这样的问题.......
vagabondkq 2003-10-11
  • 打赏
  • 举报
回复
sb
mygodtoo 2003-10-11
  • 打赏
  • 举报
回复
我贴出
?
Mfc源码
void CDialog::OnOK()
{
if (!UpdateData(TRUE))//这是检查而已
{
TRACE0("UpdateData failed during dialog termination.\n");
// the UpdateData routine will set focus to correct item
return;
}
EndDialog(IDOK);//**注
}

就是让你自己查一下。
你太懒了
mygodtoo 2003-10-11
  • 打赏
  • 举报
回复

Platform SDK: Windows User Interface
EndDialog
The EndDialog function destroys a modal dialog box, causing the system to end any processing for the dialog box.

BOOL EndDialog(
HWND hDlg, // handle to dialog box
INT_PTR nResult // value to return
);
Parameters
hDlg
[in] Handle to the dialog box to be destroyed.
nResult
[in] Specifies the value to be returned to the application from the function that created the dialog box.
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
Dialog boxes created by the DialogBox, DialogBoxParam, DialogBoxIndirect, and DialogBoxIndirectParam functions must be destroyed using the EndDialog function. An application calls EndDialog from within the dialog box procedure; the function must not be used for any other purpose.

A dialog box procedure can call EndDialog at any time, even during the processing of the WM_INITDIALOG message. If your application calls the function while WM_INITDIALOG is being processed, the dialog box is destroyed before it is shown and before the input focus is set.

EndDialog does not destroy the dialog box immediately. Instead, it sets a flag and allows the dialog box procedure to return control to the system. The system checks the flag before attempting to retrieve the next message from the application queue. If the flag is set, the system ends the message loop, destroys the dialog box, and uses the value in nResult as the return value from the function that created the dialog box.

For an example, see Creating a Modal Dialog Box.

Requirements
Windows NT/2000 or later: Requires Windows NT 3.1 or later.
Windows 95/98/Me: Requires Windows 95 or later.
Header: Declared in Winuser.h; include Windows.h.
Library: Use User32.lib.

See Also
Dialog Boxes Overview, Dialog Box Functions, DialogBox, DialogBoxIndirect, DialogBoxIndirectParam, DialogBoxParam, WM_INITDIALOG

Platform SDK Release: February 2001 Contact Platform SDK Order a Platform SDK CD Online



Requirements
Windows NT/2000 or later: Requires Windows NT 3.1 or later.
Windows 95/98/Me: Requires Windows 95 or later.
Header: Declared in Winuser.h; include Windows.h.
Library: Use User32.lib.
See Also
Dialog Boxes Overview, Dialog Box Functions, DialogBox, DialogBoxIndirect, DialogBoxIndirectParam, DialogBoxParam, WM_INITDIALOG
mygodtoo 2003-10-11
  • 打赏
  • 举报
回复
这好象不博大精深
Dialog boxes created by the DialogBox, DialogBoxParam, DialogBoxIndirect, and DialogBoxIndirectParam functions must be destroyed using the EndDialog function. An application calls EndDialog from within the dialog box procedure; the function must not be used for any other purpose.

A dialog box procedure can call EndDialog at any time, even during the processing of the WM_INITDIALOG message. If your application calls the function while WM_INITDIALOG is being processed, the dialog box is destroyed before it is shown and before the input focus is set.

EndDialog does not destroy the dialog box immediately. Instead, it sets a flag and allows the dialog box procedure to return control to the system. The system checks the flag before attempting to retrieve the next message from the application queue. If the flag is set, the system ends the message loop, destroys the dialog box, and uses the value in nResult as the return value from the function that created the dialog box.

MSDN中写的很清楚,
If your application calls the function while WM_INITDIALOG is being processed, the dialog box is destroyed before it is shown and before the input focus is set.
只要会查就可以了,要我贴出全文吗?

leon_z 2003-10-11
  • 打赏
  • 举报
回复
先搞清一件事好了,CDialog::OnOK()干了些什么事
如果我想的没错,你们所说的“不正常”是不是一按按钮对话框就消失了。。。。

其实CDialog::OnOK()就是让模式对话框返回IDOK的,表示你已经确定了,如果你不想让对话框返回,还想让它继续工作,只要删除 CDialog::OnOK()就行了。

另外,CDialog::OnCancel() 也一样,只是对话框返回的是 IDCANCEL



大家来这里只是为了讨论问题,解决问题,是不是高手不重要,人无完人,VC博大精深,所涉盛广,相信没有一个人可以什么都明白,这次是你才回答了别人的问题,没准下次回答你问题的人正是你以前帮助过的。小弟我没有别的意思,只是希望大家相互帮助,共同提高,共同营造一个良好的学习交流的环境,小弟才疏学浅,出言不驯,还望各位见谅




lovessm 2003-10-11
  • 打赏
  • 举报
回复
真是的
不回答你的问题了
mygodtoo 2003-10-11
  • 打赏
  • 举报
回复

直接用
f (!UpdateData(TRUE))//这是检查而已
{
TRACE0("UpdateData failed during dialog termination.\n");
// the UpdateData routine will set focus to correct item
return;
}
EndDialog(IDOK);//**注

代替 CDialog::OnOK();也可,几人想过
dingchong 2003-10-11
  • 打赏
  • 举报
回复
真是神经病一个,别理会他~
let5flying 2003-10-11
  • 打赏
  • 举报
回复
这种问题还要高手来解答????
寒一个先……
wkoji 2003-10-11
  • 打赏
  • 举报
回复
guankaifu(疯牛),不服你都不行
我不是敢说话了,真搞不清楚你是在问问题还是辩论赛.
有些人之所以成为高手那是他们自己努力的结果,不是你或者谁白给的
大家来这里回问题也是出于好心,并不是为名或者为利.
帮了你是给你面子,不帮你也是理所当然的,
有什么理由因此指责他们?不要动不动就扣大帽子,什么真理,正义的.
真正的高手也不需要到这里来征求你的承认.
我觉得你的心理很有问题,光会指责别人不够谦虚,你自己呢???
guankaifu 2003-10-11
  • 打赏
  • 举报
回复
哈。。。因为你答不出来才这么说吧。。你既然来了就是高手。。可是你还答不出来。
这就说不过去了吧。。。
还是说你没编程的经验??
没有经验就要向人家学习。。老是看人家不爽。。。到底不爽在哪里了??
伤害了你自以为是高手的自尊心了???
哈。。。。之所以你看着不爽是因为你觉得自己是高手,,其他人都没你强吧。。你才看着不爽吧。。哈。。。心里不平衡的人很多啊。。
这样的帖子就能探测到那些人的内心。。
问题答不出来。。还非要把自己说成高手,,真的莫名其妙啊。。。
是高手你就说啊。。
真正的高手是很谦虚的。。谦虚的人是不会在意别人说他是不是高手的。。
所以也不会看出不”爽“来
看别人不爽之前请先门心自问。。自己是不是高手。。。有没有资格来鄙视别人。。
如果你觉得别人的才华在你眼前只不过是儿戏。。。而又得到别人的夸奖的时候。
你大可以理直气壮的看他不爽。。这也是正义和追求真理的表现。。。
而你连问题都回答不出来。。。。那么不爽从何而来。。。。又可以理直气壮吗??
或是为了掩饰自己的不解。。。故弄玄虚那???
atEleven 2003-10-11
  • 打赏
  • 举报
回复
这种问题是比较容易让初学者产生困惑.我以前也是.

不过还是要指出,这确实是很初级的问题.

而楼主以这样的心态来问问题的确是不可取的.
mygodtoo 2003-10-11
  • 打赏
  • 举报
回复
另付:

此问题太弱智。
You need MSDN.
mygodtoo 2003-10-11
  • 打赏
  • 举报
回复
Mfc源码
void CDialog::OnOK()
{
if (!UpdateData(TRUE))//这是检查而已
{
TRACE0("UpdateData failed during dialog termination.\n");
// the UpdateData routine will set focus to correct item
return;
}
EndDialog(IDOK);//**注
}
**
EndDialog
The EndDialog function destroys a modal dialog box, causing the system to end any processing for the dialog box.

bluebohe 2003-10-11
  • 打赏
  • 举报
回复
你要记住你来这里是问问题的,而不是讥笑别人的
WvW 2003-10-10
  • 打赏
  • 举报
回复

说实话你的标题看的很不爽!!!

如果你再次发个帖子, 将标题改写一下,我会告诉你是什么原因!
加载更多回复(9)

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧