Discussion:
CEdit, CFormView and Cut, Copy Paste commands
(too old to reply)
Janiv Ratson
2006-04-02 12:01:03 UTC
Permalink
Hi,
I have a CFormView derived class.
My context menu includes the Copy, Cut and Paste commands and it works.
However, I cannot use the keyboard for these commands.
I've followed the instructions in:
KB article "How to Enable Edit Menu Commands for Edit Controls"
Article ID: Q145616
(http://support.microsoft.com/support/kb/articles/q145/6/16.asp)
but it does not work for me.
The handlers are never been called.
Any idead?
Thanks,
Janiv Ratson.
Ajay Kalra
2006-04-02 16:21:29 UTC
Permalink
What do you mean by keyboard does not work? Do you mean accelerators,
eg Ctrl+C etc. ? If yes, make sure your accelerator table has all these
combination in it.

--
Ajay
Janiv Ratson
2006-04-03 08:24:48 UTC
Permalink
Hello and thanks,

The accelerator table is declared in the rc file.
I'm writing an MDI application.
Maybe, there is a problem because the accelerator table is declared in the
main(app) rc file, while the CFormView is declared in my MFC extension dll.
Thanks,
J.
Post by Ajay Kalra
What do you mean by keyboard does not work? Do you mean accelerators,
eg Ctrl+C etc. ? If yes, make sure your accelerator table has all these
combination in it.
--
Ajay
Ajay Kalra
2006-04-03 10:20:28 UTC
Permalink
Post by Janiv Ratson
because the accelerator table is declared in the
main(app) rc file, while the CFormView is declared in my MFC extension dll.
No, that makes no difference. IIRC, you will need to define accelerator
table for each of the doctemplates.

--
Ajay Kalra [MVP - VC++]
***@yahoo.com
Janiv Ratson
2006-04-03 13:45:29 UTC
Permalink
Hi,
The accelerator table is defined for each of my document template in the
main(app) rc file, and not in every MFC extension DLL. I have 3 doc template
and 3 accelerator tables.
What is IIRC ?
What can I do?
Thanks,
j.
Post by Ajay Kalra
Post by Janiv Ratson
because the accelerator table is declared in the
main(app) rc file, while the CFormView is declared in my MFC extension
dll.
No, that makes no difference. IIRC, you will need to define accelerator
table for each of the doctemplates.
--
Ajay Kalra [MVP - VC++]
Ajay Kalra
2006-04-03 14:00:37 UTC
Permalink
If you have accelerator tables defined correctly, you should step in
the code where TranslateAccelerator is called.
CMDIFrameWnd::PreTrnaslateMessage has the following code that will be
hit if its translated correctly:


// translate accelerators for frame and any children
if (m_hAccelTable != NULL &&
::TranslateAccelerator(m_hWnd, m_hAccelTable, pMsg))
{
return TRUE;
}

If your code does not hit this when you hit Ctrl+C etc, its very likely
your accelerator table is not loaded. Then you trace where
m_hAccelTable is being loaded and start from there.


IIRC = If I recall correctly.


---
Ajay
Janiv Ratson
2006-04-06 10:58:57 UTC
Permalink
Hello Ajay,
I've cheked the code as you've suggested me.
The ::TranslateAccelerator(m_hWnd, m_hAccelTable, pMsg)) return FALSE when I
press the CTRL+C accelerator.
The return TRUE is never reached.
looking for the m_hAccelTable loading, I see that the accelerator loading is
done inside CFrameWnd::LoadFrame by calling the
LoadAccelTable(MAKEINTRESOURCE(nIDResource)); method.
However, this call is called only once via my
pMainFrame->LoadFrame(IDR_MAINFRAME) function call.
It is never been called for the other document template (IDR_SCREEN_VIEW,
IDR_AUTOMATION_VIEW and IDR_NETWORK_VIEW).
The accelerator tables for each of those document templates are defined in
the main app rc file.
Will you tell me what am I doing wrong ?
Thanks,
J.
Post by Ajay Kalra
If you have accelerator tables defined correctly, you should step in
the code where TranslateAccelerator is called.
CMDIFrameWnd::PreTrnaslateMessage has the following code that will be
// translate accelerators for frame and any children
if (m_hAccelTable != NULL &&
::TranslateAccelerator(m_hWnd, m_hAccelTable, pMsg))
{
return TRUE;
}
If your code does not hit this when you hit Ctrl+C etc, its very likely
your accelerator table is not loaded. Then you trace where
m_hAccelTable is being loaded and start from there.
IIRC = If I recall correctly.
---
Ajay
Janiv Ratson
2006-04-06 11:43:37 UTC
Permalink
Another finding.
When I press the Ctrl+C accelerator, the code that is called is
CMDIChildWnd::PreTranslateMessage(MSG* pMsg) which returns NULL, because in
the method CFrameWnd::GetDefaultAccelerator() which calls hAccel =
pDoc->GetDefaultAccelerator() the implementation is rerutn NULL;
Thanks,
j.
Post by Janiv Ratson
Hello Ajay,
I've cheked the code as you've suggested me.
The ::TranslateAccelerator(m_hWnd, m_hAccelTable, pMsg)) return FALSE when
I press the CTRL+C accelerator.
The return TRUE is never reached.
looking for the m_hAccelTable loading, I see that the accelerator loading
is done inside CFrameWnd::LoadFrame by calling the
LoadAccelTable(MAKEINTRESOURCE(nIDResource)); method.
However, this call is called only once via my
pMainFrame->LoadFrame(IDR_MAINFRAME) function call.
It is never been called for the other document template (IDR_SCREEN_VIEW,
IDR_AUTOMATION_VIEW and IDR_NETWORK_VIEW).
The accelerator tables for each of those document templates are defined in
the main app rc file.
Will you tell me what am I doing wrong ?
Thanks,
J.
Post by Ajay Kalra
If you have accelerator tables defined correctly, you should step in
the code where TranslateAccelerator is called.
CMDIFrameWnd::PreTrnaslateMessage has the following code that will be
// translate accelerators for frame and any children
if (m_hAccelTable != NULL &&
::TranslateAccelerator(m_hWnd, m_hAccelTable, pMsg))
{
return TRUE;
}
If your code does not hit this when you hit Ctrl+C etc, its very likely
your accelerator table is not loaded. Then you trace where
m_hAccelTable is being loaded and start from there.
IIRC = If I recall correctly.
---
Ajay
Ajay Kalra
2006-04-06 14:08:38 UTC
Permalink
CMultiDoctemplate loads accelerator table in
CMultiDocTemplate::LoadTemplate. Put a break point there and make sure
your table is loaded correctly. Its stored in m_hAccelTable.

BTW, what sort of DLLs do you have? Extension or Regular?

---
Ajay
Janiv Ratson
2006-04-06 15:54:52 UTC
Permalink
Hi and thanks so much.
The table is loaded indeed using the right m_nIDResource, but when I press
the CTRL+C accelerator, it goes to the CMDIFrameWnd::PreTranslateMessage
method and the m_hAccelTable member is not the one that was created for the
correct nIDResource.
What shall I do then?
Thanks again,
J.
Post by Ajay Kalra
CMultiDoctemplate loads accelerator table in
CMultiDocTemplate::LoadTemplate. Put a break point there and make sure
your table is loaded correctly. Its stored in m_hAccelTable.
BTW, what sort of DLLs do you have? Extension or Regular?
---
Ajay
Ajay Kalra
2006-04-06 15:16:39 UTC
Permalink
Post by Janiv Ratson
it goes to the CMDIFrameWnd::PreTranslateMessage
method and the m_hAccelTable member is not the one that was created for the
When you hit Ctrl+C, is your document (as defined in the doctemplate)
active?

---
Ajay
Janiv Ratson
2006-04-06 16:39:05 UTC
Permalink
Yes
Post by Ajay Kalra
Post by Janiv Ratson
it goes to the CMDIFrameWnd::PreTranslateMessage
method and the m_hAccelTable member is not the one that was created for the
When you hit Ctrl+C, is your document (as defined in the doctemplate)
active?
---
Ajay
Ajay Kalra
2006-04-06 18:07:23 UTC
Permalink
I just built a default wizard generated MDI application. Inserted a new
accelerator table with the same ID as the doctemplate. It all works as
expected. I dont know what you could be doing wrong.

Areas to look:

HACCEL CFrameWnd::GetDefaultAccelerator()

This should have the same accelerator table as the doctemplate. This is
called by CMDIChildWnd::PreTranslateMessage and the following code in
this method translates it:

return hAccel != NULL &&
::TranslateAccelerator(GetMDIFrame()->m_hWnd, hAccel, pMsg);

As I said earlier, it all works fine for me without doing any extra
work.

---
Ajay
Janiv Ratson
2006-04-09 14:30:49 UTC
Permalink
Hello,
I'm getting crazy, I don;t know what is the problem with my code.

The HACCEL CFrameWnd::GetDefaultAccelerator() returns the appropriate
accelerator (which was loaded via ::LoadAccelerator function and the
appropriate resource ID).

Than, there is a call to ::TranslateAccelerator which in my case accept:
the CMAinFrame CWnd* as first parameter,
the appropriate default accelerator and the pMSG struct.

this function return FALSE somehow.

then in the BOOL CMDIFrameWnd::PreTranslateMessage(MSG* pMsg) function
(after returning as FALSE from pActiveChild->PreTranslateMessage(pMsg)
method) it tries to call TranslateAccelerator with the m_hAccelTable member
of CMDIFrameWnd object, which also returns FALSE.

Finally, the return value of the CMDIFrameWnd::PreTranslateMessage function
is FALSE.

Please help,
thanks.
J.
Post by Ajay Kalra
I just built a default wizard generated MDI application. Inserted a new
accelerator table with the same ID as the doctemplate. It all works as
expected. I dont know what you could be doing wrong.
HACCEL CFrameWnd::GetDefaultAccelerator()
This should have the same accelerator table as the doctemplate. This is
called by CMDIChildWnd::PreTranslateMessage and the following code in
return hAccel != NULL &&
::TranslateAccelerator(GetMDIFrame()->m_hWnd, hAccel, pMsg);
As I said earlier, it all works fine for me without doing any extra
work.
---
Ajay
Loading...