CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Jul 2004
    Posts
    84

    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

  2. #2
    Join Date
    Jul 2004
    Posts
    84
    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

  3. #3
    Join Date
    Aug 1999
    Location
    VA
    Posts
    12

    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

  4. #4
    Join Date
    Jul 2004
    Posts
    84
    Hi Vince

    Thanks much for replying. I tried that but the DLL function keeps returning me "0" meaning ERROR. I must be missing something!

  5. #5
    Join Date
    Aug 1999
    Location
    VA
    Posts
    12
    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?

  6. #6
    Join Date
    Jul 2004
    Posts
    84
    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

  7. #7
    Join Date
    Jul 2004
    Posts
    84
    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.

  8. #8
    Join Date
    Aug 1999
    Location
    VA
    Posts
    12

    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.

  9. #9
    Join Date
    Jul 2004
    Posts
    84
    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

  10. #10
    Join Date
    Aug 1999
    Location
    VA
    Posts
    12

    :( 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...

  11. #11
    Join Date
    Jul 2004
    Posts
    84
    Dont worry Vince, i really appreciate your help. i will do some testing and see waht i can find

    thanks again

    Martin

  12. #12
    Join Date
    Jan 2002
    Location
    somewhere between a variable and a string
    Posts
    214

    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
  •  





Click Here to Expand Forum to Full Width

Featured