Search code examples
windowswinapiscrolleditcontrol

Programmatically scrolling a Windows edit control


Is there any way to programmatically scroll a single-line edit control in Windows?

For example, if the text in an edit control is too large to display at once, then the default behavior when the edit control gets the focus is to select all text and show the end of the text. I'd like to instead show the beginning of the text (while still leaving all text selected).


Solution

  • Although there's (apparently) no API for scrolling to the beginning and selecting all text, it seems to work to simulate the keystrokes that would do the same:

    #ifndef CTRL               
    #define CTRL(x) (x&037)    
    #endif
    
    SendMessage(edit_handle, WM_KEYDOWN, VK_HOME, 0);
    SendMessage(edit_handle, WM_CHAR, CTRL('A'), 0);