Results 1 to 13 of 13

Thread: changing focus to a paticular window, all i know is the window title

  1. #1

    Thread Starter
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747

    changing focus to a paticular window, all i know is the window title

    Hi, I would like to change the focus to a window of title "WindowTItle".

    i am guessing i need to loop thru all the windows (how?) and use that getwindowtext API to compare the window title, and once found setfocus API?

    or if i get desperate

    do
    sendkeys "%{TAB}", true
    loop until getActiveWindowTitle = "WindowTitle"

    how do u type that code in "visual basic code" syntax on the post?
    Last edited by SkiNLaB; Feb 24th, 2002 at 07:24 AM.

  2. #2

    Thread Starter
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    i c
    where exactly would i find short descriptions about these API's? like a web page where u type the name in, and up comes a description explaining what it does and what the arguments are.

  3. #3

    Thread Starter
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    ahh found one, www.vbapi.com

  4. #4

    Thread Starter
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    geez, this structure is weird, i just read up on this enumWindows API, its freakin weird! so u call it, and give it the address of a public function that is in a module, and then enumWindows just calls that function over and over again until there are no more windows to be processed.... how bout that, thats great, thanx for ur help! just one thing though.... in EnumWindowsProc, at the end u return true ALWAYS, at no point can it return false, is it up to me to decide when it should return false (ie once the window has been found)

  5. #5

    Thread Starter
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    oops one more thing...

    'Create a buffer
    MyStr = String(GetWindowTextLength(hwnd) + 1, Chr$(0))

    whats this buffer stuff?

  6. #6

    Thread Starter
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    i just found another API called FindWindow

    http://www.vbapi.com/ref/f/findwindow.html

    i simply feed it the title, and it returns to me the hWnd, which means i can setforegroundWindow to it, and also discovered that setFocus will only work for windows that ur program owns, which in this case mine does not.

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Download the API viewer from http://www.allapi.net/ and have the API declarations and samples of how to use them at your fingertips.

  8. #8
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Originally posted by SkiNLaB
    oops one more thing...

    'Create a buffer
    MyStr = String(GetWindowTextLength(hwnd) + 1, Chr$(0))

    whats this buffer stuff?
    Creates a buffer of length returned by the GetWindowTextLength and fills it with Null. You will get your Window Caption in this buffer.

  9. #9

    Thread Starter
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    hmm k thats what i thought, but why do i need to create a Buffer for this? does getwindowtext need a string thats allready *buffed* does it?

  10. #10
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    Why not you use AppActivate (=standard VB, no API)

    AppActivate "WindowTitle"

  11. #11

    Thread Starter
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    i thought appactivate LOADS a program, my program and adobe premiere shall be swapping focus from time to time.

  12. #12
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    VB Help:
    The AppActivate statement changes the focus to the named application or window but does not affect whether it is maximized or minimized. Focus moves from the activated application window when the user takes some action to change the focus or close the window. Use the Shell function to start an application and set the window style.

  13. #13

    Thread Starter
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    ohhhhhhhhhh, i c, damn and i just went and learnt all this API crap, ah well, i spose i had to learn it one of these days! thanx twanvl

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