OSDN Git Service

merge original branch.
[tortoisegit/TortoiseGitJp.git] / contrib / issue-tracker-plugins / ExampleAtlPlugin / WaitDialog.cpp
1 #include "stdafx.h"\r
2 #include "WaitDialog.h"\r
3 \r
4 CWaitDialog::CWaitDialog(const CString &commandLine)\r
5         : m_hThread(NULL)\r
6         , m_commandLine(commandLine)\r
7 {\r
8 }\r
9 \r
10 CWaitDialog::~CWaitDialog()\r
11 {\r
12 }\r
13 \r
14 LRESULT CWaitDialog::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)\r
15 {\r
16         // Disable the close button (the 'X').\r
17         HMENU hSystemMenu = GetSystemMenu(FALSE);\r
18         EnableMenuItem(hSystemMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);\r
19 \r
20         // Kick off the thread that actually runs the process.\r
21         m_hThread = (HANDLE)_beginthreadex(NULL, 0, _ThreadRoutine, this, 0, NULL);\r
22         \r
23         bHandled = TRUE;\r
24         return TRUE;\r
25 }\r
26 \r
27 LRESULT CWaitDialog::OnProcessStarting(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)\r
28 {\r
29         return 0;\r
30 }\r
31 \r
32 LRESULT CWaitDialog::OnProcessCompleted(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)\r
33 {\r
34         CloseHandle(m_hThread);\r
35         EndDialog(IDOK);\r
36         return 0;\r
37 }\r
38 \r
39 unsigned int CWaitDialog::ThreadRoutine()\r
40 {\r
41         PostMessage(WM_PROCESS_STARTING);\r
42 \r
43         STARTUPINFO si;\r
44         memset(&si, 0, sizeof(STARTUPINFO));\r
45         si.cb = sizeof(STARTUPINFO);\r
46 \r
47         PROCESS_INFORMATION pi;\r
48         memset(&pi, 0, sizeof(PROCESS_INFORMATION));\r
49 \r
50         BOOL ok;\r
51 \r
52 #if defined(UNICODE)\r
53         WCHAR *temp = _wcsdup(m_commandLine);\r
54         ok = CreateProcess(NULL, temp, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);\r
55         free(temp);\r
56 #else\r
57         ok = CreateProcess(NULL, m_commandLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);\r
58 #endif\r
59 \r
60         if (ok)\r
61                 WaitForSingleObject(pi.hProcess, INFINITE);\r
62 \r
63         PostMessage(WM_PROCESS_COMPLETED);\r
64 \r
65         return 0;\r
66 }\r