Search code examples
c++winapitextboxdefaultplaceholder

How to set up default background (greyed out) text for textbox in C++ Win32 GUI?


When creating a text box

hwnd = CreateWindowEx(0, "EDIT", [...])

How to set the placeholder (default, grey) text on the background of that box, which disappears when providing some input?


Solution

  • After creating the edit control, send the EM_SETCUEBANNER message to it:

    SendMessage(hwndEdit, EM_SETCUEBANNER, 0, (LPARAM)L"Default text");
    

    Or use the Edit_SetCueBannerText macro:

    Edit_SetCueBannerText(hwndEdit, L"Default text");
    

    Either way, you also need to enable Visual Styles.