LeighWardle
asked on
VB6 - Finding a Window using FindWindow from a Form object
Hi Experts,
Assuming I have this code fragment:
Dim frmFormObject As Form
Dim lngHandle As Long
How can I make this code work?
lngHandle = FindWindow(vbNullString, ????????)
Regards,
Leigh
Assuming I have this code fragment:
Dim frmFormObject As Form
Dim lngHandle As Long
How can I make this code work?
lngHandle = FindWindow(vbNullString, ????????)
Regards,
Leigh
ASKER
Hi vb_elmar,
Thanks for your suggestions.
I just need some help getting the appropriate title string from the Form object (assume it is frmFormObject).
What do I put as the 2nd argument in findwindow?
I assume it is something like frmFormObject.Caption?
Regards,
Leigh
Thanks for your suggestions.
I just need some help getting the appropriate title string from the Form object (assume it is frmFormObject).
What do I put as the 2nd argument in findwindow?
I assume it is something like frmFormObject.Caption?
Regards,
Leigh
If the title is unknown the 2nd parameter is vbNullString (see below).
To find an (unknown) title try this:
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 String, ByVal lpWindowName As String) As Long
Sub Form_Load()
h = FindWindow("ThunderRT6Form DC", vbNullString)
Dim LL As Long, aa$
aa$ = Space$(128)
result = GetWindowText(h, aa$, 128)
result = Left(aa, result)
MsgBox result
End Sub
To find an (unknown) title try this:
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 String, ByVal lpWindowName As String) As Long
Sub Form_Load()
h = FindWindow("ThunderRT6Form
Dim LL As Long, aa$
aa$ = Space$(128)
result = GetWindowText(h, aa$, 128)
result = Left(aa, result)
MsgBox result
End Sub
ASKER
Hi vb_elmar,
Sorry, that's not quite what I need.
See my code below.
The line that needs fixing is:
lngHandle = FindWindow(vbNullString, frmFormObject.Caption) ' <<< doesn't work!!!
What can I replace frmFormObject.Caption with - so the 2nd argument of FindWindow is the string required by FindWindow?
Regards,
Leigh
Public Function FormLoadIntoContainer(frmF ormObject As Form, frameFrameObject As Frame) As Boolean
Dim rec As Rect
Dim lngHandle As Long
Dim boolResult As Boolean
boolResult = FormsUnloadAllExceptThisOn e(frmFormO bject.Name )
Unload frmFormObject
frmFormObject.WindowState = vbNormal '20120522
frmFormObject.Top = -10000
frmFormObject.Show
lngHandle = FindWindow(vbNullString, frmFormObject.Caption) ' <<< doesn't work!!!
GetWindowRect lngHandle, rec
SetParent lngHandle, frameFrameObject.hwnd
' The first 5 parameters are required but we only care about the 1st three
MoveWindow lngHandle, 0, 0, frameFrameObject.Width, frameFrameObject.Height, 1
FormLoadIntoContainer = True
End Function
Sorry, that's not quite what I need.
See my code below.
The line that needs fixing is:
lngHandle = FindWindow(vbNullString, frmFormObject.Caption) ' <<< doesn't work!!!
What can I replace frmFormObject.Caption with - so the 2nd argument of FindWindow is the string required by FindWindow?
Regards,
Leigh
Public Function FormLoadIntoContainer(frmF
Dim rec As Rect
Dim lngHandle As Long
Dim boolResult As Boolean
boolResult = FormsUnloadAllExceptThisOn
Unload frmFormObject
frmFormObject.WindowState = vbNormal '20120522
frmFormObject.Top = -10000
frmFormObject.Show
lngHandle = FindWindow(vbNullString, frmFormObject.Caption) ' <<< doesn't work!!!
GetWindowRect lngHandle, rec
SetParent lngHandle, frameFrameObject.hwnd
' The first 5 parameters are required but we only care about the 1st three
MoveWindow lngHandle, 0, 0, frameFrameObject.Width, frameFrameObject.Height, 1
FormLoadIntoContainer = True
End Function
Why are you finding your own window using own your caption that is active when shown?
What are you trying to accomplish?
if you want to use your own window use <Me>
like:
Me.ControlBox = False
Me.Size = New Size(465, 60)
if you want to position your window manually:
http://msdn.microsoft.com/en-us/library/aa984420%28v=vs.71%29.aspx
frmFormObject.Show
lngHandle = FindWindow(vbNullString, frmFormObject.Caption) ' <<< doesn't work!!!
What are you trying to accomplish?
if you want to use your own window use <Me>
like:
Me.ControlBox = False
Me.Size = New Size(465, 60)
if you want to position your window manually:
http://msdn.microsoft.com/en-us/library/aa984420%28v=vs.71%29.aspx
ASKER
I want to be able to move the window, as in:
lngHandle = FindWindow(vbNullString, frmFormObject.Caption) ' <<< doesn't work!!!
GetWindowRect lngHandle, rec
SetParent lngHandle, frameFrameObject.hwnd
' The first 5 parameters are required but we only care about the 1st three
MoveWindow lngHandle, 0, 0, frameFrameObject.Width, frameFrameObject.Height, 1
lngHandle = FindWindow(vbNullString, frmFormObject.Caption) ' <<< doesn't work!!!
GetWindowRect lngHandle, rec
SetParent lngHandle, frameFrameObject.hwnd
' The first 5 parameters are required but we only care about the 1st three
MoveWindow lngHandle, 0, 0, frameFrameObject.Width, frameFrameObject.Height, 1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, vb_elmar.
Regards,
Leigh
Regards,
Leigh
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
a=findwindow("ThunderRT6Fo
sample:
a=findwindow("ThunderRT6Fo
a=findwindow("ThunderFormD
annotation:
A form running in the vb IDE
has the class name "ThunderFormDC", and a compiled
VB.EXE has the class name "ThunderRT6FormDC".