4

I have been working in a MFC project and i have seen that Ctrl + A does not work for any of the CEdit used in this project.

But if i add the following lines in the StdAfx.h file of my project, suddenly it starts working.

#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

Now what i understand from this code snippet is that we are telling the linker explicitly that we want to use ComCtl32.dll version 6.0.

Does that mean, without this line my project uses earlier version of ComCtl32.dll which does not have the Ctrl + A support?

Rasheduzzaman Sourov
  • 1,375
  • 2
  • 15
  • 36

2 Answers2

1

It looks like Ctrl-A isn't handled by default in that version. If you want Ctrl-A support, you need to extend from CEdit and implement PreTranslateMessage

See here.

void CEditExtended::PreTranslateMessage(MSG* pMsg)
{
     if(pMsg->message == WM_KEYUP )
     {
         if ( (LOWORD(pMsg->wParam) & VK_CONTROL) == VK_CONTROL )
         {
           SetSel(0, -1);
         }
     }
     return CEdit::PreTranslateMessage(pMsg);
}
Community
  • 1
  • 1
lcs
  • 4,227
  • 17
  • 36
  • you are right, i have done that. But i wanted to know/be sure about the reason why it is not working. – Rasheduzzaman Sourov Sep 01 '15 at 17:15
  • 2
    The function should return TRUE if it handles the key stroke. Not returning TRUE might cause that the keystroke is handled twice. Also I would use WM_KEYDOWN and not KEYUP. Accelerator are doing the same. – xMRi Sep 02 '15 at 06:04
  • Why is this code checking `LOWORD(wParam)` for `VK_CONTROL` and ignoring `VK_A`? This code is not ensuring that the user is actually pressing `CTRL-A`, but is simply reacting when `CTRL` itself is being released. I would think it needs to be like this instead: `if ((pMsg->message == WM_KEYDOWN) && (pMsg->wParam == 'A') && (GetKeyState(VK_CONTROL) < 0)) { SetSel(0, -1); return TRUE; } else return CEdit::PreTranslateMessage(pMsg);` – Remy Lebeau Sep 03 '15 at 00:25
  • @Remy, yes i have added the check. BTW, will there be any problem if i handle it in `WindowProc()` instead of `PreTranslateMessage()`? – Rasheduzzaman Sourov Sep 03 '15 at 05:15
1

The reason is possibly an accelerator you have that is defined in the main application.

And this accelerator handles this keystroke.

xMRi
  • 14,982
  • 3
  • 26
  • 59