|
 |
|
07-31-2002, 06:29 AM
|
#1
|
|
Registered User
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!!
|
|
|
|
|
|
Advertisement
|
Sponsored links
|
07-31-2002, 07:21 AM
|
#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.
|
|
|
07-31-2002, 09:20 AM
|
#3
|
|
Registered User
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!!
|
|
|
07-31-2002, 10:26 AM
|
#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
|
|
|
07-31-2002, 12:34 PM
|
#5
|
|
Registered User
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!!
|
|
|
07-31-2002, 03:40 PM
|
#6
|
|
FLAC
Join Date: Aug 1999
Location: Upper Marlboro, MD 20772
Posts: 1,311
|
Re: Probably no help at all
Quote:
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
Last edited by cenwesi; 07-31-2002 at 03:43 PM.
|
|
|
07-31-2002, 05:11 PM
|
#7
|
|
Registered User
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!!
|
|
|
07-31-2002, 07:58 PM
|
#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
|
|
|
|
Sponsored links
|
|
Advertisement
|
|
08-01-2002, 05:23 PM
|
#9
|
|
Registered User
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!!
|
|
|
08-01-2002, 06:02 PM
|
#10
|
|
FLAC
Join Date: Dec 1999
Location: Casina, Italy
Posts: 900
|
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.
|
|
|
08-01-2002, 06:33 PM
|
#11
|
|
Registered User
Join Date: Jul 2001
Location: The Netherlands
Posts: 307
|
hihi, think I adviced you to use this a while ago...
oops my mistake, tried to help andrew chappell with this solution , just looked it up : http://www.mp3car.com/vbulletin/show...5&pagenumber=3
but that IS what I'm using, problem is that when vblink or winamp has the focus, both my app AND WinAmp react to the keystrokes, I only want my app to react, WinAmp shouldn'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!!
|
|
|
08-03-2002, 04:07 AM
|
#12
|
|
Newbie
Join Date: Jun 2002
Location: Norfolk,UK
Posts: 45
|
@marsjell
Here's the C++ code that I'm using:
I have two message procs in one Called WndProc which handles messages from my windows and one called WinampWndProc that I use to grab the winamp messages.
when the program starts (DLL init's) I repace winamps WndProc with my own:
In this case I have the hwnd (as it's a DLL plugin), I guess that if you want to do this then it would have to be a DLL.
//Get the original proc address
lpWndProcOld = (void *) GetWindowLong(plugin.hwndParent,GWL_WNDPROC);
//Set the address where winamp's win proc is
SetWindowLong(plugin.hwndParent,GWL_WNDPROC,(long) WinampWndProc);
so in WinampWndProc:
LRESULT CALLBACK WinampWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if(iwant the message)
do something with it
else
return CallWindowProc((long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long))lpWndProcOld,hwnd,message,wParam,lParam) ;
}
Anyway that's the C++ version, perhaps someone could post the VB equivalent?
~MGP3Car
|
|
|
08-04-2002, 04:27 PM
|
#13
|
|
Registered User
Join Date: Jul 2001
Location: The Netherlands
Posts: 307
|
Hi,
so I'm guessing that "GWL_WNDPROC" determines which event to capture?
what value should this have?
__________________
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!!
|
|
|
08-05-2002, 05:50 AM
|
#14
|
|
Newbie
Join Date: Jun 2002
Location: Norfolk,UK
Posts: 45
|
Sort of (but not quite) GetWindowLong(plugin.hwndParent,GWL_WNDPROC); gets the address of the wndproc, this is the proc that handles all messages (~events) for the window refered to by hwndParent.
So by setting that value to your own wndproc, (using SetWindowLong) your proc will get the messages, not the original winamp one.
But if you get a message in your proc that you don't want, then you can still pass it back to the real winamp one using CallWindowProc with the lpWndProcOld that you got with GetWindowLong.
|
|
|
08-05-2002, 06:13 AM
|
#15
|
|
Registered User
Join Date: Jul 2001
Location: The Netherlands
Posts: 307
|
yes I understand, but I need to know which wndproc to alter therefor GWL_WNDPROC needs a value. (I think)
I do know that VB gives me an error if I do not assign a value to GWL_WNDPROC, or am I doing something wrong?
__________________
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!!
|
|
|
|
Sponsored links
|
|
Advertisement
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:31 AM.
| |