Problem mir Private declare
12.11.2003 17:48:21
chris b.
Hoffe es gibt eine Lösung und ihr könnt mir helfen.. es geht um folgendes ich habe eine Userform
dieser Code Leuft jetzt habe ich auch aus dem forum einen code bekommen mit dem ich die userform dauerhaft im vordergrund halten kann. Dieser code->
Option Explicit
Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub UserForm_Activate()
SetWindowPos FindWindow(vbNullString, Me.Caption), -1, 0, 0, 0, 0, 83
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode <> 1 Then Cancel = 1
End Sub
jetzt das Probelm in meiner userform habe ich auch schon Declare Anweisungen stehen auch eine die FindWindow heißt und die beisen sich.
einmal diese aus dem neuen Code ->
"Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long"
und noch die alte die ich schon hatte->
"Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long"
die unterscheiden sich hier habe ich gesehen
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long"
in der einen sagt der code dim as string und im andere steht dim as long.
Wenn ich nur eine Declare anweisung von den beiden benutze kommt auch ein fehler...
Ich hoffe es gibt eine einfache lösung und ihr könnt mir helfen..
Vielen Dank Christian
p.S hier ist noch falls benötigt der alte code der schon in der userform ist...:>
Public x1 As String
Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal wIndx As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2
Const GWL_STYLE = (-16)
Const WS_VISIBLE = &H10000000
Const WS_BORDER = &H800000
Dim m1
Public cb As String
Dim whandle
Private Function GetWindowTitle(ByVal hWnd As Long) As String
Dim lResult As Long, sTemp As String
lResult = GetWindowTextLength(hWnd) + 1
sTemp = Space(lResult)
lResult = GetWindowText(hWnd, sTemp, lResult)
GetWindowTitle = Left(sTemp, Len(sTemp) - 1)
End Function
Private Sub CommandButton2_Click()
cb = ComboBox1.Value
Cells(1, 1) = cb
'Unload UserForm1
'UserForm1.Hide
If OptionButton1.Value = True Then Call vordergrund
If OptionButton2.Value = True Then Call hintergrund
Label1.Caption = "Fertig"
NeueStunde = Hour(Now())
NeueMinute = Minute(Now())
NeueSekunde = Second(Now()) + 1
WarteZeit = TimeSerial(NeueStunde, NeueMinute, NeueSekunde)
Application.Wait WarteZeit
Label1.Caption = ""
End Sub
Private Sub CommandButton3_Click()
Unload UserForm1
UserForm1.Hide
Application.Visible = True
End Sub
Private Sub UserForm_Initialize()
Dim hWnd As Long, sTitle As String, lStyle As Long
hWnd = GetWindow(FindWindow(ByVal 0&, ByVal 0&), GW_HWNDFIRST)
Do
lStyle = GetWindowLong(hWnd, GWL_STYLE) And (WS_VISIBLE Or WS_BORDER)
sTitle = GetWindowTitle(hWnd)
If (lStyle = (WS_VISIBLE Or WS_BORDER)) = True And Trim(sTitle) <> "" Then
' MsgBox sTitle
ComboBox1.AddItem sTitle
End If
hWnd = GetWindow(hWnd, GW_HWNDNEXT)
Loop Until hWnd = 0
End Sub
Private Sub CommandButton4_Click()
Unload UserForm1
UserForm1.Hide
Load UserForm1
UserForm1.Show
End Sub