-
April 17th, 2019, 06:50 AM
#1
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.
-
April 17th, 2019, 01:40 PM
#2
Re: Sending WM_KEYDOWN from OnKeyDown
What are you trying to achieve?
Victor Nijegorodov
-
April 17th, 2019, 02:50 PM
#3
Re: Sending WM_KEYDOWN from OnKeyDown
Originally Posted by VictorN
What are you trying to achieve?
A deadlock.
-
April 17th, 2019, 02:53 PM
#4
Re: Sending WM_KEYDOWN from OnKeyDown
Victor Nijegorodov
-
April 18th, 2019, 12:29 AM
#5
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.
-
April 18th, 2019, 01:55 AM
#6
Re: Sending WM_KEYDOWN from OnKeyDown
Originally Posted by mesajflaviu
...
is this a bad idea ?
It depends upon why you want to resend this message to the parent of your CMyCtrl...
Victor Nijegorodov
-
April 18th, 2019, 02:46 AM
#7
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 ...
-
April 18th, 2019, 03:22 AM
#8
Re: Sending WM_KEYDOWN from OnKeyDown
Or there is another simple way to send this message, WM_KEYDOWN to parent ?
-
April 27th, 2019, 12:55 PM
#9
Re: Sending WM_KEYDOWN from OnKeyDown
Originally Posted by mesajflaviu
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
-
April 18th, 2019, 07:40 AM
#10
Re: Sending WM_KEYDOWN from OnKeyDown
Probably better to send a WM_USER defined message to the parent.
-
April 19th, 2019, 01:28 AM
#11
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).
-
April 19th, 2019, 01:44 AM
#12
Re: Sending WM_KEYDOWN from OnKeyDown
Originally Posted by mesajflaviu
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
-
April 19th, 2019, 02:36 AM
#13
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 ...
-
April 19th, 2019, 10:32 PM
#14
Re: Sending WM_KEYDOWN from OnKeyDown
Originally Posted by mesajflaviu
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|