How to hardcode a value in a texbox in c++
I am using the below code to popup the authentica开发者_运维知识库tion dialog. I want to hard-code the password in my code and make it a read-only text box. What should I do?
IDD_LOGIN_AUTH_DIALOG DIALOG DISCARDABLE 0, 0, 148, 82
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Authentication"
FONT 8, "MS Shell Dlg"
BEGIN
LTEXT "Host:",IDC_STATIC_HOST,7,8,36,10,SS_CENTERIMAGE |
NOT WS_GROUP
EDITTEXT IDC_VNCHOST,46,7,95,12,ES_AUTOHSCROLL | ES_READONLY |
NOT WS_TABSTOP
CONTROL 108,IDC_STATIC_LOGO,"Static",SS_BITMAP,7,23,32,30
RTEXT "User name:",IDC_STATIC_LOGIN,41,25,39,10,SS_CENTERIMAGE
EDITTEXT IDC_LOGIN_EDIT,84,24,57,12,ES_AUTOHSCROLL
RTEXT "Password:",IDC_STATIC_PASSWD,41,42,39,10,SS_CENTERIMAGE
EDITTEXT IDC_PASSWD_EDIT,84,41,57,12,ES_PASSWORD | ES_READONLY |
NOT WS_TABSTOP
DEFPUSHBUTTON "&OK",IDOK,20,61,50,14
PUSHBUTTON "&Cancel",IDCANCEL,77,61,50,14
END
You get full control over all fields if you use the CONTROL keyword rather than the EDITTEXT keyword, use
CONTROL "mypassword", IDC_PASSWD_EDIT, "Edit",
ES_LEFT | WS_BORDER | ES_PASSWORD | ES_READONLY,
84,41,57,12
instead of
EDITTEXT IDC_PASSWD_EDIT,84,41,57,12,ES_PASSWORD | ES_READONLY | NOT WS_TABSTOP
From memory:
HWND hwnd = ...//handle to the dialog
::SetDlgItemText(hwnd, IDC_STATIC_PASSWD, "YourText");
::EnableWindow(::GetDlgItem(hwnd, IDC_STATIC_PASSWD), FALSE);
精彩评论