如何在dialog创建并绘制完成后第一时间运行我的函数

null.space 2017-04-27 09:39:55
我想在dialog绘制完成后第一时间运行我的函数,但是并没有找到像WM_PAINT_FINISH之类的消息,所以我在dialog的回调函数里应该怎么写?
...全文
328 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
schlafenhamster 2017-05-06
  • 打赏
  • 举报
回复
“这个不是MFC吗?” MFC 是 api 的 包装, win32 是 DialogBox DialogBoxIndirect DialogBoxIndirectParam DialogBoxParam 。。。
null.space 2017-05-05
  • 打赏
  • 举报
回复
引用 17 楼 schlafenhamster 的回复:
因为 "CxxxDialog::OnPaint” 退出时,子窗口 可能 还没有 绘制。" 所以必须 在对话框 OnPaint 中 把 所有 子窗口(控件)都 绘制 出来。(UpdateWindow))
没懂。。。
null.space 2017-05-05
  • 打赏
  • 举报
回复
引用 20 楼 schlafenhamster 的回复:
1 一开始 void CAboutDlg::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here // Do not call CDialog::OnPaint() for painting messages } // 注意 CPaintDC dc(this); 这句 将 给 对话框 里 所有 控件 发 Invalidate ,这样 所有控件 的 窗口 将 成为 ‘无效区’ 2 接着 // TODO: 中你加入 绘制 对话框 本身的 语句。 3 然后 OnPaint 退出。 这时 所有 子窗口(控件)是 无效的 ,所以 系统 会 进入 各个控件的 绘制 中(OnPaint) 如果你在 对话框 的 OnPaint 中 运行 别的函数。 控件 就可能 没有 绘制 完
这个不是MFC吗?
schlafenhamster 2017-05-05
  • 打赏
  • 举报
回复
1 一开始 void CAboutDlg::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here // Do not call CDialog::OnPaint() for painting messages } // 注意 CPaintDC dc(this); 这句 将 给 对话框 里 所有 控件 发 Invalidate ,这样 所有控件 的 窗口 将 成为 ‘无效区’ 2 接着 // TODO: 中你加入 绘制 对话框 本身的 语句。 3 然后 OnPaint 退出。 这时 所有 子窗口(控件)是 无效的 ,所以 系统 会 进入 各个控件的 绘制 中(OnPaint) 如果你在 对话框 的 OnPaint 中 运行 别的函数。 控件 就可能 没有 绘制 完
赵4老师 2017-05-03
  • 打赏
  • 举报
回复
《深入浅出MFC》?
null.space 2017-05-02
  • 打赏
  • 举报
回复
引用 6 楼 schlafenhamster 的回复:
初始化一个Timer (200ms) 在OnTimer中 killtimer, 后 执行你的 程序。
这个方法我也考虑过,但是有延迟的话不是很舒服。。。
null.space 2017-05-02
  • 打赏
  • 举报
回复
引用 4 楼 zhao4zhong1 的回复:
OnInitDialog
引用 5 楼 VisualEleven 的回复:
你可以在对话框窗口初始化函数中添加你的代码即可。
我不用mfc哈。。
null.space 2017-05-02
  • 打赏
  • 举报
回复
引用 1 楼 swwllx 的回复:
添加WM_PAINT消息函数啊
引用 2 楼 worldy 的回复:
OnPaint是一个随机调用的函数(WM_PAINT消息发生在如何需要重绘的时候),为什么你的函数需要在绘制完成后调用? 如果只是这样的要求,你在OnPaint实现的最后一条指令调用你的函数就是 void OnPaint() { .................//绘制窗口 你的特殊函数(....); }
我可能没说清楚。。。我的函数需要绘制完成后再调用的原因是,这个函数会运行很长一段时间,因此我希望我一打开这个程序,程序会先绘制完自己的界面,绘制完之后再运行我的函数。但是实际上我并不想和WM_PAINT消息扯上关系,因为一旦和WM_PAINT扯上关系,那么每次绘制完之后都会运行一遍我的函数。我仅需要程序启动后、界面初始化完成后,运行一遍我的程序。 举个栗子就拿电脑版的QQ来说吧,QQ有个自动登录,开启自动登录后,一打开qq就会第一时间自己自动登录qq,不需要我手动点击“登录”。我想实现的和这个一样,打开后自动运行我的功能。 另外我不用mfc。。。。
schlafenhamster 2017-05-02
  • 打赏
  • 举报
回复
不是 “CDialog::OnInitDialog” 是“CxxxDialog::OnPaint” 退出时,子窗口 可能 还没有 绘制。最好是 单次 timer。
schlafenhamster 2017-05-02
  • 打赏
  • 举报
回复
“CDialog::OnInitDialog” 退出时, 子窗口 可能 还没有 绘制。最好是 单次 timer。
赵4老师 2017-05-02
  • 打赏
  • 举报
回复
引用 8 楼 DaSo_CSDN 的回复:
[quote=引用 4 楼 zhao4zhong1 的回复:] OnInitDialog
引用 5 楼 VisualEleven 的回复:
你可以在对话框窗口初始化函数中添加你的代码即可。
我不用mfc哈。。[/quote] 你以为你不用MFC,MFC的帮助就对你没用了? CDialog::OnInitDialog virtual BOOL OnInitDialog( ); Return Value Specifies whether the application has set the input focus to one of the controls in the dialog box. If OnInitDialog returns nonzero, Windows sets the input focus to the first control in the dialog box. The application can return 0 only if it has explicitly set the input focus to one of the controls in the dialog box. Remarks This member function is called in response to the WM_INITDIALOG message. This message is sent to the dialog box during the Create, CreateIndirect, or DoModal calls, which occur immediately before the dialog box is displayed. Override this member function if you need to perform special processing when the dialog box is initialized. In the overridden version, first call the base class OnInitDialog but disregard its return value. You will normally return TRUE from your overridden member function. Windows calls the OnInitDialog function via the standard global dialog-box procedure common to all Microsoft Foundation Class Library dialog boxes, rather than through your message map, so you do not need a message-map entry for this member function. CDialog Overview | Class Members | Hierarchy Chart See Also CDialog::Create, CDialog::CreateIndirect,WM_INITDIALOG WM_INITDIALOG The WM_INITDIALOG message is sent to the dialog box procedure immediately before a dialog box is displayed. Dialog box procedures typically use this message to initialize controls and carry out any other initialization tasks that affect the appearance of the dialog box. WM_INITDIALOG hwndFocus = (HWND) wParam; // handle of control to receive focus lInitParam = lParam; // initialization parameter Parameters hwndFocus Value of wParam. Identifies the control to receive the default keyboard focus. The system assigns the default keyboard focus only if the dialog box procedure returns TRUE. lInitParam Value of lParam. Specifies additional initialization data. This data is passed to the system as the lParamInit parameter in a call to the CreateDialogIndirectParam, CreateDialogParam, DialogBoxIndirectParam, or DialogBoxParam function used to create the dialog box. For property sheets, this parameter is a pointer to thePROPSHEETPAGE structure used to create the page. This parameter is zero if any other dialog box creation function is used. Return Values The dialog box procedure should return TRUE to direct the system to set the keyboard focus to the control given by hwndFocus. Otherwise, it should return FALSE to prevent the system from setting the default keyboard focus. The dialog box procedure should return the value directly. The DWL_MSGRESULT value set by the SetWindowLong function is ignored. Remarks The control to receive the default keyboard focus is always the first control in the dialog box that is visible, not disabled, and that has the WS_TABSTOP style. When the dialog box procedure returns TRUE, the system checks the control to ensure that the procedure has not disabled it. If it has been disabled, the system sets the keyboard focus to the next control that is visible, not disabled, and has the WS_TABSTOP. An application can return FALSE only if it has set the keyboard focus to one of the controls of the dialog box. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Requires version 1.0 or later. Header: Declared in winuser.h. See Also Dialog Boxes Overview, Dialog Box Messages, CreateDialogIndirectParam, CreateDialogParam, DialogBoxIndirectParam, DialogBoxParam,PROPSHEETPAGE, SetFocus
worldy 2017-05-02
  • 打赏
  • 举报
回复
引用 7 楼 DaSo_CSDN 的回复:
[quote=引用 1 楼 swwllx 的回复:] 添加WM_PAINT消息函数啊
引用 2 楼 worldy 的回复:
OnPaint是一个随机调用的函数(WM_PAINT消息发生在如何需要重绘的时候),为什么你的函数需要在绘制完成后调用? 如果只是这样的要求,你在OnPaint实现的最后一条指令调用你的函数就是 void OnPaint() { .................//绘制窗口 你的特殊函数(....); }
我可能没说清楚。。。我的函数需要绘制完成后再调用的原因是,这个函数会运行很长一段时间,因此我希望我一打开这个程序,程序会先绘制完自己的界面,绘制完之后再运行我的函数。但是实际上我并不想和WM_PAINT消息扯上关系,因为一旦和WM_PAINT扯上关系,那么每次绘制完之后都会运行一遍我的函数。我仅需要程序启动后、界面初始化完成后,运行一遍我的程序。 举个栗子就拿电脑版的QQ来说吧,QQ有个自动登录,开启自动登录后,一打开qq就会第一时间自己自动登录qq,不需要我手动点击“登录”。我想实现的和这个一样,打开后自动运行我的功能。 另外我不用mfc。。。。[/quote] 设置一个成员变量或者全局变量,BOOL bDone=FALSE void OnPaint() { .................//绘制窗口 if(!bDone) { 你的特殊函数(....); bDone=TRUE;//第一次执行后,以后就不再执行 } }
zgl7903 2017-05-02
  • 打赏
  • 举报
回复
WM_PAINT 的消息响应中调用你的函数
schlafenhamster 2017-05-02
  • 打赏
  • 举报
回复
"但是有延迟的话不是很舒服" 那 200ms 是 paint 用的 ,没有 延迟。可改 小点。
schlafenhamster 2017-05-02
  • 打赏
  • 举报
回复
因为 "CxxxDialog::OnPaint” 退出时,子窗口 可能 还没有 绘制。" 所以必须 在对话框 OnPaint 中 把 所有 子窗口(控件)都 绘制 出来。(UpdateWindow))
null.space 2017-05-02
  • 打赏
  • 举报
回复
引用 13 楼 zhao4zhong1 的回复:
[quote=引用 8 楼 DaSo_CSDN 的回复:] [quote=引用 4 楼 zhao4zhong1 的回复:] OnInitDialog
引用 5 楼 VisualEleven 的回复:
你可以在对话框窗口初始化函数中添加你的代码即可。
我不用mfc哈。。[/quote] 你以为你不用MFC,MFC的帮助就对你没用了? CDialog::OnInitDialog virtual BOOL OnInitDialog( ); Return Value Specifies whether the application has set the input focus to one of the controls in the dialog box. If OnInitDialog returns nonzero, Windows sets the input focus to the first control in the dialog box. The application can return 0 only if it has explicitly set the input focus to one of the controls in the dialog box. Remarks This member function is called in response to the WM_INITDIALOG message. This message is sent to the dialog box during the Create, CreateIndirect, or DoModal calls, which occur immediately before the dialog box is displayed. Override this member function if you need to perform special processing when the dialog box is initialized. In the overridden version, first call the base class OnInitDialog but disregard its return value. You will normally return TRUE from your overridden member function. Windows calls the OnInitDialog function via the standard global dialog-box procedure common to all Microsoft Foundation Class Library dialog boxes, rather than through your message map, so you do not need a message-map entry for this member function. CDialog Overview | Class Members | Hierarchy Chart See Also CDialog::Create, CDialog::CreateIndirect,WM_INITDIALOG WM_INITDIALOG The WM_INITDIALOG message is sent to the dialog box procedure immediately before a dialog box is displayed. Dialog box procedures typically use this message to initialize controls and carry out any other initialization tasks that affect the appearance of the dialog box. WM_INITDIALOG hwndFocus = (HWND) wParam; // handle of control to receive focus lInitParam = lParam; // initialization parameter Parameters hwndFocus Value of wParam. Identifies the control to receive the default keyboard focus. The system assigns the default keyboard focus only if the dialog box procedure returns TRUE. lInitParam Value of lParam. Specifies additional initialization data. This data is passed to the system as the lParamInit parameter in a call to the CreateDialogIndirectParam, CreateDialogParam, DialogBoxIndirectParam, or DialogBoxParam function used to create the dialog box. For property sheets, this parameter is a pointer to thePROPSHEETPAGE structure used to create the page. This parameter is zero if any other dialog box creation function is used. Return Values The dialog box procedure should return TRUE to direct the system to set the keyboard focus to the control given by hwndFocus. Otherwise, it should return FALSE to prevent the system from setting the default keyboard focus. The dialog box procedure should return the value directly. The DWL_MSGRESULT value set by the SetWindowLong function is ignored. Remarks The control to receive the default keyboard focus is always the first control in the dialog box that is visible, not disabled, and that has the WS_TABSTOP style. When the dialog box procedure returns TRUE, the system checks the control to ensure that the procedure has not disabled it. If it has been disabled, the system sets the keyboard focus to the next control that is visible, not disabled, and has the WS_TABSTOP. An application can return FALSE only if it has set the keyboard focus to one of the controls of the dialog box. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Requires version 1.0 or later. Header: Declared in winuser.h. See Also Dialog Boxes Overview, Dialog Box Messages, CreateDialogIndirectParam, CreateDialogParam, DialogBoxIndirectParam, DialogBoxParam,PROPSHEETPAGE, SetFocus [/quote] 然而WM_INITDIALOG我早就试过了,但是这个消息只是告诉Windows要初始化dialog,并不是dialog已经初始化完成。在dialog回调函数的WM_INITDIALOG消息处理里加上我的函数之后,依然是先运行我的函数,然后再绘制dialog
schlafenhamster 2017-04-29
  • 打赏
  • 举报
回复
初始化一个Timer (200ms) 在OnTimer中 killtimer, 后 执行你的 程序。
赵4老师 2017-04-28
  • 打赏
  • 举报
回复
OnInitDialog
叶恭介叶恭介 2017-04-28
  • 打赏
  • 举报
回复
无理问题。
worldy 2017-04-28
  • 打赏
  • 举报
回复
OnPaint是一个随机调用的函数(WM_PAINT消息发生在如何需要重绘的时候),为什么你的函数需要在绘制完成后调用? 如果只是这样的要求,你在OnPaint实现的最后一条指令调用你的函数就是 void OnPaint() { .................//绘制窗口 你的特殊函数(....); }
加载更多回复(2)

16,472

社区成员

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

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

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