1 #include <windows.h> 2 #include "leash-int.h" 3 4 //#include <string.h> 5 6 static ATOM sAtom = 0; 7 static HINSTANCE shInstance = 0; 8 9 /* Callback for the MITPasswordControl 10 This is a replacement for the normal edit control. It does not show the 11 annoying password char in the edit box so that the number of chars in the 12 password are not known. 13 */ 14 15 #define PASSWORDCHAR '#' 16 #define DLGHT(ht) (HIWORD(GetDialogBaseUnits())*(ht)/8) 17 #define DLGWD(wd) (LOWORD(GetDialogBaseUnits())*(wd)/4) 18 19 static 20 LRESULT 21 CALLBACK 22 MITPasswordEditProc( 23 HWND hWnd, 24 UINT message, 25 WPARAM wParam, 26 LPARAM lParam 27 ) 28 { 29 static SIZE pwdcharsz; 30 BOOL pass_the_buck = FALSE; 31 32 if (message > WM_USER && message < 0x7FFF) 33 pass_the_buck = TRUE; 34 35 switch(message) 36 { 37 case WM_GETTEXT: 38 case WM_GETTEXTLENGTH: 39 case WM_SETTEXT: 40 pass_the_buck = TRUE; 41 break; 42 case WM_PAINT: 43 { 44 HDC hdc; 45 PAINTSTRUCT ps; 46 RECT r; 47 48 hdc = BeginPaint(hWnd, &ps); 49 GetClientRect(hWnd, &r); 50 Rectangle(hdc, 0, 0, r.right, r.bottom); 51 EndPaint(hWnd, &ps); 52 } 53 break; 54 case WM_SIZE: 55 { 56 MoveWindow(GetDlgItem(hWnd, 1), DLGWD(2), DLGHT(2), 57 pwdcharsz.cx / 2, pwdcharsz.cy, TRUE); 58 } 59 break; 60 case WM_LBUTTONDOWN: 61 case WM_SETFOCUS: 62 { 63 SetFocus(GetDlgItem(hWnd, 1)); 64 } 65 break; 66 case WM_CREATE: 67 { 68 HWND heditchild; 69 char pwdchar = PASSWORDCHAR; 70 HDC hdc; 71 /* Create a child window of this control for default processing. */ 72 hdc = GetDC(hWnd); 73 GetTextExtentPoint32(hdc, &pwdchar, 1, &pwdcharsz); 74 ReleaseDC(hWnd, hdc); 75 76 heditchild = 77 CreateWindow("edit", "", WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | 78 ES_LEFT | ES_PASSWORD | WS_TABSTOP, 79 0, 0, 0, 0, 80 hWnd, 81 (HMENU)1, 82 ((LPCREATESTRUCT)lParam)->hInstance, 83 NULL); 84 SendMessage(heditchild, EM_SETPASSWORDCHAR, PASSWORDCHAR, 0L); 85 } 86 break; 87 } 88 89 if (pass_the_buck) 90 return SendMessage(GetDlgItem(hWnd, 1), message, wParam, lParam); 91 return DefWindowProc(hWnd, message, wParam, lParam); 92 } 93 94 BOOL 95 Register_MITPasswordEditControl( 96 HINSTANCE hInst 97 ) 98 { 99 if (!sAtom) { 100 WNDCLASS wndclass; 101 102 memset(&wndclass, 0, sizeof(WNDCLASS)); 103 104 shInstance = hInst; 105 106 wndclass.style = CS_HREDRAW | CS_VREDRAW; 107 wndclass.lpfnWndProc = (WNDPROC)MITPasswordEditProc; 108 wndclass.cbClsExtra = sizeof(HWND); 109 wndclass.cbWndExtra = 0; 110 wndclass.hInstance = shInstance; 111 wndclass.hbrBackground = (void *)(COLOR_WINDOW + 1); 112 wndclass.lpszClassName = MIT_PWD_DLL_CLASS; 113 wndclass.hCursor = LoadCursor((HINSTANCE)NULL, IDC_IBEAM); 114 115 sAtom = RegisterClass(&wndclass); 116 } 117 return sAtom ? TRUE : FALSE; 118 } 119 120 BOOL 121 Unregister_MITPasswordEditControl( 122 HINSTANCE hInst 123 ) 124 { 125 BOOL result = TRUE; 126 127 if ((hInst != shInstance) || !sAtom) { 128 SetLastError(ERROR_INVALID_PARAMETER); 129 return FALSE; 130 } 131 132 result = UnregisterClass(MIT_PWD_DLL_CLASS, hInst); 133 if (result) { 134 sAtom = 0; 135 shInstance = 0; 136 } 137 return result; 138 } 139