1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2003, 2013, 2018 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #include "LoginDialog.h"
20 #include "TortoisePlinkRes.h"
23 #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
25 HINSTANCE g_hmodThisDll
;
31 LoginDialog(const std::string
& prompt
);
33 static bool DoLoginDialog(std::string
& password
, const std::string
& prompt
);
39 std::string myPassword
;
42 void CreateModule(void);
43 void RetrieveValues();
45 std::string
GetPassword();
47 friend BOOL CALLBACK
LoginDialogProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
51 BOOL
DoLoginDialog(char* password
, int maxlen
, const char* prompt
)
53 g_hmodThisDll
= GetModuleHandle(0);
54 g_hwndMain
= GetParentHwnd();
55 std::string passwordstr
;
56 BOOL res
= LoginDialog::DoLoginDialog(passwordstr
, prompt
);
58 strncpy(password
, passwordstr
.c_str(), maxlen
);
63 BOOL CALLBACK
LoginDialogProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
65 if (uMsg
== WM_INITDIALOG
)
67 LoginDialog
* pDlg
= (LoginDialog
*) lParam
;
68 pDlg
->_hdlg
= hwndDlg
;
69 SetWindowLongPtr(hwndDlg
, GWLP_USERDATA
, lParam
);
71 SendDlgItemMessage(hwndDlg
, IDC_LOGIN_PROMPT
, WM_SETTEXT
,
72 pDlg
->myPrompt
.length(), (LPARAM
) pDlg
->myPrompt
.c_str());
73 // Make sure edit control has the focus
74 //SendDlgItemMessage(hwndDlg, IDC_LOGIN_PASSWORD, WM_SETFOCUS, 0, 0);
75 if (GetDlgCtrlID((HWND
) wParam
) != IDC_LOGIN_PASSWORD
)
77 SetFocus(GetDlgItem(hwndDlg
, IDC_LOGIN_PASSWORD
));
82 else if (uMsg
== WM_COMMAND
&& LOWORD(wParam
) == IDCANCEL
&& HIWORD(wParam
) == BN_CLICKED
)
84 LoginDialog
* pDlg
= (LoginDialog
*) GetWindowLongPtr(hwndDlg
, GWLP_USERDATA
);
86 EndDialog(hwndDlg
, IDCANCEL
);
89 else if (uMsg
== WM_COMMAND
&& LOWORD(wParam
) == IDOK
&& HIWORD(wParam
) == BN_CLICKED
)
91 LoginDialog
* pDlg
= (LoginDialog
*) GetWindowLongPtr(hwndDlg
, GWLP_USERDATA
);
93 pDlg
->RetrieveValues();
94 EndDialog(hwndDlg
, IDOK
);
100 LoginDialog::LoginDialog(const std::string
& prompt
)
105 void LoginDialog::CreateModule(void)
107 DialogBoxParam(g_hmodThisDll
, MAKEINTRESOURCE(IDD_LOGIN
), g_hwndMain
,
108 (DLGPROC
)(LoginDialogProc
), (LPARAM
)this);
112 bool LoginDialog::DoLoginDialog(std::string
& password
, const std::string
& prompt
)
114 LoginDialog
*pDlg
= new LoginDialog(prompt
);
116 pDlg
->CreateModule();
118 bool ret
= pDlg
->myOK
;
119 password
= pDlg
->myPassword
;
127 std::string
LoginDialog::GetPassword()
130 SendDlgItemMessage(_hdlg
, IDC_LOGIN_PASSWORD
, WM_GETTEXT
, sizeof(szTxt
), (LPARAM
)szTxt
);
131 std::string strText
= szTxt
;
135 void LoginDialog::RetrieveValues()
137 myPassword
= GetPassword();
144 vi
.dwOSVersionInfoSize
= sizeof(vi
);
145 if (GetVersionEx(&vi
))
147 if (vi
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
159 return GetDesktopWindow();
163 return GetForegroundWindow();