Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: never lose focus

  1. #1
    Variable Bitrate
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    307

    never lose focus

    anybody know how to make sure that my VBapp allways has the focus? I've tried this:

    sub form1_lostfocus
    me.setfocus
    end sub

    but that doesn't work, in fact the whole lostfocus function does not work, I tried
    sub form1_lostfocus
    msgbox "blabla"
    end sub

    and it never gave me a messagebox telling me to blabla...

    thanks!
    If at first you don't succeed.........
    destroy all evidence you tried

    for info on t6369c LCD or Presslab's powersupply check:
    http://www.namms.tk <=updated!!

  2. #2
    Newbie
    Join Date
    Jun 2002
    Posts
    49
    I assume by "always have the focus" that you mean that you want your program to always be the topmost form. If that's what you're after, check out this link:

    http://216.26.168.92/tips/tip4.html

    I think there's another API call that you can make to do this, but I can't think of it off the top of my head.

  3. #3
    Variable Bitrate
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    307
    no that doesn't work, even if the app is allways the topmost app, that doesn't mean that it has the focus (is the current active form).

    Problem is that I use my keyboard to handle my app, but if it doesn't have the focus I'm handling another as well as my app.

    example:
    my app starts up winamp. if winamp has the focus and I press B winamp will go to the next songs & my app will do whatever I've programmed "under" B. I don't want winamp to respond to my key-touching...

    am I clear? (my english isn't all that...)
    If at first you don't succeed.........
    destroy all evidence you tried

    for info on t6369c LCD or Presslab's powersupply check:
    http://www.namms.tk <=updated!!

  4. #4
    Newbie
    Join Date
    Jun 2002
    Location
    Norfolk,UK
    Posts
    45

    Probably no help at all

    marsjell,
    I don't know VB but in C++, a neat trick is to get a handle to the external programs window proc (FindWindow etc.), save the handle away, replace the window proc handle with your own proc handle (SetWindowLong) and in the new proc pass any messages that you don't want to handle back to the original proc (CallWndProg).
    I used this as I couldn't get get SetWindowFocus to work.
    I don't know if you can do this lower level stuff in VB.
    ~MGP3Car

  5. #5
    Variable Bitrate
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    307
    Hi,
    well the low level stuff is possible in VB, but I don't fully understand what you are saying, also I want other programms to ignore the keystrokes, only my app may respond.

    now when I hit a key and winamp has the focus, winamp responds to the keyhit (obviously) and so does my app... my app should respond, but winamp shopuldn't
    If at first you don't succeed.........
    destroy all evidence you tried

    for info on t6369c LCD or Presslab's powersupply check:
    http://www.namms.tk <=updated!!

  6. #6
    FLAC
    Join Date
    Aug 1999
    Location
    Upper Marlboro, MD 20772
    Posts
    1,311

    Re: Probably no help at all

    Originally posted by MGP3Car
    marsjell,
    I don't know VB but in C++, a neat trick is to get a handle to the external programs window proc (FindWindow etc.), save the handle away, replace the window proc handle with your own proc handle (SetWindowLong) and in the new proc pass any messages that you don't want to handle back to the original proc (CallWndProg).
    I used this as I couldn't get get SetWindowFocus to work.
    I don't know if you can do this lower level stuff in VB.
    ~MGP3Car
    yes u can....he might need to define a structure
    ...let me look for the api call... i use that in C2/3/4
    Or you can go to this site http://www.allapi.net/ and download the API-Guide app there...tons of VB stuff with that app..
    abcd-1
    Author of CobraI,II,III and now CobraIV.
    You can contact me on AOL instant messenger....nick is cenwesi or cenwesi3

  7. #7
    Variable Bitrate
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    307
    thanks cenwesi,

    the api-guide is great, haven't solved my problem yet but.......
    If at first you don't succeed.........
    destroy all evidence you tried

    for info on t6369c LCD or Presslab's powersupply check:
    http://www.namms.tk <=updated!!

  8. #8
    Newbie
    Join Date
    Jun 2002
    Location
    Norfolk,UK
    Posts
    45
    marsjell,
    Basically the idea is that every program has a message handler (WndProc), this takes in events such as quit, getting focus, paint requests and keyboard input.
    If you can change which program (or sub proc?) gets called on these events then you can 'steal' the keyboard input.
    Replace the external programs WndProc with your own and then you will always effectively have focus.
    Of course it's not as easy as that because the external program will still want to handle messages that you are not interested in, so any message that you don't want to handle should be sent directly to the original, so you will need to store away the original reference before you overwrite it.

    winamp e.g.

    Normally:
    messages->winamp's WndProc
    With your mesage handler:
    messages->your WndProc->winamp's WndProc

    If you want the message then don't pass it on to winamp.

    If you would like the c++ code that I used for Winamp then I'll post it, or if cenwesi could post some Cobra VB code then that would obviously be better for you.

    Hope this explains it.

    ~MGP3Car

  9. #9
    Variable Bitrate
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    307
    Hi, if you would be willing to post that part of your code please... I understand in theorie what you're saying, but have no idea how to do this in practise.

    thanks!
    If at first you don't succeed.........
    destroy all evidence you tried

    for info on t6369c LCD or Presslab's powersupply check:
    http://www.namms.tk <=updated!!

  10. #10
    FLAC Gutter's Avatar
    Join Date
    Dec 1999
    Location
    Casina, Italy
    Posts
    901
    Try this:

    <CODE>
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

    Private Function GetKey(ByVal vKey As KeyCodeConstants) As Boolean
    GetKey = GetAsyncKeyState(vKey) And &H8000
    End Function

    Private Sub Timer1_Timer()
    If GetKey(vbKey1) Then
    Debug.Print "Down 1"
    ElseIf GetKey(vbKey2) Then
    Debug.Print "Down 10"
    ElseIf GetKey(vbKey3) Then
    Debug.Print "Down 100"
    ElseIf GetKey(vbKey5) Then
    Debug.Print "Play/Pause"
    ElseIf GetKey(vbKey7) Then
    Debug.Print "Up 1"
    ElseIf GetKey(vbKey8) Then
    Debug.Print "Up 10"
    ElseIf GetKey(vbKey9) Then
    Debug.Print "Up 100"
    End If
    End Sub

    </CODE>

    Add a timer control which has an interval of at least 100ms. This will do what I think you're asking.

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •