CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Posts
    399

    Convert OnKeyDown to WM_KEYDOWN

    How can I translate OnKeyDown to WM_KEYDOWN ? I mean, where can I put nRepCount inside lParam ?
    Code:
    void CMyCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
    {
    	// TODO: Add your message handler code here and/or call default
    
    	CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
    
    	::SendMessage(GetParent()->GetSafeHwnd(), WM_KEYDOWN, (WPARAM)nChar, LPARAM(nFlags));
    }
    is correct like this ?
    Code:
    ::SendMessage(GetParent()->GetSafeHwnd(), WM_KEYDOWN, (WPARAM)nChar, MAKELPARAM(nRepCnt, nFlags));
    I guess not … https://docs.microsoft.com/en-us/win...dev/wm-keydown
    Last edited by mesajflaviu; April 19th, 2019 at 01:29 AM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Sending WM_KEYDOWN from OnKeyDown

    What are you trying to achieve?
    Victor Nijegorodov

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Sending WM_KEYDOWN from OnKeyDown

    Quote Originally Posted by VictorN View Post
    What are you trying to achieve?
    A deadlock.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Sending WM_KEYDOWN from OnKeyDown

    Quote Originally Posted by Arjay View Post
    A deadlock.
    Victor Nijegorodov

  5. #5
    Join Date
    Jan 2009
    Posts
    399

    Re: Sending WM_KEYDOWN from OnKeyDown

    If some option would be enabled, CMyCtrl would be send on CMyView, something like that:
    Code:
    void CMyCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
    {
    	// TODO: Add your message handler code here and/or call default
    
    	CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
    
            if(m_bOption)
    	    ::SendMessage(GetParent()->GetSafeHwnd(), WM_KEYDOWN, (WPARAM)nChar, MAKELPARAM(nRepCnt, nFlags));
    }
    is this a bad idea ?
    Last edited by mesajflaviu; April 19th, 2019 at 01:29 AM.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Sending WM_KEYDOWN from OnKeyDown

    Quote Originally Posted by mesajflaviu View Post
    ...
    is this a bad idea ?
    It depends upon why you want to resend this message to the parent of your CMyCtrl...
    Victor Nijegorodov

  7. #7
    Join Date
    Jan 2009
    Posts
    399

    Re: Sending WM_KEYDOWN from OnKeyDown

    Inside CMyCtrl I handle some keyboard keys, and there is some situations where app that own this CMyCtrl have to react to some keyboard keys ... but this depend by app, and in this case the only thing is to set m_bOption to TRUE, and I can have this handle on CMyView ... due to CMyCtrl is spread all over CMyView ...

    Until then, I still don't know how to re-send this message ...

  8. #8
    Join Date
    Jan 2009
    Posts
    399

    Re: Sending WM_KEYDOWN from OnKeyDown

    Or there is another simple way to send this message, WM_KEYDOWN to parent ?

  9. #9
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Sending WM_KEYDOWN from OnKeyDown

    Quote Originally Posted by mesajflaviu View Post
    Or there is another simple way to send this message, WM_KEYDOWN to parent ?
    This message is never sent and must not be. The message is posted to the window by kernel as the result of processing user input. You want this message be received by window, you synthesize user input event. You want this message be reflected to another window, you send custom message from WM_APP range.
    Last edited by Igor Vartanov; April 27th, 2019 at 01:27 PM.
    Best regards,
    Igor

  10. #10
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Sending WM_KEYDOWN from OnKeyDown

    Probably better to send a WM_USER defined message to the parent.

  11. #11
    Join Date
    Jan 2009
    Posts
    399

    Re: Sending WM_KEYDOWN from OnKeyDown

    Yes, agree, but in this WM_USER message I should send the same OnKeyDown parameters … (I corrected the first post, where I wrote OnKeyUp/WM_KEYDOWN).

  12. #12
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Sending WM_KEYDOWN from OnKeyDown

    Quote Originally Posted by mesajflaviu View Post
    Yes, agree, but in this WM_USER message I should send the same OnKeyDown parameters … (I corrected the first post, where I wrote OnKeyUp/WM_KEYDOWN).
    Yes! And there is not a problem at all!
    You can send two parameters (values) as WPARAM and LPARAM. Or you can create some structure(s) and send the pointer(s) to it/them...

    I'd also recommend to send a Registered Windows Message to avoid potential possibility of message ID conflicts.
    Victor Nijegorodov

  13. #13
    Join Date
    Jan 2009
    Posts
    399

    Re: Sending WM_KEYDOWN from OnKeyDown

    I am trying to say that sending WM_KEYDOWN with all information packed to WPARAM and LPARAM will be the shortest way instead to create a custom user message ...

  14. #14
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Sending WM_KEYDOWN from OnKeyDown

    Quote Originally Posted by mesajflaviu View Post
    I am trying to say that sending WM_KEYDOWN with all information packed to WPARAM and LPARAM will be the shortest way instead to create a custom user message ...
    Or maybe it will be more confusing to folks that have to maintain your code?

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