win32 select all on edit ctrl (textbox)

Ctrl+A is not a built-in accelerator like Ctrl+C and Ctrl+V. This is why you see WM_CUT, WM_PASTE and WM_COPY messages defined, but there is no WM_SELECTALL.

You have to implement this functionality yourself. I did in my MFC app like this:

static BOOL IsEdit( CWnd *pWnd ) 
{
    if ( ! pWnd ) return FALSE ;
    HWND hWnd = pWnd->GetSafeHwnd();
    if (hWnd == NULL)
     return FALSE;

    TCHAR szClassName[6];
    return ::GetClassName(hWnd, szClassName, 6) &&
         _tcsicmp(szClassName, _T("Edit")) == 0;
}

BOOL LogWindowDlg::PreTranslateMessage(MSG* pMsg) 
{
    if(pMsg->message==WM_KEYDOWN)
    {
        if ( pMsg->wParam=='A' && GetKeyState(VK_CONTROL)<0 )
        {
            // User pressed Ctrl-A.  Let's select-all
            CWnd * wnd = GetFocus() ;
            if ( wnd && IsEdit(wnd) )
                ((CEdit *)wnd)->SetSel(0,-1) ;
        }
    }   
    return CDialog::PreTranslateMessage(pMsg);
}

Note, I stole IsEdit from this page: http://support.microsoft.com/kb/145616

I point that out partly because I want to give credit, and partly because I think the IsEdit function (comparing classname strings) is dorky and I want to give blame.


You need to capture that keystroke and do the select all yourself.

Here is some C# code for use with a RichTextBox:

    protected override void OnKeyDown(KeyEventArgs e)
    {
        // Ctrl-A does a Select All in the editor window
        if (e.Control && (e.KeyCode == Keys.A))
        {
            this.SelectAll();
            e.Handled = true;
        }
    }

Sorry, I don't have Win32 code for you.


I tend to use MFC (forgive me) instead of Win32 so I cannot answer this definitively, but I noticed this comment added to a page on an MS site concerning talking with an Edit control (a simple editor within the Edit control):

The edit control uses WM_CHAR for accepting characters, not WM_KEYDOWN etc. You must Translate() your messages or you ironically won't be able to edit the text in the edit control.

I don't know if this applies to BoltBait's response, but I suspect it does.

(I found this at http://msdn.microsoft.com/en-us/library/bb775462(VS.85).aspx)