Results 1 to 8 of 8

Thread: Click something, when know only the handle id?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350
    Hello everybody!

    I would like to click a button or menu from my application (like a BuzOf). I have only handle (by FindWindowEx). How to do it?



    -----------

    Thanks,
    Johnny (753187 sec. to 15th birthday!)

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    You can use the SendMessag API but I can't tell you how unless I know exactly what you're trying to do.

    If you post more Details I'll see if I can Help.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350
    OK. I would like to monitore the window and press any button in it, when it shows.

    For example:

    I will be looking by FindWindow to 'Security warning' window (showed by IE when recieving a cookie). When I found it, I would like to press a 'More Details' button (by my application, of course).
    Who is friendly with BuzOf (www.basta.com) knows what I want.

    Or:

    I would like to change a 'Show images' option in IE accesing the registry. Then, if an instance of IE is running, press the View/Refresh menu. Please do not help me with such things like SendKeys "{F5}". I need to run any of menu items in various applications.

    If it is clear, now, please help me...


    ----------------
    Thanks,
    Johnny (677428 sec. to 15th birhtday!)

  4. #4
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Well, assuming you have got the windowhandle (lets call it hWind), you can send the WM_LBUTTONDOWN message followed by a WM_LBUTTONUP message
    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long
    Private Const WM_LBUTTONDOWN = &H201
    Private Const WM_LBUTTONUP = &H202
    
    Private Sub Command1_Click()
    Dim retVal as long
        retVal = SendMessage(hWind, WM_LBUTTONDOWN, 0&, &H10001) ' we click at an offset of 1 pixel by 1
        retVal = SendMessage(hWind, WM_LBUTTONUP, 0&, &H10001)
    End Sub
    Edited by Frans C on 03-17-2000 at 02:51 PM

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350

    But...

    This works well, but only if the window is enabled. I need to call its click subroutine, even it is disabled.

    ?


    ----------
    Thanks,
    John (406655 sec. to 15th birthday!)

  6. #6
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363
    Can this be used to select a menu that's in another app? I need to select the Edit menu from another app. I have the correct handle but GetLastError returns 1400 (Invalid Window Handle). Is that because it's a menu?

    Thanks,
    Wade

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350
    To enable item do this (change "TITLE" to app's title):

    w = FindWindow(vbNullString, "TITLE")
    m = GetMenu(w)
    sm = GetSubMenu(m,2) 'Change 2 to &Edit's index
    'first submenu is 0
    'first submenu can be an icon in MDI app(!)
    EnableMenuItem sm, its index, &H400 or &H0

    You type select; would you like to click the whole Edit menu or run a specified item? To run item, use SendMessage.


    -----------------
    To my problem:
    Is done
    1. the do..loop method helped
    2. as well (maybe not so) as SendMesage

  8. #8
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363
    I'd like to select the whole Edit menu. I can use SendMessage to select it, but I need to dropdown the menu instead. That's when it enables/disables its submenus.

    Thanks,
    Wade

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