1 // SshAskPass.cpp : Defines the entry point for the application.
5 #include "SshAskPass.h"
8 #define MAX_LOADSTRING 100
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
,
31 UNREFERENCED_PARAMETER(hPrevInstance
);
33 if( _tcslen(lpCmdLine
) == 0 )
35 g_Prompt
= g_Promptphrase
;
42 _tcslwr(lpCmdLine
); //low case
44 TCHAR
*yesno
=_T("(yes/no)");
45 int lens
=_tcslen(yesno
);
51 if(_tcsncmp(p
,yesno
,lens
) == 0)
60 if(::MessageBox(NULL
,lpCmdLine
,_T("OpenSSH"),MB_YESNO
|MB_ICONQUESTION
) == IDYES
)
72 if(DialogBox(hInst
, MAKEINTRESOURCE(IDD_ASK_PASSWORD
), NULL
, About
) == IDOK
)
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
))
93 hAccelTable
= LoadAccelerators(hInstance
, MAKEINTRESOURCE(IDC_SSHASKPASS
));
96 while (GetMessage(&msg
, NULL
, 0, 0))
98 if (!TranslateAccelerator(msg
.hwnd
, hAccelTable
, &msg
))
100 TranslateMessage(&msg
);
101 DispatchMessage(&msg
);
109 // FUNCTION: MyRegisterClass()
111 // PURPOSE: Registers the window class.
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
121 ATOM
MyRegisterClass(HINSTANCE hInstance
)
125 wcex
.cbSize
= sizeof(WNDCLASSEX
);
127 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
128 wcex
.lpfnWndProc
= WndProc
;
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
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
)
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
);
166 ShowWindow(hWnd
, nCmdShow
);
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
)
191 wmId
= LOWORD(wParam
);
192 wmEvent
= HIWORD(wParam
);
193 // Parse the menu selections:
197 DialogBox(hInst
, MAKEINTRESOURCE(IDD_ASK_PASSWORD
), hWnd
, About
);
203 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
207 hdc
= BeginPaint(hWnd
, &ps
);
208 // Add any drawing code here...
215 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
220 // Message handler for about box.
221 INT_PTR CALLBACK
About(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
223 UNREFERENCED_PARAMETER(lParam
);
229 ::GetWindowRect(hDlg
,&rect
);
230 DWORD dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
231 DWORD dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
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
);
240 ::SetWindowText(title
,g_Prompt
);
242 return (INT_PTR
)TRUE
;
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
;
258 return (INT_PTR
)FALSE
;