Поле с постановкой/снятием ES_PASSWORD
От: Слава Шевцов Россия http://www.rentaguru.ru/
Дата: 30.03.05 17:35
Оценка:
Есть поле с паролем. Пытаюсь сделать переключение по чекбоксу со звёздочек на нормальный текст (чтобы пользователь смог прочитать содержимое) и обратно. Делаю так:

    DWORD dwStyle;

    if(SendMessage(m_hwndPasswordCheck, BM_GETCHECK, 0, 0) == BST_CHECKED)
    {
        dwStyle = GetWindowLong(m_hwndEditPassword, GWL_STYLE);
        dwStyle = dwStyle | ES_PASSWORD;
        SetWindowLong(m_hwndEditPassword, GWL_STYLE, dwStyle);
    }
    else
    {
        dwStyle = GetWindowLong(m_hwndEditPassword, GWL_STYLE);
        dwStyle = dwStyle & ~ES_PASSWORD;
        SetWindowLong(m_hwndEditPassword, GWL_STYLE, dwStyle);
    }


Не получается В чём причина?
----------------------------------------------------------------------------------------------
Rentaguru
Re: Поле с постановкой/снятием ES_PASSWORD
От: Назарет http://www.trenajor.ru/
Дата: 31.03.05 01:43
Оценка:
Здравствуйте, Слава Шевцов, Вы писали:

СШ> SetWindowLong(m_hwndEditPassword, GWL_STYLE, dwStyle);

СШ>Не получается В чём причина?

Эта функция не переключает стиль.
Наверное, нужно использовать EM_SETPASSWORDCHAR


lResult = SendMessage(      // returns LRESULT in lResult     
         (HWND) hWndControl,      // handle to destination control     
         (UINT) EM_SETPASSWORDCHAR,      // message ID     
         (WPARAM) wParam,      // = (WPARAM) () wParam;    
         (LPARAM) lParam      // = 0; not used, must be zero );



Parameters

wParam
Specifies the character to be displayed in place of the characters typed by the user. If this parameter is zero, the control removes the current password character and displays the characters typed by the user.
lParam
This parameter is not used
The ES_PASSWORD style is removed if an EM_SETPASSWORDCHAR message is sent with the wParam parameter set to zero.


wParam=0 ; // символы видны
wParam='*'. ; // символы заменяются звездочкой
Re: Поле с постановкой/снятием ES_PASSWORD
От: Chez Россия  
Дата: 01.04.05 12:21
Оценка: 4 (1)
Здравствуйте, Слава Шевцов, Вы писали:
СШ>Не получается В чём причина?
И я сталкивался с этим. Результат исследования показал, что единственный выход — пересоздавать edit-box.

MSDN говорит:

Edit Control Styles

--------------------------------------------------------------------------------

To create an edit control using the CreateWindow or CreateWindowEx function, specify the EDIT class, appropriate window style constants, and a combination of the following edit control styles. After the control has been created, these styles cannot be modified, except as noted.
....

ES_PASSWORD
Displays an asterisk (*) for each character typed into the edit control. This style is valid only for single-line edit controls.
Windows XP: If the edit control is from user32.dll, the default password character is an asterisk. However, if the edit control is from comctl32.dll version 6, the default character is a black circle.

To change the characters that is displayed, or set or clear this style, use the EM_SETPASSWORDCHAR message.

Note Comctl32.dll version 6 is not redistributable but it is included in Microsoft® Windows® XP or later. To use Comctl32.dll version 6, specify it in a manifest. For more information on manifests, see Using Windows XP Visual Styles.


Хотя в стровке по EM_SETPASSWORDCHAR написано:

If an edit control is created with the ES_PASSWORD style, the default password character is set to an asterisk (*). If an edit control is created without the ES_PASSWORD style, there is no password character. The ES_PASSWORD style is removed if an EM_SETPASSWORDCHAR message is sent with the wParam parameter set to zero.

Это почему-то не помогало. Хотя может просто Update окну надо было сделать...

Chez, ICQ#161095094

Posted via:RSDN@Home;version:1.1.3;muzikstamp:Dvar — Ya Raii Ta Hirrih

Re[2]: Поле с постановкой/снятием ES_PASSWORD
От: Назарет http://www.trenajor.ru/
Дата: 03.04.05 04:03
Оценка: 8 (1)
Здравствуйте, Chez, Вы писали:

C>Это почему-то не помогало. Хотя может просто Update окну надо было сделать...


Совершенно верно. Но не UpdateWindow, а InvalidateRect
Re[3]: Поле с постановкой/снятием ES_PASSWORD
От: Слава Шевцов Россия http://www.rentaguru.ru/
Дата: 04.04.05 16:43
Оценка:
Здравствуйте, Назарет, Вы писали:

C>>Это почему-то не помогало. Хотя может просто Update окну надо было сделать...


Н>Совершенно верно. Но не UpdateWindow, а InvalidateRect


Ни то, ни другое не помогло. После долгих испытаний пришёл к такому работающему варианту:

    DWORD dwStyle = GetWindowLong(m_hwndEditPassword, GWL_STYLE);

    // По чекбоксу либо скрываем, либо показываем пароль в поле
    if(SendMessage(m_hwndPasswordCheck, BM_GETCHECK, 0, 0) == BST_CHECKED)
    {
        // Устанавливаем парольное поле
        SetWindowLong(m_hwndEditPassword, GWL_STYLE, dwStyle | ES_PASSWORD);
        SendMessage(m_hwndEditPassword, EM_SETPASSWORDCHAR, '*', NULL);
    }
    else
    {
        // Устанавливаем непарольное поле
        SetWindowLong(m_hwndEditPassword, GWL_STYLE, dwStyle & ~ES_PASSWORD);
        SendMessage(m_hwndEditPassword, EM_SETPASSWORDCHAR, NULL, NULL);
    }

    SetFocus(m_hwndEditPassword);    // Переводим фокус в поле с паролём
    SetFocus(m_hwndPasswordCheck);    // Возвращаем фокус на чекбокс


Только не спрашивайте почему это работает
----------------------------------------------------------------------------------------------
Rentaguru
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.