CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 31
  1. #16
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: Help! How to send a CTRL+X key to another window?

    It IS Microsoft. Say no more.

    (If a Microsoft lawyer is reading this post, sit on this .|..).

    --
    Jason Teagle
    [email protected]

  2. #17
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: Help! How to send a CTRL+X key to another window?

    OK, I give up
    How do you get to be a Linux, Unix or a Mac programmer?

    Sally


  3. #18
    Join Date
    May 1999
    Posts
    7

    Re: Help! How to send a CTRL+X key to another window?

    Oh,My God! How a discussion! Why don't you try my way:


    HWND hWnd=::FindWindow(NULL, some window caption);
    if (hWnd)
    {
    BYTE ks[1]=
    {
    VK_CTRL//if wanna to send a ALT+somekey, change to VK_MENU
    };
    DWORD tid=::GetWindowThreadProcessId(hWnd,NULL);
    ::SetKeyboardState(ks);
    ::AttachThreadInput(::GetCurrentThreadId(),tid,TRUE);
    ::BringWindowToTop(hWnd);
    ::PostMessage(hWnd,WM_KEYDOWN,someletter, 0);
    ::AttachThreadInput(::GetCurrentThreadId(),tid,FALSE);
    }
    However, I can't send the "shift+somekey", nor the combination of 3 keys, sush as "CTRL+SHIFT+somekey".


  4. #19
    Join Date
    May 1999
    Posts
    7

    About Linux

    Hey, I am a faithful linux fan.I am now studying
    the network and XWindow programming. Is there anybody interested in these?


  5. #20
    Guest

    Re: Help! How to send a CTRL+X key to another window?

    Thats all exciting ... but I tried to use your code to send WM_SYSKEYDOWN / -UP messages from a child to its parent (that is from a tab page to its containing dialog). I sent the message from out PreTranslateMessage() when receiving a WM_SYSKEYxxx for a system key that doesn't exist on this page. It doesn't do anything at all, even the WM_KEYDOWN message does not reach the parent. What am I doing wrong?

    PreTranslateMessage( ... )
    {
    ...
    else if( ((pMsg->message == WM_SYSKEYDOWN) || (pMsg->message == WM_SYSKEYUP)) && (pMsg->wParam != VK_MENU) )
    {
    if( !IsSysKey(pMsg->wParam) ) // SysKey dieser Page ?
    if( ((CPraxisDialog*)GetOwner()->GetOwner())->IsSysKey(pMsg->wParam) )
    {
    BYTE ks[1] = { VK_MENU };
    GetOwner()->GetOwner()->SetFocus();
    ::SetKeyboardState( ks );
    ::AttachThreadInput( ::GetCurrentThreadId(), ::GetWindowThreadProcessId(GetOwner()->GetOwner()->m_hWnd, NULL), TRUE );
    ::BringWindowToTop( GetOwner()->GetOwner()->m_hWnd );

    GetOwner()->GetOwner()->PostMessage( (pMsg->message == WM_SYSKEYDOWN)? WM_KEYDOWN : WM_KEYUP, pMsg->wParam, 0 );//pMsg->lParam );

    ::AttachThreadInput( ::GetCurrentThreadId(),
    ::GetWindowThreadProcessId(GetOwner()->GetOwner()->m_hWnd, NULL), FALSE );

    return TRUE;
    }
    }



  6. #21
    Join Date
    Nov 2001
    Posts
    17

    Re: Help! How to send a CTRL+X key to another window?

    Hi All:

    I hope this can help
    Try this: (first of all you need the HWND of the window wich will receive the message, in this case ventana)

    HWND ventana;
    .....


    ::BringWindowToTop(ventana); //bring ventana to TOP
    // simulate Alt + return
    keybd_event(VK_MENU,
    0,
    0,
    0);
    keybd_event(VK_RETURN,
    0,
    0,
    0);
    keybd_event(VK_RETURN,
    0,
    KEYEVENTF_KEYUP,
    0);
    keybd_event(VK_MENU,
    0,
    KEYEVENTF_KEYUP,
    0);

  7. #22
    Join Date
    Jul 2007
    Location
    in your pocket
    Posts
    339

    Re: Help! How to send a CTRL+X key to another window?

    Quote Originally Posted by shellreef
    Get the hwnd of the window you want to send the keys to (for example CWnd* pWnd = CWnd::FindWindow(NULL, "Untitled - Notepad"), and then post or send a WM_CHAR message to it. For example:

    [ccode]
    // Get the window that we want to send Ctrl+X to. In this example 'pWnd' will be set to
    // the edit control in Notepad (dialog ID 0x0F). Change this.
    CWnd* pWnd = CWnd::FindWindow(NULL, "Untitled - Notepad");
    if (pWnd)
    {
    pWnd = pWnd->GetDlgItem(0x0F);
    } else {
    AfxMessageBox("Can't find notepad");
    exit(0);
    }
    pWnd->SendMessage(WM_CHAR, 24, 0, 0); // 24 = Ctrl+X




    Hope this helps.
    Can you pls tell how did you get this 24 equelent fo Ctrl + X ?
    "Don't Bring A Knife To A Gun Fight"

  8. #23
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Help! How to send a CTRL+X key to another window?

    Since Shellreef hasn't posted for over 9 years, I wouldn't waste a lot of time waiting for a response.

  9. #24
    Join Date
    Jul 2007
    Location
    in your pocket
    Posts
    339

    Re: Help! How to send a CTRL+X key to another window?

    oh, is this thread 9 years old, oh then they are now too old to post a reply
    "Don't Bring A Knife To A Gun Fight"

Page 2 of 3 FirstFirst 123 LastLast

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

Featured