【发布时间】:2013-07-26 22:44:17
【问题描述】:
为了将用户界面类(一个 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);'在它完成它必须做的事情之前不会返回,这没什么。问题是我不确定如何让它在运行时接受来自 WinMain 的输入(如果可能的话)。
-
这是非常基础的,请务必从您当地的图书馆中查阅有关 Winforms 编程的书籍。如果您希望运行除 UI 之外的其他代码,则需要使用线程。
标签: c++ .net winforms visual-c++ c++-cli