【发布时间】:2014-10-29 06:15:36
【问题描述】:
是否可以混合使用 WinAPI 控件创建和 WinForms 功能?
这样的代码行不通。
HWND hWndButton = CreateWindowEx(NULL,
"BUTTON",
"OK",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
50,
220,
100,
24,
(HWND)Handle.ToInt32(),
(HMENU)101,
GetModuleHandle(NULL),
NULL);
System::Windows::Forms::Control^ control =
System::Windows::Forms::Control::FromHandle(System::IntPtr(hWndButton));
Controls->Add(control);
我需要这样做以便在 WinForms 应用程序中添加一些由其他公司编写的 C++ Win32 API 控件。
谢谢
【问题讨论】:
-
你好,看看这篇文章 (codeproject.com/Articles/12563/…) 可能对你有帮助。
-
当然,CreateWindowEx() 调用工作得很好。但是你不能用 Control 包装它,FromHandle() 将返回 nullptr。从按钮获取通知消息需要重写 WndProc()。使用这些 3rd 方控件究竟需要什么非常不清楚,从来没有人这样做过。你当然应该问他们。