#include #include LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); BOOL CALLBACK EnumChildProc(HWND hWnd, LPARAM lParam); TCHAR szClassName[] = TEXT("PassGenWnd"); int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { HWND hWnd, hButton, hEdit, hStatic, hAbout; MSG Msg; WNDCLASSEX wcex; wcex.cbClsExtra = 0; wcex.cbSize = sizeof(WNDCLASSEX); wcex.cbWndExtra = 0; wcex.hbrBackground = (HBRUSH) COLOR_WINDOW; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION); wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wcex.hInstance = hInstance; wcex.lpfnWndProc = WndProc; wcex.lpszClassName = szClassName; wcex.lpszMenuName = NULL; wcex.style = CS_HREDRAW | CS_VREDRAW; RegisterClassEx(&wcex); hWnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, szClassName, TEXT("Secure Password Generator"), WS_VISIBLE | WS_SYSMENU, 100, 100, 300, 100, NULL, NULL, hInstance, NULL); hButton = CreateWindowEx(0, TEXT("BUTTON"), TEXT("Generate"), WS_VISIBLE | WS_CHILD, 190, 38, 100, 30, hWnd, NULL, hInstance, NULL); hStatic = CreateWindowEx(0, TEXT("STATIC"), TEXT("If you decide to use one of these passwords, do not forget it!"), WS_VISIBLE | WS_CHILD, 0, 0, 290, 20, hWnd, NULL, hInstance, NULL); hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT(""), WS_VISIBLE | WS_CHILD | ES_READONLY, 0, 20, 290, 20, hWnd, NULL, hInstance, NULL); hAbout = CreateWindowEx(0, TEXT("STATIC"), TEXT("Made by Govind on Sythe.org"), WS_VISIBLE | WS_CHILD, 0, 40, 160, 20, hWnd, NULL, hInstance, NULL); ShowWindow(hWnd, SW_SHOW); EnumChildWindows(hWnd, EnumChildProc, MAKELPARAM(FALSE, 0)); UpdateWindow(hWnd); while(GetMessage(&Msg, NULL, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam; } BOOL CALLBACK EnumChildProc(HWND hWnd, LPARAM lParam) { HFONT hfDefault = (HFONT) GetStockObject(DEFAULT_GUI_FONT); SendMessage(hWnd, WM_SETFONT, (WPARAM) hfDefault, MAKELPARAM(FALSE, 0)); return TRUE; } LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; switch(Msg) { case WM_CLOSE: DestroyWindow(hWnd); break; case WM_COMMAND: srand((unsigned)GetTickCount()); if((HWND)lParam==FindWindowEx(hWnd, 0, TEXT("BUTTON"), 0)) { TCHAR szTable[] = TEXT("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890,.`~!@#$%^&*()_+=-;:[{]}\\|/\?<>\'\""); int len = wcslen(szTable); int pwlen = 12+rand()%6; int i; TCHAR newPass[19]; HWND hEdit = FindWindowEx(hWnd, 0, TEXT("EDIT"), 0); for(i = 0; i < pwlen; i++) { newPass[i] = szTable[rand()%len]; } newPass[i] = 0; SetWindowText(hEdit, newPass); } break; case WM_DESTROY: PostQuitMessage(0); break; case WM_PAINT: BeginPaint(hWnd, &ps); EnumChildWindows(hWnd, EnumChildProc, MAKELPARAM(FALSE, 0)); EndPaint(hWnd, &ps); break; default: return DefWindowProc(hWnd, Msg, wParam, lParam); } return 0; }