如何在c ++中对文本框中的值进行硬编码

时间:2010-02-05 04:27:51

标签: c++ winapi

我使用以下代码弹出身份验证对话框。我想在我的代码中硬编码密码并使其成为只读文本框。我该怎么办?

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

2 个答案:

答案 0 :(得分:3)

如果您使用CONTROL关键字而不是EDITTEXT关键字,则可以完全控制所有字段,请使用

CONTROL     "mypassword", IDC_PASSWD_EDIT, "Edit", 
            ES_LEFT | WS_BORDER | ES_PASSWORD | ES_READONLY, 
            84,41,57,12

而不是

EDITTEXT    IDC_PASSWD_EDIT,84,41,57,12,ES_PASSWORD | ES_READONLY | NOT WS_TABSTOP  

答案 1 :(得分:0)

来自记忆:

HWND hwnd = ...//handle to the dialog
::SetDlgItemText(hwnd, IDC_STATIC_PASSWD, "YourText");
::EnableWindow(::GetDlgItem(hwnd, IDC_STATIC_PASSWD), FALSE);