我有两个项目,一个是win32程序,另一个是c++/cli动态库。
在c++/cli动态库中,导出这个函数:
using namespace System::Windows::Forms;
using namespace System::Diagnostics;
LIB_API void Create(HWND parent){
auto c = gcnew TextBox();
c->Location = System::Drawing::Point(0, 0);
c->Name = "textBox1";
c->Size = System::Drawing::Size(100, 21);
c->Parent = Control::FromHandle(IntPtr(parent));
}
当win32程序调用该函数时,win创建一个
TextBox
控件。
但这不起作用。
调试日志显示
TextBox
已创建,但使用spy++找不到它。
我自己解决了这个问题。
using namespace System::Windows::Forms;
using namespace System::Diagnostics;
LIB_API void Create(HWND parent){
auto c = gcnew TextBox();
//c->Location = System::Drawing::Point(0, 0);
c->Name = "textBox1";
//c->Size = System::Drawing::Size(100, 21);
//c->Parent = Control::FromHandle(IntPtr(parent));
::SetParent((HWND)c->Handle.ToPointer(), parent);
::MoveWindow((HWND)c->Handle.ToPointer(), 0, 0, 200, 200, true);
}
``