How to set up default background (greyed out) text

2019-02-28 07:50发布

When creating a text box

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

How to set default, grey text on the background of that box, which disappears when providing some input? An example. I'm using codeblocks.

EDIT:

#include <commctrl.h>

[...]

HWND hwndEdit = CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 10, 110, 300, 20, hwnd, NULL, hThisInstance, NULL);
SendMessage(hwndEdit, EM_SETCUEBANNER, FALSE, (LPARAM) L"Default text");

1条回答
Root(大扎)
2楼-- · 2019-02-28 08:29

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.

查看更多
登录 后发表回答