-
Well, I've tried a lot of things, but can somebody please give me the code to make a form, with 2 labels on it, a text box and a command button.
P.S. I need to use CreateWindowEx in a module.
P.P.S. This IS advanced for me, but maybe not to Yonatan, Aaron Young, and/or Serge, and I'm sure others.
THANX
------------------
Tom Young, 14 Year Old
[email protected]
ICQ: 15743470
AIM: TomY10
PERL, JavaScript and VB Programmer
-
Try this. Create a project. Remove the default form and add a Module. Copy this code to your 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
Regards,
------------------
Serge
Software Developer
[email protected]
[email protected]
[This message has been edited by Serge (edited 11-04-1999).]
-
WOW I gotta say... those 3 guys (yonathan, Aaron Young and Serge) Impress me a lot!