|
-
May 30th, 2000, 03:08 PM
#1
Thread Starter
PowerPoster
Does antbody know how to get the PictureBox hWnd? Assume the PictureBox Object does not support the Picture1.hWnd properties.
Because I writing a program that run under WinCE OS where the PictureBox does not support the Picture1.hWnd properties.
Your feedback is very useful!
-
May 30th, 2000, 03:17 PM
#2
transcendental analytic
Hehe, that was a pretty hard Q, i think, if WinCE does not support hWnds then why do you need it?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 30th, 2000, 03:37 PM
#3
Thread Starter
PowerPoster
I can get alternative choice
But I currently developing a program that run under WinCE. So I need to resolve it. I know it is a hard Q, but I know you're guy should be able to provide me some idea about this task.
In pricture box object, it does not have the Title, so can not use the FindWindow API function to locate the hWnd. Arhhhh Do help me!!!
-
May 30th, 2000, 03:48 PM
#4
Addicted Member
Use the class Name
Use Findwindow api but use the class name, it is
ThunderPictureBox
in VB.
If you can't pronounce my name, call me GURU 
-
May 30th, 2000, 04:05 PM
#5
Thread Starter
PowerPoster
Re: Use the class Name
Originally posted by G.Kumaraguru
Use Findwindow api but use the class name, it is
ThunderPictureBox
in VB.
I did try it, but how about the lpWindowName arguement? We can leave it blank or put "". But sis put it as "". The result is still 0. That mean the API also can not find the PictureBox.
But I used the Spy++ it does return me the PictureBox hWnd, Window, ClassName, Window Style, Window RECT value, Thread ID and Process ID. So I'm sure there must be a way to do it!
Can Some Guru help me!!!
-
May 30th, 2000, 04:10 PM
#6
transcendental analytic
Here comes you Guru... ehm fanatic
put a string variable instead of ""
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 30th, 2000, 04:27 PM
#7
Thread Starter
PowerPoster
Can not be others string
Can not, still return zero to me. I think me can not simply pass a string to the lpWindowName arguement. Since it is one of the searching key for the FindWindow API function.
Some more hints... please...
-
May 30th, 2000, 04:32 PM
#8
transcendental analytic
Then what about vbnull, if that doesn't work then i don't know
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 30th, 2000, 04:36 PM
#9
Hyperactive Member
Handle
I was under the impression that the handle to a picture box could be obtained by just using
Just to show what I mean try this
Code:
Private Sub Command1_Click()
MsgBox Picture1.Picture
End Sub
-
May 30th, 2000, 05:19 PM
#10
transcendental analytic
Actuatlly that's the same as using picture1.picture1.handle not picture1.hwnd - you get the handle of the picture instead
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 30th, 2000, 05:22 PM
#11
Thread Starter
PowerPoster
vbNull is working BUT...
gravyboy, yours does not work. Thanks Kedaman, it work with vbNull as the lpWindowName arguement.
Now, I've another problem... the vbNull work fine with one PictureBox control in the form. But, now I've 2 PictureBox (PictureBox1, PicureBox2) under the same Form call (frmMain.frm).
So, I still can not use the FindWindow API to get the 2 PictureBox1 and PictureBox2 hWnd value that I'll use it to set the PictureBox1 become the child Window of PictureBox2 by using the SetParent API function:
SetParent xHwnd, yHwnd
Assume the xHwnd is the handle value fot PictureBox1,
yHwnd is the handle value for PictureBox2.
So, how the single FindWindow API function can differentiate the handle for PictureBox1 and PictureBox2?
xHwnd = FindWindow("ThunderPictureBox",vbNull)
yHwnd = FindWindow("ThunderPictureBox",vbNull)
[Edited by Chris on 05-31-2000 at 06:28 AM]
-
May 30th, 2000, 06:16 PM
#12
transcendental analytic
I'm not sure if there's any direct way then, but you could enumerate the parentwindow's childs, and get all the wnds
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 31st, 2000, 12:51 AM
#13
The second parameter (lpWindowName) is expected to be a string, therefore, you must pass a string data type value:
Code:
Dim lHwnd As Long
lHwnd = FindWindow("ThunderPictureBox",vbNullString)
Also, since the Picturebox belongs to the form then you better use FindWindowEx API:
Code:
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Sub Command1_Click()
Dim lHwnd As Long
lHwnd = FindWindowEx(Me.hWnd, 0, "ThunderPictureBox", vbNullString)
End Sub
-
May 31st, 2000, 12:57 AM
#14
New Member
off-topic...
Sorry for the off-topic post, but what version if VB do you have to have to develop Win CE programs? Is there an app wizard or tutorial?
Thanks,
Shawn
-
May 31st, 2000, 07:18 AM
#15
Thread Starter
PowerPoster
Re: off-topic...
Originally posted by grizzly
Sorry for the off-topic post, but what version if VB do you have to have to develop Win CE programs? Is there an app wizard or tutorial?
Thanks,
Shawn
Just stay with you VB6 + SP3 + WinCE ToolKit for VB6 that enough already.
-
May 31st, 2000, 07:44 AM
#16
transcendental analytic
Enumerating windows
Ok, i have this for you
Code:
Private Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private returnval(), counter%, Parent&
Private Function EnumFunction(ByVal hwnd&, ByVal lParam&) As Long
'If Parent = GetDesktopWindow Then
'If GetParent(hwnd) <> Parent Then If GetParent(hwnd) > 0 Then EnumFunction = True: Exit Function 'Exits if it's a indirect child
'Else
If GetParent(hwnd) <> Parent Then EnumFunction = True: Exit Function 'Exits if it's a indirect child
'End If
counter = counter + 1
ReDim Preserve returnval(counter - 1)
returnval(counter - 1) = hwnd
EnumFunction = True
End Function
Public Function Getchild(Parenthwnd&)
Parent = Parenthwnd
counter = 0
EnumChildWindows Parenthwnd, AddressOf EnumFunction, 0
If counter Then Getchild = returnval
End Function
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 31st, 2000, 07:54 AM
#17
Thread Starter
PowerPoster
GetChild
Thanks Kedaman, your GetChild work great but it return all the available child hwnd to me, which I just interested in those have WindowClass "ThunderPictureBox"
Come on... more hints...
-
May 31st, 2000, 08:24 AM
#18
transcendental analytic
Oh, i thought you would figure out, just make a loop checking the classnames of the wnd's and sort them out
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 31st, 2000, 08:41 AM
#19
Thread Starter
PowerPoster
Kedaman, I'll try & tell you later.
-
May 31st, 2000, 09:25 AM
#20
Thread Starter
PowerPoster
GetClassName API
Hi Kedaman, I just add the GetClassName API function ontop of you code & it work. The only think is the GetClassNAme API return me the PictureBox Class Name = "ThunderPictureBoxDC" instead of "ThunderPictureBox" Anyway, I manage to differentiate between the PictureBox and others control.
Now, I have the handle for 2 different picture box, but how do I differentiate the handle is belong to which PictureBox.
Code:
Private Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private returnval(), counter%, Parent&
Private ReturnStr$, nReturn&, rethWnd$
Private PichWnd(), hWndCnt%
Private Function EnumFunction(ByVal hwnd&, ByVal lParam&) As Long
'If Parent = GetDesktopWindow Then
'If GetParent(hwnd) <> Parent Then If GetParent(hwnd) > 0 Then EnumFunction = True: Exit Function 'Exits if it's a indirect child
'Else
If GetParent(hwnd) <> Parent Then EnumFunction = True: Exit Function 'Exits if it's a indirect child
'End If
counter = counter + 1
ReDim Preserve returnval(counter - 1)
returnval(counter - 1) = hwnd
ReturnStr = String(255, Chr(0))
nReturn = GetClassName(hwnd, ReturnStr, 255)
If nReturn <> 0 Then
rethWnd = Left(ReturnStr, InStr(1, ReturnStr, Chr(0), vbBinaryCompare) - 1)
If rethWnd = "ThunderPictureBoxDC" Then
hWndCnt = hWndCnt + 1
ReDim Preserve PichWnd(hWndCnt)
PichWnd(hWndCnt) = hwnd
End If
End If
EnumFunction = True
End Function
Public Function Getchild(Parenthwnd&)
Parent = Parenthwnd
counter = 0
hWndCnt = 0
EnumChildWindows Parenthwnd, AddressOf EnumFunction, 0
If counter Then Getchild = returnval
SetParent PichWnd(1), PichWnd(2)
End Function
-
May 31st, 2000, 09:29 AM
#21
Try something like this. Add a module to your project. Also, add a couple of pictureboxes a listbox and a button (for testing purposes). Copy this code to the module:
Code:
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public m_arrHwndPicBoxes() As Long
Public Function EnumFunction(ByVal pHwnd As Long, ByVal lParam As Long) As Long
Static intIndex As Long
Dim lngRetVal As Long
Dim strClassName As String
'Get ClassName for pHwnd
strClassName = Space(125)
lngRetVal = GetClassName(pHwnd, strClassName, Len(strClassName))
If lngRetVal Then
strClassName = Left(strClassName, lngRetVal)
'Check if the ClassName is ThunderPictureBox
If strClassName = "ThunderPictureBoxDC" Then
ReDim Preserve m_arrHwndPicBoxes(intIndex)
m_arrHwndPicBoxes(intIndex) = pHwnd
intIndex = intIndex + 1
End If
End If
'Continue enumeration
EnumFunction = 1
End Function
Copy this code to your form:
Code:
Private Sub Command1_Click()
Dim i As Integer
On Error Resume Next
Call EnumChildWindows(Me.hwnd, AddressOf EnumFunction, 0)
For i = LBound(m_arrHwndPicBoxes) To UBound(m_arrHwndPicBoxes)
If Err.Number = 0 Then
List1.AddItem m_arrHwndPicBoxes(i)
End If
Next
End Sub
-
May 31st, 2000, 02:22 PM
#22
Thread Starter
PowerPoster
How to differentiate?
Thanks both Kedaman & Serge, because you guys really look into my problem & I know this quite a hard question.
Although I manage to get the handle for both PictureBox with the sample code from both of you kedaman and Serge, I still can not differentiate the handle is belong to which picture box.
Thanks for your further Help.
-
May 31st, 2000, 03:14 PM
#23
transcendental analytic
There must be other properties of the wnd's that differs those boxes, ie, you can't have them laying on each other do you? If not you can get their rect's
Code:
Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Long, lpRect As RECT) As Long
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 31st, 2000, 03:35 PM
#24
Thread Starter
PowerPoster
Reference.
Hi Kedaman, to get the Window Rect is not a problem, since your code can get the hWnd for both PictureBox. So, how do i differentiate the PictureBox just base on the window rect value? which should I set as a reference? because the PictureBox can be at any place when the program run.
Thansk for all those helpful feedback.
-
May 31st, 2000, 03:47 PM
#25
transcendental analytic
Well you drived me almost nuts when you said that, then i realized, you can still get the location of the pictureboxes, do they have left, top,width and heigh? If so you can compare
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 31st, 2000, 04:09 PM
#26
Thread Starter
PowerPoster
Don't you feel this is very challenging
no...Kedaman I did drive to nut, but just wander to find out how can achieve this task.
I know, but let said my intial PictureBox1 is at
Top = 0
Left = 0
Height = 100
Width = 100
and PictureBox2 at
Top = 200
Left = 200
Height = 100
Width = 100
later PictureBox1 and PictureBox2 also move by the user to somewhere else, then I may lost the refernce point. I may still can resolve it by keep thier respective value into the registry. Don't you see that there was some may procedure to do upon the user have move the picture box?
because I need to aware the Speed to the handheld device.
Thanks a lot.
-
May 31st, 2000, 08:40 PM
#27
transcendental analytic
Compare the rect to the current picturebox position (you have their names and position)
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|