#define WIN32_LEAN_AND_MEAN #include #include LPCTSTR szWindowClass = _T("Mcapture2"); LPCTSTR szTitle = _T("PassGet Test Program"); HINSTANCE hInst; ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); void OpningPrintString(HWND); BOOL GetPasswdWindow(HWND, LPARAM); int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { MSG msg; MyRegisterClass(hInstance); if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } BOOL bRet; while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0) { if(bRet == -1) { break; } if (!TranslateAccelerator(msg.hwnd, NULL, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return (int) msg.wParam; } ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, NULL); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = (LPCTSTR)NULL; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, NULL); return RegisterClassEx(&wcex); } BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; hInst = hInstance; hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, 600, 200, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_PAINT: OpningPrintString(hWnd); break; case WM_LBUTTONDOWN: SetCapture(hWnd); SetCursor(LoadCursor(NULL, IDC_CROSS)); break; case WM_LBUTTONUP: if( GetPasswdWindow(hWnd, lParam) ) MessageBox(hWnd, _T("GetPasswdWindow"), _T("Error"), MB_OK); ReleaseCapture(); SetCursor(LoadCursor(NULL, IDC_ARROW)); break; case WM_CLOSE: DestroyWindow(hWnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } void OpningPrintString(HWND hWnd) { RECT rc; GetClientRect(hWnd, &rc); rc.left += 40, rc.top += 40, rc.right -= 40, rc.bottom -= 40; PAINTSTRUCT paint; HDC hdc = BeginPaint(hWnd, &paint); DrawText(hdc, _T( "このWindow領域をクリックするとマウスカーソルが変わるので、\n" "クリックしたまま、パスワードが書かれてある領域に、\n" "ドラッグしてください"), -1, &rc, DT_WORDBREAK); EndPaint(hWnd, &paint); } BOOL GetPasswdWindow(HWND hWnd, LPARAM lp) { POINTS pts = MAKEPOINTS(lp); POINT pt = { pts.x, pts.y }; ClientToScreen(hWnd, &pt); HWND hTarget = WindowFromPoint(pt); if(hTarget == NULL) return TRUE; PostMessage(hTarget, EM_SETPASSWORDCHAR, (WPARAM)0, (LPARAM)0); InvalidateRect(hTarget, NULL, TRUE); return FALSE; }