fixed build on Win32, partly reverted 0634b6b3605b492b02a480af4e11c89663504fcd
[TortoiseGit.git] / src / SshAskPass / SshAskPass.cpp
blob7f9bb99ecba5f68d0a7280f1de1cf6de079e4059
1 // SshAskPass.cpp : Defines the entry point for the application.
2 //
4 #include "stdafx.h"
5 #include "SshAskPass.h"
6 #include <stdio.h>
8 #define MAX_LOADSTRING 100
10 // Global Variables:
11 HINSTANCE hInst; // current instance
12 TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
13 TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
15 // Forward declarations of functions included in this code module:
16 ATOM MyRegisterClass(HINSTANCE hInstance);
17 BOOL InitInstance(HINSTANCE, int);
18 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
19 INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
21 TCHAR g_Promptphrase[] = _T("Enter your OpenSSH passphrase:");
22 TCHAR *g_Prompt = NULL;
24 TCHAR g_PassWord[MAX_LOADSTRING];
26 int APIENTRY _tWinMain(HINSTANCE hInstance,
27 HINSTANCE hPrevInstance,
28 LPTSTR lpCmdLine,
29 int nCmdShow)
31 UNREFERENCED_PARAMETER(hPrevInstance);
33 if( _tcslen(lpCmdLine) == 0 )
35 g_Prompt = g_Promptphrase;
37 else
39 g_Prompt = lpCmdLine;
42 _tcslwr(lpCmdLine); //low case
44 TCHAR *yesno=_T("(yes/no)");
45 int lens=_tcslen(yesno);
46 TCHAR *p = lpCmdLine;
47 BOOL bYesNo=FALSE;
49 while(*p)
51 if(_tcsncmp(p,yesno,lens) == 0)
53 bYesNo = TRUE;
55 p++;
58 if(bYesNo)
60 if(::MessageBox(NULL,lpCmdLine,_T("OpenSSH"),MB_YESNO|MB_ICONQUESTION) == IDYES)
62 _tprintf(_T("yes"));
64 else
66 _tprintf(_T("no"));
68 return 0;
70 else
72 if(DialogBox(hInst, MAKEINTRESOURCE(IDD_ASK_PASSWORD), NULL, About) == IDOK)
74 _tprintf(g_PassWord);
75 return 0;
77 return -1;
80 #if 0
81 // Initialize global strings
82 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
83 LoadString(hInstance, IDC_SSHASKPASS, szWindowClass, MAX_LOADSTRING);
84 MyRegisterClass(hInstance);
86 // Perform application initialization:
87 if (!InitInstance (hInstance, nCmdShow))
89 return FALSE;
93 hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SSHASKPASS));
95 // Main message loop:
96 while (GetMessage(&msg, NULL, 0, 0))
98 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
100 TranslateMessage(&msg);
101 DispatchMessage(&msg);
104 #endif
105 return (int) 0;
109 // FUNCTION: MyRegisterClass()
111 // PURPOSE: Registers the window class.
113 // COMMENTS:
115 // This function and its usage are only necessary if you want this code
116 // to be compatible with Win32 systems prior to the 'RegisterClassEx'
117 // function that was added to Windows 95. It is important to call this function
118 // so that the application will get 'well formed' small icons associated
119 // with it.
121 ATOM MyRegisterClass(HINSTANCE hInstance)
123 WNDCLASSEX wcex;
125 wcex.cbSize = sizeof(WNDCLASSEX);
127 wcex.style = CS_HREDRAW | CS_VREDRAW;
128 wcex.lpfnWndProc = WndProc;
129 wcex.cbClsExtra = 0;
130 wcex.cbWndExtra = 0;
131 wcex.hInstance = hInstance;
132 wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SSHASKPASS));
133 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
134 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
135 wcex.lpszMenuName = MAKEINTRESOURCE(IDC_SSHASKPASS);
136 wcex.lpszClassName = szWindowClass;
137 wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
139 return RegisterClassEx(&wcex);
143 // FUNCTION: InitInstance(HINSTANCE, int)
145 // PURPOSE: Saves instance handle and creates main window
147 // COMMENTS:
149 // In this function, we save the instance handle in a global variable and
150 // create and display the main program window.
152 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
154 HWND hWnd;
156 hInst = hInstance; // Store instance handle in our global variable
158 hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
159 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
161 if (!hWnd)
163 return FALSE;
166 ShowWindow(hWnd, nCmdShow);
167 UpdateWindow(hWnd);
169 return TRUE;
173 // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
175 // PURPOSE: Processes messages for the main window.
177 // WM_COMMAND - process the application menu
178 // WM_PAINT - Paint the main window
179 // WM_DESTROY - post a quit message and return
182 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
184 int wmId, wmEvent;
185 PAINTSTRUCT ps;
186 HDC hdc;
188 switch (message)
190 case WM_COMMAND:
191 wmId = LOWORD(wParam);
192 wmEvent = HIWORD(wParam);
193 // Parse the menu selections:
194 switch (wmId)
196 case IDM_ABOUT:
197 DialogBox(hInst, MAKEINTRESOURCE(IDD_ASK_PASSWORD), hWnd, About);
198 break;
199 case IDM_EXIT:
200 DestroyWindow(hWnd);
201 break;
202 default:
203 return DefWindowProc(hWnd, message, wParam, lParam);
205 break;
206 case WM_PAINT:
207 hdc = BeginPaint(hWnd, &ps);
208 // Add any drawing code here...
209 EndPaint(hWnd, &ps);
210 break;
211 case WM_DESTROY:
212 PostQuitMessage(0);
213 break;
214 default:
215 return DefWindowProc(hWnd, message, wParam, lParam);
217 return 0;
220 // Message handler for about box.
221 INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
223 UNREFERENCED_PARAMETER(lParam);
224 switch (message)
226 case WM_INITDIALOG:
228 RECT rect;
229 ::GetWindowRect(hDlg,&rect);
230 DWORD dwWidth = GetSystemMetrics(SM_CXSCREEN);
231 DWORD dwHeight = GetSystemMetrics(SM_CYSCREEN);
233 DWORD x,y;
234 x=(dwWidth - (rect.right-rect.left))/2;
235 y=(dwHeight - (rect.bottom-rect.top))/2;
237 ::MoveWindow(hDlg,x,y,rect.right-rect.left,rect.bottom-rect.top,TRUE);
238 HWND title=::GetDlgItem(hDlg,IDC_STATIC_TITLE);
239 if(g_Prompt)
240 ::SetWindowText(title,g_Prompt);
242 return (INT_PTR)TRUE;
244 case WM_COMMAND:
246 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
248 if( LOWORD(wParam) == IDOK )
250 HWND password = ::GetDlgItem(hDlg,IDC_PASSWORD);
251 ::GetWindowText(password,g_PassWord,MAX_LOADSTRING);
253 EndDialog(hDlg, LOWORD(wParam));
254 return (INT_PTR)TRUE;
256 break;
258 return (INT_PTR)FALSE;