从Windows窗体外部(从int WINAPI WinMain)调用Windows窗体方法
call a Windows Forms method from outside Windows Forms (from int WINAPI WinMain)
为了将用户界面类(一个Windows窗体类)与程序的其余部分分离,我试图从int WINAPI WinMain()调用Windows窗体方法
例如,我正在尝试以下操作:
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
Application::EnableVisualStyles();
UserInterface1 ^myInterface = gcnew UserInterface1();
String ^ picture1 = "img1";
String ^ picture2 = "img2";
Application::Run(myInterface);
Bitmap^ B = gcnew Bitmap (512,512);
//user defined class that reads an image from a file
PImage PI(picture1);
//a Windows Forms method that updates the image displayed in a pictureBox element
myInterface->ModifyDisplay (B, PI);
//user defined class that reads an image from a file
PImage PI2(picture2);
//a Windows Forms method that updates the image displayed in a pictureBox element
myInterface->ModifyDisplay (B, PI2);
return 0;
}
不用说,它并没有像现在这样工作,我不确定我试图做的事情是否可行,因为我对.Net编程还很陌生。
它看起来像"Application::Run(myInterface);"在完成它必须做的事情之前不会返回,这不是
这不是什么。Application::Run
最重要的是启动Windows事件消息泵。这个事件循环使您的应用程序保持活动和运行。Application::Run
将仅在该循环退出时返回。
当您关闭主窗体或试图关闭任务管理器等的流程时,事件循环通常会退出。
这意味着当Application::Run
返回时,您的myInterface
表单已经关闭,这使得它下面的其余代码变得无用。您可以将该代码移动到类似Form
的Load
事件中。
确切地说,"Application::Run()"之后的代码将在表单关闭时运行。我建议您创建两个表单,例如"Form1"answers"Form2"(使用线程是另一种方式,但这更容易)。
使用"Form1"作为隐藏的基本表单,它用于通过从文件中获取图像来更新应用程序。
使用"Form2"作为UserInterface1。要做到这一点,如果你是新手,你应该在"Form1"中运行"Form2",如下所示:
// Inside Form1.
#include "Form2.h"
Form2 ^openForm2 = gcnew Form2();
openForm2->Show();
最后,您可以在Form1中运行ModifyDisplay函数。
openForm->ModifyDisplay();
相关文章:
- 如何在Windows窗体应用程序中打开txt文件并将行导入文本框
- 我可以在 vb.net Windows 窗体应用程序中使用 COLECONTROLModule 吗?
- std::线程在 Windows 窗体中不可用
- 无法在 Visual Studio 2015 中创建 Windows 窗体
- 如何在 Windows 窗体应用程序 (C++) 中使用固定宽度整数
- Windows窗体应用程序无法播放视频[VLC ActiveX插件和IE Web插件v2]
- Windows窗体作为非托管应用程序的子窗口
- 生成窗体的控制台应用程序(Windows窗体)
- 何时销毁 Windows 窗体数据源
- 文本框为空时,C++Windows窗体应用程序出现未处理的异常错误
- 文本框为空时C++ Windows 窗体应用程序未处理的异常错误
- C++ Windows 应用程序窗体无法进行前向声明
- 是Windows窗体应用程序(在visual studio c++中)自动c++/CLI
- 如何检查是否所有字段都已填写?[C++,VS 2015,Windows窗体]
- 使用Visual Studio c++的Windows窗体应用程序,该应用程序链接到CUDA项目
- 使用windows窗体在richtextbox中设置斜体的示例
- 在 Windows 窗体中使用 C++ 类会导致 System.AccessViolationException
- 可视化如何将项目 win32 控制台应用程序转换为C++ Windows 窗体
- DDX 数据绑定与 Windows 窗体找不到类方法
- 在调用不同类的函数时刷新 Windows 窗体