Hallo,
da dies aber schon vorhanden ist ersetzt er es einfach.
klar, Du hast ja nur die eine Form. Wenn Du eine weitere brauchst, mußt Du eine weitere Form zur Laufzeit erzeugen.
Schreib Dir den Code in ein Modul, damit gehts … (hab’ ich gerade von ActveVB geholt …
)
Gruß, Rainer
'\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
'\* modMain.bas \*
'\* creates a simple window \*
'\* Programmed: Claus von der Burchard \*
'\* Last Change: 12.07.2004 14:29 \*
'\* Version: 1.0.0 \*
'\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
Option Explicit
'user32.dll
Private Declare Function RegisterClassEx Lib "user32.dll" Alias "RegisterClassExA" (ByRef pcWndClassEx As WNDCLASSEX) As Integer
Private Declare Function UnregisterClass Lib "user32.dll" Alias "UnregisterClassA" (ByVal lpClassName As String, ByVal hInstance As Long) As Long
Private Declare Function CreateWindowEx Lib "user32.dll" 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, ByRef lpParam As Any) As Long
Private Declare Function DefWindowProc Lib "user32.dll" Alias "DefWindowProcA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetMessage Lib "user32.dll" Alias "GetMessageA" (ByRef lpMsg As Msg, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
Private Declare Function DispatchMessage Lib "user32.dll" Alias "DispatchMessageA" (ByRef lpMsg As Msg) As Long
Private Declare Sub PostQuitMessage Lib "user32.dll" (ByVal nExitCode As Long)
Private Declare Function BeginPaint Lib "user32.dll" (ByVal hwnd As Long, ByRef lpPaint As PAINTSTRUCT) As Long
Private Declare Function EndPaint Lib "user32.dll" (ByVal hwnd As Long, ByRef lpPaint As PAINTSTRUCT) As Long
Private Declare Function LoadIcon Lib "user32.dll" Alias "LoadIconW" (ByVal hInstance As Long, ByVal lpIcon As Long) As Long
Private Declare Function LoadCursor Lib "user32.dll" Alias "LoadCursorW" (ByVal hInstance As Long, ByVal lpCursor As Long) As Long
'gdi32.dll
Private Declare Function TextOut Lib "gdi32.dll" Alias "TextOutW" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As Long, ByVal nCount As Long) As Long
Private Declare Function SetBkMode Lib "gdi32.dll" (ByVal hdc As Long, ByVal nBkMode As Long) As Long
Private Declare Function CreateFontA Lib "gdi32.dll" (ByVal nHeight As Long, ByVal nWidth As Long, ByVal nEscapement As Long, ByVal nOrientation As Long, ByVal fnWeight As Long, ByVal fdwItalic As Long, ByVal fdwUnderline As Long, ByVal fdwStrikeOut As Long, ByVal fdwCharSet As Long, ByVal fdwOutputPrecision As Long, ByVal fdwClipPrecision As Long, ByVal fdwQuality As Long, ByVal fdwPitchAndFamily As Long, ByVal lpszFace As String) As Long
Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
'----------------------------------------------------
Private Type WNDCLASSEX
cbSize As Long
style As Long
lpfnWndProc As Long
cbClsExtra As Long
cbWndExtra As Long
hInstance As Long
hIcon As Long
hCursor As Long
hbrBackground As Long
lpszMenuName As String
lpszClassName As String
hIconSm As Long
End Type
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type Msg
hwnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type PAINTSTRUCT
hdc As Long
fErase As Long
rcPaint As RECT
fRestore As Long
fIncUpdate As Long
rgbReserved As Byte
End Type
'----------------------------------------------------
Private Const ClassName As String = "MyWindowClass"
Private Const CS\_BYTEALIGNCLIENT As Long = &H1000
Private Const CS\_BYTEALIGNWINDOW As Long = &H2000
Private Const WS\_EX\_LEFT As Long = &H0&
Private Const WM\_DESTROY As Long = &H2
Private Const WM\_PAINT As Long = &HF&
Private Const WM\_COMMAND As Long = &H111
Private Const COLOR\_BTNFACE As Long = 15
Private Const WS\_CAPTION As Long = &HC00000
Private Const WS\_SYSMENU As Long = &H80000
Private Const WS\_THICKFRAME As Long = &H40000
Private Const WS\_MINIMIZEBOX As Long = &H20000
Private Const WS\_MAXIMIZEBOX As Long = &H10000
Private Const WS\_OVERLAPPED As Long = &H0&
Private Const WS\_VISIBLE As Long = &H10000000
Private Const WS\_CHILD As Long = &H40000000
Private Const WS\_OVERLAPPEDWINDOW As Long = (WS\_OVERLAPPED Or WS\_CAPTION Or WS\_SYSMENU Or WS\_THICKFRAME Or WS\_MINIMIZEBOX Or WS\_MAXIMIZEBOX)
Private Const TRANSPARENT As Long = 1
Private Const IDC\_ARROW As Long = 32512&
Private Const IDI\_APPLICATION As Long = 32512&
'----------------------------------------------------
Private m\_hWnd As Long
Private m\_hButton As Long
'----------------------------------------------------
Public Sub Main()
Dim WindowClass As WNDCLASSEX
'registering window class'
WindowClass.cbSize = LenB(WindowClass)
WindowClass.style = CS\_BYTEALIGNCLIENT Or CS\_BYTEALIGNWINDOW
WindowClass.lpfnWndProc = GetAddressOf(AddressOf WndProc)
WindowClass.cbClsExtra = 0
WindowClass.cbWndExtra = 0
WindowClass.hInstance = App.hInstance
WindowClass.hbrBackground = COLOR\_BTNFACE + 1
WindowClass.lpszMenuName = vbNullString
WindowClass.lpszClassName = ClassName
WindowClass.hIcon = LoadIcon(App.hInstance, IDI\_APPLICATION)
WindowClass.hCursor = LoadCursor(0, IDC\_ARROW)
Call RegisterClassEx(WindowClass)
'creating main window'
m\_hWnd = CreateWindowEx( \_
WS\_EX\_LEFT, \_
ClassName, \_
"Ein einfaches Fenster", \_
WS\_OVERLAPPEDWINDOW Or WS\_VISIBLE, \_
300, \_
300, \_
250, \_
200, \_
0, \_
0, \_
App.hInstance, \_
ByVal 0 \_
)
'creating button'
m\_hButton = CreateWindowEx( \_
WS\_EX\_LEFT, \_
"Button", \_
"Klick!", \_
WS\_VISIBLE Or WS\_CHILD, \_
10, \_
30, \_
90, \_
30, \_
m\_hWnd, \_
0, \_
0, \_
ByVal 0 \_
)
Call MsgLoop
Call UnregisterClass(WindowClass.lpszClassName, WindowClass.hInstance)
End Sub
Private Function MsgLoop()
Dim message As Msg, \_
ret As Long
Do
ret = GetMessage(message, 0, 0, 0)
If ret = 0 Then
Exit Do
Else
Call DispatchMessage(message)
End If
Loop
End Function
Private Function GetAddressOf(ByVal Address As Long)
GetAddressOf = Address
End Function
Public Function WndProc( \_
ByVal hwnd As Long, \_
ByVal uMsg As Long, \_
ByVal wParam As Long, \_
ByVal lParam As Long \_
) As Long
'Checking messages before default window proc'
Select Case uMsg
Case WM\_DESTROY
Call PostQuitMessage(0)
Case WM\_PAINT
'print 'Hallo!' on the window
Dim paintdata As PAINTSTRUCT, \_
hFont As Long
Call BeginPaint(hwnd, paintdata)
Call SetBkMode(paintdata.hdc, TRANSPARENT)
hFont = CreateFontA(-11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
Call DeleteObject(SelectObject(paintdata.hdc, hFont))
Call TextOut(paintdata.hdc, 10, 10, StrPtr("Hallo!"), 6)
Call EndPaint(hwnd, paintdata)
Exit Function
Case WM\_COMMAND
If lParam = m\_hButton Then
Call MsgBox("Button geklickt!", vbOKOnly Or vbInformation, "Pling!")
Exit Function
End If
End Select
'default window proc'
WndProc = DefWindowProc(hwnd, uMsg, wParam, lParam)
'add after message checking here if necessary'
End Function