When you catch the key combo's, and when you catch the user clicking on
a particular menu option, you can set a flag. With
PreTranslateMessage, you can throw events that the key combo's would
normally do, like WM_COPY. Then you can handle that message. In the
WM_COPY message handler, you can get to the text before windows does,
and you can choose not to continue if necessary. With
PreTranslateMessage, I usually either set flags, or execute key combo's
not normally used by default (like F3 is "find next" in a search).
Here's an example I just found:
"""
BOOL CDlgExempt::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
if(pMsg->wParam == VK_F3)
{
if(m_bSearched){
AfxGetApp()->BeginWaitCursor();
m_iSearchNum++;
EndSearching();
AfxGetApp()->EndWaitCursor();
return TRUE;
}
}
}
return CDialog::PreTranslateMessage(pMsg);
}
"""
I apologize for the Python-like commenting quotes. Make sure the
message is a key down message. This can handle all messages before
they are sent to MFC, so you can check if pMsg->message == WM_COPY,
etc. Then I made sure that pMsg->wParam was F3 (these codes can be
found in windows.h I think on msdn.com). The m_bSearched flag is a
boolean telling me if a search has been performed. Then I set up a
wait cursor (the hourglass), and call EndSearching(), which will update
the controls on this particular dialog, advance a row in the recordset,
etc. Notice how I returned TRUE in this case. I didn't want windows
to mess with F3 if what I did worked correctly. Otherwise, you can
have Windows do what they would like, by returning
CDialog::PreTranslateMessage(pMsg);
HTH.
Benry
Post by gloomygodWell, i'm not sure about howto use the PreTranslateMessage() function, but
i'm going to look for an example for clarify it. Anyway, are you sure that
catching the key combination with that method, i can get access to the
content of the clipboard before mfc manage it???? And what about the Edit
menu>Cut... actions?
Well, i'll look for an example. If you have one, and have some free time,
please, post it.
Again, thaks in advance.
See u.
David.
Post by Joseph M. NewcomerAlso, you have to subclass the edit control and intercept WM_CUT, WM_COPY and WM_PASTE
messages, which can be sent by various mechanisms.
joe
Post by BenryUse the PreTranslateMessage handler function, and check if the user is
pressing "CTRL" and "c" or "v" etc. You can handle any key combonation
press using PreTranslateMessage function. Let us know if you need an
example (too busy to dig for one right now, but I can get you one).
-Benry
Post by gloomygodGood morning every1.
I got a problem here wich is troubling my nerves!!!!
I need to catch the Copy/paste/cut event in an edit to put some code before
the content of the edit is passed to the clipboard and viceversa.
I know i can fire those events with the Copy(), paste(), and Cut() methods
programatically, but that's not what i want. I need to catch the event when
the USER makes a ctrl+c ctrl+v Edit menu>Command .
I imagined that i could do it catching a message, and tried WM_COPY and
those, but again, this messages are passed to the edit when you make a call
to edit.Copy() method, but nope when the user fires the event!!!!
Please, some help aprecciated.
Thanks in advance.
David.
Joseph M. Newcomer [MVP]
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
--
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth