为什么CreateWindowEx返回0

发布于 2024-08-21 22:43:53 字数 1253 浏览 4 评论 0原文

VB.NET 2008 Express

Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Integer, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hwndParent As Integer, ByVal hMenu As Integer, ByVal hInstance As Integer, ByRef lpParam As Object) As Integer

Private Const WS_EX_APPWINDOW = &H40000
Private Const WS_EX_WINDOWEDGE = &H100&
Private Const WS_SYSMENU = &H80000
Private Const WS_CAPTION = &HC00000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_THICKFRAME = &H40000
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX)

Dim AppHandle As Int32 = System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32()

Dim WindowHandle as integer = CreateWindowEx(WS_EX_APPWINDOW Or WS_EX_WINDOWEDGE, "MyWindow", "MyTitle", WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, 0, 0, AppHandle, Nothing)

CreateWindowEx 返回 0?

VB.NET 2008 Express

Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Integer, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hwndParent As Integer, ByVal hMenu As Integer, ByVal hInstance As Integer, ByRef lpParam As Object) As Integer

Private Const WS_EX_APPWINDOW = &H40000
Private Const WS_EX_WINDOWEDGE = &H100&
Private Const WS_SYSMENU = &H80000
Private Const WS_CAPTION = &HC00000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_THICKFRAME = &H40000
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX)

Dim AppHandle As Int32 = System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32()

Dim WindowHandle as integer = CreateWindowEx(WS_EX_APPWINDOW Or WS_EX_WINDOWEDGE, "MyWindow", "MyTitle", WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, 0, 0, AppHandle, Nothing)

CreateWindowEx returns 0?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

友欢 2024-08-28 22:43:53

调用 CreateWindowEx 后需要检查是否为 NULL,如果是,则可以立即调用 Marshal.GetLastWin32Error 了解原因。

You need to check for NULL after calling CreateWindowEx, and if it is, you can then immediately call Marshal.GetLastWin32Error for the reason why.

多孤肩上扛 2024-08-28 22:43:53

可能的原因是您忘记使用RegisterClass/Ex()注册“MyWindow”窗口类,没有正确设置窗口过程或没有正确处理WM_CREATE消息。另外,您的 P/Invoke 声明是错误的,它无法在 64 位操作系统上运行。

不要自己编写此类代码,Windows 窗体是 CreateWindowEx() 的一个非常好的包装器。

Possible reasons are that you forgot to register the "MyWindow" window class with RegisterClass/Ex(), didn't set the window procedure correctly or don't properly handle the WM_CREATE message. Also, your P/Invoke declaration is wrong, it won't work on 64-bit operating systems.

Don't write this kind of code yourself, Windows Forms is a very nice wrapper around CreateWindowEx().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文