How to implement a WM_COPY handler for a CEdit derived control
-
Hi, I have written a CEdit derived control for displaying formatted float values. Now I want to implement a handler for WM_COPY and WM_PASTE. The WM_COPY handler for e.g. must copy the unformatted(!) float value to the clipboard. I have tried something like BEGIN_MESSAGE_MAP(CMyNumberEdit, CEdit) ON_MESSAGE(WM_COPY, OnCopy) END_MESSAGE_MAP() ... but OnCopy is never called. Can anyone help me? THX
-
Hi, I have written a CEdit derived control for displaying formatted float values. Now I want to implement a handler for WM_COPY and WM_PASTE. The WM_COPY handler for e.g. must copy the unformatted(!) float value to the clipboard. I have tried something like BEGIN_MESSAGE_MAP(CMyNumberEdit, CEdit) ON_MESSAGE(WM_COPY, OnCopy) END_MESSAGE_MAP() ... but OnCopy is never called. Can anyone help me? THX
madmax0001 wrote:
ON_MESSAGE(WM_COPY, OnCopy)
Try:
ON_COMMAND(WM_COPY, OnCopy)
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"We will be known forever by the tracks we leave." - Native American Proverb
-
madmax0001 wrote:
ON_MESSAGE(WM_COPY, OnCopy)
Try:
ON_COMMAND(WM_COPY, OnCopy)
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"We will be known forever by the tracks we leave." - Native American Proverb
Hi, I've tried but it is also never called.
-
Hi, I've tried but it is also never called.
Something else must be up. I used the following and both methods get called:
BEGIN_MESSAGE_MAP(CEditEx, CEdit)
//{{AFX_MSG_MAP(CEditEx)
ON_MESSAGE(WM_COPY, OnCopy)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
...
LRESULT CEditEx::OnCopy( WPARAM wParam, LPARAM lParam )
{
// handle it here
return 0;
}
...
LRESULT CEditEx::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if (WM_COPY == message)
; // or herereturn CEdit::WindowProc(message, wParam, lParam);
}
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"We will be known forever by the tracks we leave." - Native American Proverb
-
Something else must be up. I used the following and both methods get called:
BEGIN_MESSAGE_MAP(CEditEx, CEdit)
//{{AFX_MSG_MAP(CEditEx)
ON_MESSAGE(WM_COPY, OnCopy)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
...
LRESULT CEditEx::OnCopy( WPARAM wParam, LPARAM lParam )
{
// handle it here
return 0;
}
...
LRESULT CEditEx::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if (WM_COPY == message)
; // or herereturn CEdit::WindowProc(message, wParam, lParam);
}
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"We will be known forever by the tracks we leave." - Native American Proverb
Hi, thank you very much. You're right. I have found my problem. I had implemented a handler for WM_CHAR where my editbox content is formatted. To process WM_COPY commands I must call the base class procedure for WM_CHAR for nonprintable characters like this: void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { if(isprint(nChar)==0){ CEdit::OnChar(nChar, nRepCnt, nFlags); return; } // Further processing here } Now the OnCopy implementation is called ! :-)