Re: keyboard event

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: David Saint (beer_at_hotmail.com)
Date: 09/15/04


Date: Wed, 15 Sep 2004 09:05:12 +0100


"alpine" <alpine_don'tsendspam@mvps.org> wrote in message
news:0hjek0p0jmie47v4om4j7i22r4odnt26i5@4ax.com...
> On Tue, 14 Sep 2004 18:37:40 +0100, "David Saint" <beer@hotmail.com>
> wrote:
>
> >
> >"alpine" <alpine_don'tsendspam@mvps.org> wrote in message
> >news:ji0ek058lmv0k1j9q5jpkhvh75ahnt64al@4ax.com...
> >> On Tue, 14 Sep 2004 08:53:22 +0100, "David Saint" <beer@hotmail.com>
> >> wrote:
> >>
> >> >hello everyone
> >> >
> >> >i have had to re-post this question due to a lack
> >> >of any responce from another group.
> >> >
> >> >i really need some help with this.
> >> >this is what i am currently using in my vb6 app.
> >> >
> >> >keybd_event VK_T, 0, 0, 0
> >> >keybd_event VK_T, 0, KEYEVENTF_KEYUP, 0
> >> >
> >> >the problem is this, the user is able to unknowingly
> >> >create an error by giving the focus to another window.
> >> >
> >> >can i use something else (more reliable) to send keys to another
window
> >> >without an error being caused if my app loses focus ? i have already
> >> >tried the SetFocusAPI in a loop, but that is still not 100% effective.
> >> >
> >> >could SendMessage, SetWindowText or something like that be what
> >> >i need to use for a 100% garanteed result ?
> >> >
> >> >thanks
> >>
> >>
> >> The methods you use will depend quite a bit on the target you want to
> >> send text into. If it is a standard edit control, you will probably
> >> be better off using SetWindowText or sending a WM_SETTEXT message. Of
> >> course, you will need the hWnd of the target window in order to use
> >> either of these but getting that usually isn't too much of a problem
> >> using some combination of the FindWindow, FindWindowEx and/or
> >> EnumChildWindows API functions.
> >>
> >> HTH,
> >> Bryan
> >> ____________________________________________________________
> >> New Vision Software "When the going gets weird,"
> >> Bryan Stafford "the weird turn pro."
> >> alpine_don'tsendspam@mvps.org Hunter S. Thompson -
> >> Microsoft MVP-Visual Basic Fear and Loathing in LasVegas
> >
> >Bryan
> >i'm aready able to find the window's hWnd through
> >
> >Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA"
> >(ByVal lpClassName As _
> >Any, ByVal lpWindowName As Any) As Long
> >...
> >dwnd = FindWindow(vbNullString, "WindowName")
> >...
> >i didn't realise this was going to be the tricky part.
> >
> >thanks Bryan
>
>
> Use the Spy++ application that comes with VS to find the class name of
> the actual target control (from your description I assume it is an
> edit control residing on the parent window). Once you know the window
> hierarchy, you can walk it to get to the hWnd of the target window.
>
> HTH,
> Bryan
> ____________________________________________________________
> New Vision Software "When the going gets weird,"
> Bryan Stafford "the weird turn pro."
> alpine_don'tsendspam@mvps.org Hunter S. Thompson -
> Microsoft MVP-Visual Basic Fear and Loathing in LasVegas

ok thanks Bryan
i use a tool from PSC i think it's called advanced windows API
it acts like visual studio's spy tool but you can do even more with this one
plus, all the code for it is freely available.

how could i maintain the focus on the window control
once i found it ? at the moment in testing, if i click anywhere
while the operation is running the keys are not sent to the correct
destination control.

what about something like this

hWnd = FindWindow(vbNullString, sWinTxt)
If hWnd = 0 Then
Exit Sub
Else
For x = 1 To 5000
    r = SetFocusAPI(hWnd)
...
' SetWindowText or WM_SETTEXT code here
...
Next
End If

this does work in a fashion, but it seems stall until the loop is complete
then it deals with text ?

thanks for the help Bryan



Relevant Pages

  • Re: Swap handles of attached windows ... assert in wincore.cpp .... please explain
    ... attach the new hwnd to the old controls CWnd but then all ... SendMessages to my control seem to vanish into void. ... CWnd* pWnd = QGetCWnd; ... that way destroying the old window. ...
    (microsoft.public.vc.mfc)
  • Re: How add buton onto title bar of any external active window?
    ... I want to add buttons ontoany active window. ... int sm_CXSIZE; ... static int WindowsFeaturesWidth(HWND hwnd, DWORD style) ... LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM ...
    (microsoft.public.win32.programmer.gdi)
  • Re: MFC and Worker Thread issue
    ... situations such as the thread has terminated before the window was created but has no way ... CWnd* which is the message sink and it is created before the thread (with its HWND value) ... which does never see PostMessage or HWND. ... Callbacks add their own problems; I try to avoid them if at all possible. ...
    (microsoft.public.vc.mfc)
  • Re: Are VBA userforms always child of Windows desktop?
    ... I only need this Hwnd of the parent, ... GetAncestor API (with GA_PARENT) to get Parent. ... I suppose which window you need will depend on the overall objective. ... Private Declare Function GetDesktopWindow Lib "user32" As Long ...
    (microsoft.public.excel.programming)
  • Re: Why doesnt this recursive function return the right value?
    ... sClassName Like ClassName & "*" Then FindWindowHwndLike_B = hwnd lHolder = hwnd ... Couldn't find anything for the ClassName comparison. ... Dim s1 As String, s2 As String ... 'finds the first window where the class name start with ClassName ...
    (microsoft.public.excel.programming)