【问题标题】:Mix WinForms and WinAPI controls混合 WinForms 和 WinAPI 控件
【发布时间】: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 方控件究竟需要什么非常不清楚,从来没有人这样做过。你当然应该问他们。

标签: winforms winapi c++-cli


【解决方案1】:

您可以覆盖 Control 类中的 CreateParams 属性以指定所需的类名。详细解释见this博文。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-15
    • 2011-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    相关资源
    最近更新 更多