|
-
Jul 17th, 2000, 05:00 PM
#1
Thread Starter
Lively Member
Can someone please send me an example on how to use CreateWindow ?
Please!
-
Jul 17th, 2000, 05:20 PM
#2
Frenzied Member
The Beast advice I have is not to use it. If you're going to use it you have to set up your own Message Handler, this is essentially a loop of code that shunts messages along to your window Procedure, which you have to write yourself, which is a nightmare on it's own. If you Find an old book on windows programming it'll explain it all, it'll be in C but that's the least of your worries. essentially the stuff you have to do doesn't work too well with VB, especially as you can use normal VB methods to do anything CreateWindow Can do. WHat are you trying to use it for? There'll be a much better way ruond.
-
Jul 17th, 2000, 05:23 PM
#3
Thread Starter
Lively Member
Okay!
I was just wondering how to use it... =)
What it does and stuff like that...but okay!!
-
Jul 17th, 2000, 05:28 PM
#4
CreateWindow API
I agree with Sam on this one, but neverthess if you still want it, here is a piece of code Serge gave me a while back.
Put this in a module.
Code:
Declare Function RegisterClass Lib "user32" Alias "RegisterClassA" (Class As WNDCLASS) As Long
Declare Function UnregisterClass Lib "user32" Alias "UnregisterClassA" (ByVal lpClassName As String, ByVal hInstance As Long) As Long
Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Sub PostQuitMessage Lib "user32" (ByVal nExitCode As Long)
Declare Function GetMessage Lib "user32" Alias "GetMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
Declare Function TranslateMessage Lib "user32" (lpMsg As Msg) As Long
Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" (lpMsg As Msg) As Long
Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Any) As Long
Type WNDCLASS
style As Long
lpfnwndproc As Long
cbClsextra As Long
cbWndExtra2 As Long
hInstance As Long
hIcon As Long
hCursor As Long
hbrBackground As Long
lpszMenuName As String
lpszClassName As String
End Type
Type POINTAPI
x As Long
y As Long
End Type
Type Msg
hWnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Public Const COLOR_WINDOW = 5
Public Const BM_CLICK = 245
Public Const CS_VREDRAW = &H1
Public Const CS_HREDRAW = &H2
Public Const CS_KEYCVTWINDOW = &H4
Public Const WS_OVERLAPPED = &H0&
Public Const WS_POPUP = &H80000000
Public Const WS_CHILD = &H40000000
Public Const WS_MINIMIZE = &H20000000
Public Const WS_VISIBLE = &H10000000
Public Const WS_DISABLED = &H8000000
Public Const WS_CLIPSIBLINGS = &H4000000
Public Const WS_CLIPCHILDREN = &H2000000
Public Const WS_MAXIMIZE = &H1000000
Public Const WS_CAPTION = &HC00000 ' WS_BORDER Or WS_DLGFRAME
Public Const WS_BORDER = &H800000
Public Const WS_DLGFRAME = &H400000
Public Const WS_VSCROLL = &H200000
Public Const WS_HSCROLL = &H100000
Public Const WS_SYSMENU = &H80000
Public Const WS_THICKFRAME = &H40000
Public Const WS_GROUP = &H20000
Public Const WS_TABSTOP = &H10000
Public Const WS_MINIMIZEBOX = &H20000
Public Const WS_MAXIMIZEBOX = &H10000
Public Const WS_TILED = WS_OVERLAPPED
Public Const WS_ICONIC = WS_MINIMIZE
Public Const WS_SIZEBOX = WS_THICKFRAME
Public Const WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX)
Public Const WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW
Public Const WS_POPUPWINDOW = (WS_POPUP Or WS_BORDER Or WS_SYSMENU)
Public Const WS_CHILDWINDOW = (WS_CHILD)
Public Const WS_EX_CLIENTEDGE = 512
Public Const WM_DESTROY = &H2
Public Const WM_MOVE = &H3
Public Const WM_SIZE = &H5
Public Const SW_HIDE = 0
Public Const SW_SHOWNORMAL = 1
Public Const SW_NORMAL = 1
Public Const SW_SHOW = 5
Public Const SW_MINIMIZE = 6
Public Const IDC_ARROW = 32512&
Public Const GWL_WNDPROC = -4
Public lHwndButton As Long
Public lHwndLabel2 As Long
Public lHwndLabel1 As Long
Public lHwndTextbox As Long
Public hWndForm As Long
Public Sub Main()
Dim lStyle As Long
'Register Class
Call RegisterClassProc
'Create a FORM
lStyle = WS_OVERLAPPED Or WS_SYSMENU Or WS_CLIPCHILDREN Or WS_CLIPSIBLINGS
hWndForm = CreateWindowEx(0, "MyCoolClass", "Dynamic Form using CreateEx API from Serge", lStyle, 0, 0, 400, 300, 0, 0, App.hInstance, ByVal 0&)
'Create controls on the form
lHwndLabel1 = CreateWindowEx(0, "Static", "New Label1", WS_CHILD, 50, 25, 100, 25, hWndForm, 0, App.hInstance, ByVal 0&)
lHwndLabel2 = CreateWindowEx(0, "Static", "New Label2", WS_CHILD, 50, 55, 100, 25, hWndForm, 0, App.hInstance, ByVal 0&)
lHwndButton = CreateWindowEx(0, "Button", "New Button", WS_CHILD, 50, 90, 100, 25, hWndForm, 0, App.hInstance, ByVal 0&)
lHwndTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, "edit", "Sample Text", WS_CHILD, 50, 125, 100, 25, hWndForm, 0, App.hInstance, ByVal 0&)
If hWndForm <> 0 Then ShowWindow hWndForm, SW_SHOWNORMAL
'Show controls on the new form
ShowWindow lHwndTextbox, SW_SHOWNORMAL
ShowWindow lHwndButton, SW_SHOWNORMAL
ShowWindow lHwndLabel1, SW_SHOWNORMAL
ShowWindow lHwndLabel2, SW_SHOWNORMAL
MessageProc
End Sub
Private Sub MessageProc()
Dim ms As Msg
Do While GetMessage(ms, 0, 0, 0)
TranslateMessage ms
DispatchMessage ms
Loop
End Sub
Function ProcessWndProc(ByVal lWndProc As Long) As Long
ProcessWndProc = lWndProc
End Function
Public Sub RegisterClassProc()
Dim ws As WNDCLASS
'Prepare Class to be registered
ws.style = CS_HREDRAW + CS_VREDRAW
ws.lpfnwndproc = ProcessWndProc(AddressOf WindowProc)
ws.cbClsextra = 0
ws.cbWndExtra2 = 0
ws.hInstance = App.hInstance
ws.hIcon = 0
ws.hCursor = LoadCursor(0, IDC_ARROW)
ws.hbrBackground = COLOR_WINDOW
ws.lpszMenuName = 0
ws.lpszClassName = "MyCoolClass"
'Register Class
RegisterClass ws
End Sub
Private Function WindowProc(ByVal hWnd As Long, ByVal message As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case message
Case WM_DESTROY
PostQuitMessage (0)
UnregisterClass "MyCoolClass", App.hInstance
End Select
WindowProc = DefWindowProc(hWnd, message, wParam, lParam)
End Function
-
Jul 17th, 2000, 05:34 PM
#5
Thread Starter
Lively Member
Oh!
Okay, so if I asked you, should I use Forms or should I create my own windows ?
Then you would tell me to use Forms, right ?
But which is the best to use ?
-
Jul 17th, 2000, 05:44 PM
#6
It's better to just add Form's normally without using CreateWindow. It's much less of a hassle.
-
Jul 17th, 2000, 06:09 PM
#7
Thread Starter
Lively Member
Okay....
Please read my other Questions "CreateMenu API ?" and "Extract Icons ? How ?"
-
Jul 17th, 2000, 06:29 PM
#8
Yes, I answered the one about Extract Icon's.
CreateMenu just creates a Menu and returns the handle to the new menu. You have to use additional API's like InsertMenu, AppendMenu, DrawMenuBar, etc. to add the actual Menu's.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|