Path: blob/main/crypto/krb5/src/windows/leashdll/winutil.c
34914 views
#include <windows.h>1#include "leash-int.h"23//#include <string.h>45static ATOM sAtom = 0;6static HINSTANCE shInstance = 0;78/* Callback for the MITPasswordControl9This is a replacement for the normal edit control. It does not show the10annoying password char in the edit box so that the number of chars in the11password are not known.12*/1314#define PASSWORDCHAR '#'15#define DLGHT(ht) (HIWORD(GetDialogBaseUnits())*(ht)/8)16#define DLGWD(wd) (LOWORD(GetDialogBaseUnits())*(wd)/4)1718static19LRESULT20CALLBACK21MITPasswordEditProc(22HWND hWnd,23UINT message,24WPARAM wParam,25LPARAM lParam26)27{28static SIZE pwdcharsz;29BOOL pass_the_buck = FALSE;3031if (message > WM_USER && message < 0x7FFF)32pass_the_buck = TRUE;3334switch(message)35{36case WM_GETTEXT:37case WM_GETTEXTLENGTH:38case WM_SETTEXT:39pass_the_buck = TRUE;40break;41case WM_PAINT:42{43HDC hdc;44PAINTSTRUCT ps;45RECT r;4647hdc = BeginPaint(hWnd, &ps);48GetClientRect(hWnd, &r);49Rectangle(hdc, 0, 0, r.right, r.bottom);50EndPaint(hWnd, &ps);51}52break;53case WM_SIZE:54{55MoveWindow(GetDlgItem(hWnd, 1), DLGWD(2), DLGHT(2),56pwdcharsz.cx / 2, pwdcharsz.cy, TRUE);57}58break;59case WM_LBUTTONDOWN:60case WM_SETFOCUS:61{62SetFocus(GetDlgItem(hWnd, 1));63}64break;65case WM_CREATE:66{67HWND heditchild;68char pwdchar = PASSWORDCHAR;69HDC hdc;70/* Create a child window of this control for default processing. */71hdc = GetDC(hWnd);72GetTextExtentPoint32(hdc, &pwdchar, 1, &pwdcharsz);73ReleaseDC(hWnd, hdc);7475heditchild =76CreateWindow("edit", "", WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL |77ES_LEFT | ES_PASSWORD | WS_TABSTOP,780, 0, 0, 0,79hWnd,80(HMENU)1,81((LPCREATESTRUCT)lParam)->hInstance,82NULL);83SendMessage(heditchild, EM_SETPASSWORDCHAR, PASSWORDCHAR, 0L);84}85break;86}8788if (pass_the_buck)89return SendMessage(GetDlgItem(hWnd, 1), message, wParam, lParam);90return DefWindowProc(hWnd, message, wParam, lParam);91}9293BOOL94Register_MITPasswordEditControl(95HINSTANCE hInst96)97{98if (!sAtom) {99WNDCLASS wndclass;100101memset(&wndclass, 0, sizeof(WNDCLASS));102103shInstance = hInst;104105wndclass.style = CS_HREDRAW | CS_VREDRAW;106wndclass.lpfnWndProc = (WNDPROC)MITPasswordEditProc;107wndclass.cbClsExtra = sizeof(HWND);108wndclass.cbWndExtra = 0;109wndclass.hInstance = shInstance;110wndclass.hbrBackground = (void *)(COLOR_WINDOW + 1);111wndclass.lpszClassName = MIT_PWD_DLL_CLASS;112wndclass.hCursor = LoadCursor((HINSTANCE)NULL, IDC_IBEAM);113114sAtom = RegisterClass(&wndclass);115}116return sAtom ? TRUE : FALSE;117}118119BOOL120Unregister_MITPasswordEditControl(121HINSTANCE hInst122)123{124BOOL result = TRUE;125126if ((hInst != shInstance) || !sAtom) {127SetLastError(ERROR_INVALID_PARAMETER);128return FALSE;129}130131result = UnregisterClass(MIT_PWD_DLL_CLASS, hInst);132if (result) {133sAtom = 0;134shInstance = 0;135}136return result;137}138139140