-
August 18th, 2004, 11:10 AM
#1
get the Handle of an Active X control
Hi
Got an active X control on a form and i want to use functions from a library (DLL) to do some action on the control, but to use these functions, i must pass the Handle of the control to it. Ho do i do that?
thanks
-
August 18th, 2004, 12:37 PM
#2
My question may sound stupid since i am pretty new to VB6. Please help me with that, i am sure it is simple
thanks
Martin
-
August 18th, 2004, 12:44 PM
#3
Just remember that controls are actually windows...
You should be able to pass the hWnd for the control as the handle. These are properties that are available from the controls themselves. Using the hWnd property, you can make DLL calls such as "LockWindowUpdate" and whatnot.
Hope this helps.
Code:
' These are some sample window handles for a combobox and listbox control
Combo1.hWnd
List1.hWnd
-
August 18th, 2004, 01:14 PM
#4
Hi Vince
Thanks much for replying. I tried that but the DLL function keeps returning me "0" meaning ERROR. I must be missing something!
-
August 18th, 2004, 01:24 PM
#5
Can you post the snipet of code where you are calling the DLL? Is this a custom DLL or are you using a system DLL?
-
August 18th, 2004, 01:25 PM
#6
Wait a minute! the DLL function that i am calling needs 3 parameters
BOOL NvtGetCursorPos(
HDISPLAY hDisplay, // handle to the virtual display
LPINT lpnCursorX, // address of variable for column position
LPINT lpnCursorY // address of variable for row position
);
The NvtGetCursorPos function returns the current cursor column and row position on the virtual display.
Parameters
hDisplay
Handle to the virtual display.
lpnCursorX
Address of the variable that will be set to the column of the current cursor position. If this argument is a NULL pointer, the argument is ignored.
lpnCursorY
Address of the variable that will be set to the row of the current cursor position. If this argument is a NULL pointer, the argument is ignored.
Return Value
If the function succeeds, the return value is a non-zero value. If the handle to the virtual display is invalid, the function will return zero.
I think my problem come from the last 2 parameters. for these i am passing 2 variables defined as long. but the definition above says "Address of the variable..."
Anyone can point me to the right direction?
Thanks
Martin
-
August 18th, 2004, 01:37 PM
#7
it is a custom DLL (not from me)
Code:
Dim ret4 As Long
Dim CurPosCol As Long
Dim CurPosRow As Long
ret4 = NvtGetCursorPos(Terminal1.hWnd, CurPosCol, CurPosRow)
Terminal1 is a custom control. The function always return 0 (error) and also CurPosCol and CurPosRow also return value of 0.
-
August 18th, 2004, 01:53 PM
#8
Can I see how you are declaring the external function?
Can you please include how you are referencing the function in the DLL in your project? For example:
Code:
Private Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, ByVal
wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Any) As Long
It may be as simple as making sure the X and Y are "ByRef" parameters which should pass the reference (pointer) to the function call.
-
August 18th, 2004, 02:00 PM
#9
The function is declared into a VB module supplied with the DLL.
It is declared as followed:
Code:
Declare Function NvtGetCursorPos Lib "csnvtapi.dll" ( _
ByVal hDisplay As Long, _
ByRef lpxPos As Long, _
ByRef lpyPos As Long _
) As Long
-
August 18th, 2004, 02:29 PM
#10
:( Running out of ideas...
Your lpxPos and lpyPos variables should be fine...they are being passed by Reference and thus by the address of the variable.
The only thing I can think of is that your Terminal custom control is not passing the proper hWnd value. Is that a control that you wrote yourself?
(You might want to drop a standard VB control into your app and do some experimenting with the DLL call to make sure everything works with a basic text box or something.)
I'm sorry I'm not helping you out too much here...
-
August 18th, 2004, 02:32 PM
#11
Dont worry Vince, i really appreciate your help. i will do some testing and see waht i can find
thanks again
Martin
-
August 18th, 2004, 02:55 PM
#12
Hwnd
GetWindow By Name , GetWindow By Text are other options .
As the HWND changes everytime a Window is built in Windows.
This maybe why your recieving an Error.
If you're going to use the HWND as the Parameter , then you will have to Get the HWND of the control each time you perform an action.
Grab the HWND , store it temporarily ( Textbox , Memory , etc... ), then refer to the HWND you stored , then Windows ( VB ) just has to look for the stored HWND # .
If your control is closed and then re-opened , the HWND changes , Re-Store Temp Stored HWND #.
How can anyone sell information when all the information that they sell is free at the library ?
How come Doctors keep getting smarter yet they cannot cure the common cold ?
If Scientist are right and man evolved from monkey then where did the monkeys' come from ?
Man I love this little dude that waves => <= He just doesn't stop
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
|