1 // SshAskPass.cpp : Defines the entry point for the application.
\r
5 #include "SshAskPass.h"
\r
8 #define MAX_LOADSTRING 100
\r
10 // Global Variables:
\r
11 HINSTANCE hInst; // current instance
\r
12 TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
\r
13 TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
\r
15 // Forward declarations of functions included in this code module:
\r
16 ATOM MyRegisterClass(HINSTANCE hInstance);
\r
17 BOOL InitInstance(HINSTANCE, int);
\r
18 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
\r
19 INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
\r
21 TCHAR g_Promptphrase[] = _T("Entry your OpenSSH passphrase:");
\r
22 TCHAR *g_Prompt = NULL;
\r
24 TCHAR g_PassWord[MAX_LOADSTRING];
\r
26 int APIENTRY _tWinMain(HINSTANCE hInstance,
\r
27 HINSTANCE hPrevInstance,
\r
31 UNREFERENCED_PARAMETER(hPrevInstance);
\r
32 UNREFERENCED_PARAMETER(lpCmdLine);
\r
34 // TODO: Place code here.
\r
39 if( _tcslen(lpCmdLine) == 0 )
\r
41 g_Prompt = g_Promptphrase;
\r
45 g_Prompt = lpCmdLine;
\r
48 _tcslwr(lpCmdLine); //low case
\r
50 TCHAR *yesno=_T("(yes/no)");
\r
51 int lens=_tcslen(yesno);
\r
52 TCHAR *p = lpCmdLine;
\r
57 if(_tcsncmp(p,yesno,lens) == 0)
\r
66 if(::MessageBox(NULL,lpCmdLine,_T("OpenSSH"),MB_YESNO|MB_ICONQUESTION) == IDYES)
\r
68 _tprintf(_T("yes"));
\r
78 if(DialogBox(hInst, MAKEINTRESOURCE(IDD_ASK_PASSWORD), NULL, About) == IDOK)
\r
80 _tprintf(g_PassWord);
\r
87 // Initialize global strings
\r
88 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
\r
89 LoadString(hInstance, IDC_SSHASKPASS, szWindowClass, MAX_LOADSTRING);
\r
90 MyRegisterClass(hInstance);
\r
92 // Perform application initialization:
\r
93 if (!InitInstance (hInstance, nCmdShow))
\r
99 hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SSHASKPASS));
\r
101 // Main message loop:
\r
102 while (GetMessage(&msg, NULL, 0, 0))
\r
104 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
\r
106 TranslateMessage(&msg);
\r
107 DispatchMessage(&msg);
\r
117 // FUNCTION: MyRegisterClass()
\r
119 // PURPOSE: Registers the window class.
\r
123 // This function and its usage are only necessary if you want this code
\r
124 // to be compatible with Win32 systems prior to the 'RegisterClassEx'
\r
125 // function that was added to Windows 95. It is important to call this function
\r
126 // so that the application will get 'well formed' small icons associated
\r
129 ATOM MyRegisterClass(HINSTANCE hInstance)
\r
133 wcex.cbSize = sizeof(WNDCLASSEX);
\r
135 wcex.style = CS_HREDRAW | CS_VREDRAW;
\r
136 wcex.lpfnWndProc = WndProc;
\r
137 wcex.cbClsExtra = 0;
\r
138 wcex.cbWndExtra = 0;
\r
139 wcex.hInstance = hInstance;
\r
140 wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SSHASKPASS));
\r
141 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
\r
142 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
\r
143 wcex.lpszMenuName = MAKEINTRESOURCE(IDC_SSHASKPASS);
\r
144 wcex.lpszClassName = szWindowClass;
\r
145 wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
\r
147 return RegisterClassEx(&wcex);
\r
151 // FUNCTION: InitInstance(HINSTANCE, int)
\r
153 // PURPOSE: Saves instance handle and creates main window
\r
157 // In this function, we save the instance handle in a global variable and
\r
158 // create and display the main program window.
\r
160 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
\r
164 hInst = hInstance; // Store instance handle in our global variable
\r
166 hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
\r
167 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
\r
174 ShowWindow(hWnd, nCmdShow);
\r
175 UpdateWindow(hWnd);
\r
181 // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
\r
183 // PURPOSE: Processes messages for the main window.
\r
185 // WM_COMMAND - process the application menu
\r
186 // WM_PAINT - Paint the main window
\r
187 // WM_DESTROY - post a quit message and return
\r
190 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
\r
199 wmId = LOWORD(wParam);
\r
200 wmEvent = HIWORD(wParam);
\r
201 // Parse the menu selections:
\r
205 DialogBox(hInst, MAKEINTRESOURCE(IDD_ASK_PASSWORD), hWnd, About);
\r
208 DestroyWindow(hWnd);
\r
211 return DefWindowProc(hWnd, message, wParam, lParam);
\r
215 hdc = BeginPaint(hWnd, &ps);
\r
216 // TODO: Add any drawing code here...
\r
217 EndPaint(hWnd, &ps);
\r
220 PostQuitMessage(0);
\r
223 return DefWindowProc(hWnd, message, wParam, lParam);
\r
228 // Message handler for about box.
\r
229 INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
\r
231 UNREFERENCED_PARAMETER(lParam);
\r
234 case WM_INITDIALOG:
\r
237 ::GetWindowRect(hDlg,&rect);
\r
238 DWORD dwWidth = GetSystemMetrics(SM_CXSCREEN);
\r
239 DWORD dwHeight = GetSystemMetrics(SM_CYSCREEN);
\r
242 x=(dwWidth - (rect.right-rect.left))/2;
\r
243 y=(dwHeight - (rect.bottom-rect.top))/2;
\r
245 ::MoveWindow(hDlg,x,y,rect.right-rect.left,rect.bottom-rect.top,TRUE);
\r
246 HWND title=::GetDlgItem(hDlg,IDC_STATIC_TITLE);
\r
248 ::SetWindowText(title,g_Prompt);
\r
250 return (INT_PTR)TRUE;
\r
254 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
\r
256 if( LOWORD(wParam) == IDOK )
\r
258 HWND password = ::GetDlgItem(hDlg,IDC_PASSWORD);
\r
259 ::GetWindowText(password,g_PassWord,MAX_LOADSTRING);
\r
261 EndDialog(hDlg, LOWORD(wParam));
\r
262 return (INT_PTR)TRUE;
\r
266 return (INT_PTR)FALSE;
\r