-
I'm writing a program that will run on Windows 95 and up without an install package.
It will run off of a floppy to collect system info and user info.
I need command buttons, labels, and text box.
I've created a form in a module with CreateWindowEx but can someone point me to the correct api's for
creating the labels, buttons, and text box?
-
Button -- class "BUTTON"
Text Box -- class "EDIT"
Label -- class "STATIC"
Check the Platform SDK for the exact details on the extra window styles for each of these classes.
-
Code:
Private 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
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const WS_CHILD = &H40000000
Private Const WS_VISIBLE = &H10000000
Private Const WS_EX_CLIENTEDGE = &H200&
Private hWndBtn As Long
Private hWndEdit As Long
Private hWndLabel As LongPrivate Sub Form_Load()
' Now add this code to the create them. Usually you
' would do this when the WM_CREATE message is
' triggered
hWndBtn = CreateWindowEx(0, "Button", "MyButton", WS_CHILD Or WS_VISIBLE, 32, 32, 64, 64, hwnd, 0, App.hInstance, 0)
hWndEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", "MyEdit", WS_CHILD Or WS_VISIBLE, 200, 10, 100, 100, hwnd, 0, App.hInstance, 0)
hWndBtn = CreateWindowEx(WS_EX_CLIENTEDGE, "Static", "MyLabel", WS_CHILD Or WS_VISIBLE, 10, 100, 100, 40, hwnd, 0, App.hInstance, 0)
-
Thanks for the code, but what else will I need to capture the button click and shell out a exe, and capture the info from the textbox?
By the way, if there is no standard form, just the one created by the api call, is there still the Form_Load event in your code you posted?
-
Well, I assume you have your "Formless window" already made and the code as well. For this, you must also have a WindowProc function, which is specified in the lpfnWndProc variable of the WNDCLASEX structure.
To capture the click of a button, you need to handle the WM_COMMAND message. If the handle (stored in the lParam argument) is the same as the button, then it was clicked. Here is a small example:
Code:
Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If wMsg = WM_COMMAND Then
If lParam = hWnd_Btn Then MsgBox "Button was clicked!"
End If
WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
End Function