| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 407 人关注过本帖
标题:点解创建不了窗口类?
只看楼主 加入收藏
蓝魂
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2006-6-6
收藏
 问题点数:0 回复次数:0 
点解创建不了窗口类?
Public Class cApp
Private bCls As String
Private hwnd As IntPtr
Private Const WS_VISIBLE As Integer = &H10000000
Private Const WS_POPUP As Integer = &H80000000
Private Const WS_SYSMENU As Integer = &H80000
Private Const SM_CXSCREEN As Integer = 0
Private Const SM_CYSCREEN As Integer = 1
Private Const CS_DBLCLKS As Integer = &H8
Private Structure WNDCLASSEX
Public cbSize As Int32
Public hIconSm As Int32
Public hIcon As Int32
Public hCursor As Int32
Public hbrBackground As Int32
Public lpszMenuName As String
Public lpszClassName As String
Public cbClsExtra As Int32
Public cbWndExtra As Int32
Public hInstance As IntPtr
Public lpfnWndProc As WNDPROC
Public style As Int32
End Structure
Private Structure MSG
Public hwnd As Int32
Public time As Int32
Public pt As POINTAPI
Public wParam As Int32
Public lParam As Int32
Public message As Int32
End Structure
Private Structure POINTAPI
Public x As Long
Public y As Long
End Structure
Private Delegate Function WNDPROC(ByVal hWnd As IntPtr, ByVal message As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
Private Declare Function RegisterClassEx Lib "user32" Alias "RegisterClassExA" (ByRef pcWndClassEx As WNDCLASSEX) As Int32
Private Declare Function GetCurrentProcessId Lib "kernel32" () As IntPtr
Private Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hwnd As IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Int32, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Int32, ByVal x As Int32, ByVal y As Int32, ByVal nWidth As Int32, ByVal nHeight As Int32, ByVal hWndParent As Int32, ByVal hMenu As Int32, ByVal hInstance As IntPtr, ByVal lpParam As IntPtr) As IntPtr
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Int32) As Int32
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (ByRef lpMsg As MSG, ByVal hwnd As Int32, ByVal wMsgFilterMin As Int32, ByVal wMsgFilterMax As Int32, ByVal wRemoveMsg As Int32) As Int32
Private Declare Function TranslateMessage Lib "user32" (ByVal lpMsg As MSG) As Int32
Private Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" (ByVal lpMsg As MSG) As Int32
Private Declare Function WaitMessage Lib "user32" () As Int32
Private Declare Function GetMessage Lib "user32" Alias "GetMessageA" (ByVal lpMsg As MSG, ByVal hwnd As Int32, ByVal wMsgFilterMin As Int32, ByVal wMsgFilterMax As Int32) As Int32
Public Function RegClass(ByVal pCls As String)
Dim wndcls As New WNDCLASSEX
wndcls.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(wndcls)
wndcls.cbClsExtra = 0
wndcls.cbWndExtra = 0
wndcls.hInstance = GetCurrentProcessId
wndcls.lpszClassName = pCls
wndcls.style = CS_DBLCLKS
wndcls.lpfnWndProc = AddressOf MyProc
bCls = pCls
Return (RegisterClassEx(wndcls))
End Function
Public Function Create(ByVal ptitle As String)
hwnd = CreateWindowEx(0, bCls, ptitle, WS_VISIBLE Or WS_POPUP Or WS_SYSMENU, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), Nothing, Nothing, GetCurrentProcessId, Nothing)
Return (Not hwnd.ToInt32 = 0)
End Function
Private Function MyProc(ByVal hWnd As IntPtr, ByVal message As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
Return DefWindowProc(hWnd, message, wParam, lParam)
End Function
Public Function Run() As Boolean
Dim msgs As MSG
While (True)
If (PeekMessage(msgs, Nothing, 0, 0, 0)) Then
If (Not GetMessage(msgs, Nothing, 0, 0)) Then
Return msgs.wParam
End If
TranslateMessage(msgs)
DispatchMessage(msgs)
Else
WaitMessage()
End If
End While
Return True
End Function
End Class
搜索更多相关主题的帖子: 窗口 
2006-06-06 10:06
快速回复:点解创建不了窗口类?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013864 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved