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
Re: Sending WM_KEYDOWN from OnKeyDown
What are you trying to achieve?
Re: Sending WM_KEYDOWN from OnKeyDown
Quote:
Originally Posted by
VictorN
What are you trying to achieve?
A deadlock.
Re: Sending WM_KEYDOWN from OnKeyDown
Quote:
Originally Posted by
Arjay
A deadlock.
:cry::cry::cry:
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 ?
Re: Sending WM_KEYDOWN from OnKeyDown
Quote:
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...
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 ...
Re: Sending WM_KEYDOWN from OnKeyDown
Or there is another simple way to send this message, WM_KEYDOWN to parent ?
Re: Sending WM_KEYDOWN from OnKeyDown
Probably better to send a WM_USER defined message to the parent.
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).
Re: Sending WM_KEYDOWN from OnKeyDown
Quote:
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.
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 ...
Re: Sending WM_KEYDOWN from OnKeyDown
Quote:
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?
Re: Sending WM_KEYDOWN from OnKeyDown
Quote:
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.