C ++多个窗口形式 [英] c++ multiple windows forms

查看:104
本文介绍了C ++多个窗口形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

> HELLO全部,

我在使用c ++ Windows窗体时遇到问题...我想从第一个窗体和第二个窗体调用第二个窗体,当我按下按钮时,第一个窗体的文本或标签会发生变化.... plz plz我非常需要这个,这不是教程

>HELLO all,

i have problem using c++ windows forms...i want to call second form from first form and from second form when i press button the text or label at first form changes....plz plz i badly need this their is no tutorial

推荐答案

好吧,我很无聊-我会咬. (尽管会指出"plz plz"并没有真正被认为是礼貌的)对于讲英语的人来说,它的价值是-我们通常用句号(.)来表示句子的结尾,而首字母大写除了名称中的第一个字符外,句子中的字母. Txt spk或sms tlk通常在互联网的这个特定角落收不到很好的效果.回顾并遵守这些准则,您可能会在遇到任何问题时得到更好,更快的结果.

紧跟我在说明之后什么都不说的冲动,我将指出这些说明适用于基于Win32对话框的应用程序,使用Code :: Blocks
和gcc. (MFC或多或少需要采用相同的方法,但实现方式有所不同)

所以这就是你需要做的.

1)创建基于对话框的应用程序
2)在对话框中添加一个新的静态变量,确保它具有唯一的ID-例如,parentsStaticHwnd
3)使用新名称复制并粘贴DialogProcedure,例如ChildDialogProc
4)为额外的对话框和一个或两个按钮添加资源
5)在DialogProcedure中处理WM_INITDIALOG时,使用GetDlgItem获取在步骤2中添加的静态控件的HWND.-存储到全局变量中,如hInst(因为两个对话框都需要它,而不仅仅是从您的对话框中调用的一个) WinMain.
6)为您在第二个对话框中添加的按钮添加处理程序代码.只需设置您在步骤5中获得HWND的窗口的文本(主对话框中的静态窗口)
7)连接第二个对话框,以便在按下第一个窗体上的按钮时调用它-这是我的代码:
Okay, I''m bored - I''ll bite. (Though will point out that "plz plz" is not really considered polite) For what it''s worth, as english speakers - we generally signify the end of a sentence with a full-stop (.) and use capitals for the first letter in a sentence in addition to the first character in names. Txt spk or sms tlk are generally not received very well in this particular corner of the internet. Recall and observe these guidelines and you''l likely get better, faster results to any questions.

Against my urge to say nothing until after the instructions, I will point out that these instructions are for a Win32 dialog based app, using Code::Blocks
and gcc. (MFC would require the same approach more or less with some differences in implementation)

So here''s what you need to do.

1) Create dialog based app
2) Add a new static to the dialog, make sure it has a unique ID - e.g parentsStaticHwnd
3) Copy and paste the DialogProcedure with a new name e.g ChildDialogProc
4) Add resources for the extra dialog and a button or two
5) While handling WM_INITDIALOG in DialogProcedure, use GetDlgItem to get a HWND of the static control you added in step 2. - store into a global var, like hInst (since you need it for both dialogs, and not just the one invoked from your WinMain.
6) Add handler code for the button you added on the 2nd dialog. Just set the text of the window whose HWND you got in step 5 (the static on the main dialog)
7) Wire-up the 2nd dialog so that it is invoked when the button on the first form is pressed - here''s my code:
DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)MainDialogProc);



在那里,您已经完成并完成了它. 67行代码,38行resource.rc



There you have it, done and done. 67 lines of code, 38 lines of resource.rc


这篇关于C ++多个窗口形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆