Skip to content

Commit 8ae84a9

Browse files
committed
initial commit
0 parents  commit 8ae84a9

File tree

178 files changed

+61726
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+61726
-0
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.old
2+
*.suo
3+
*.sdf
4+
*.ncb
5+
*.user
6+
*.aps
7+
*.VC.db
8+
*.VC.opendb
9+
.svn
10+
bin
11+
Common.user.props
12+
obj
13+
ipch
14+
ShellDLL/work
15+
EasySFTP/work

Common.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Import Condition="Exists('$(SolutionDir)Common.user.props')" Project="$(SolutionDir)Common.user.props" />
3+
</Project>

Common.user.sample.props

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!--
2+
-->
3+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
4+
<PropertyGroup>
5+
<OpenSSLRoot>\OpenSSL\</OpenSSLRoot>
6+
<LibraryPath Condition="'$(Platform)'=='x64'">$(OpenSSLRoot)lib\x64;$(LibraryPath)</LibraryPath>
7+
<LibraryPath Condition="'$(Platform)'!='x64'">$(OpenSSLRoot)lib;$(LibraryPath)</LibraryPath>
8+
<IncludePath>$(OpenSSLRoot)include;$(IncludePath)</IncludePath>
9+
</PropertyGroup>
10+
</Project>

Common/AppClass.cpp

Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
1+
/*
2+
Copyright (C) 2011 Kuri-Applications
3+
4+
AppClass.cpp - implementations of CMyApplication and WinMain
5+
*/
6+
7+
#include "StdAfx.h"
8+
#include "AppClass.h"
9+
10+
#include "MyWindow.h"
11+
12+
#include <process.h>
13+
14+
static struct CCurrentAppData
15+
{
16+
CMyApplication* pMainApp;
17+
CMyDLLApplication* pDLLApp;
18+
} s_app;
19+
20+
extern "C" void WINAPI EndWindowData();
21+
22+
EXTERN_C int APIENTRY MyWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
23+
LPTSTR lpCmdLine, int nCmdShow)
24+
{
25+
if (!s_app.pMainApp)
26+
return -1;
27+
s_app.pMainApp->m_dwThreadID = ::GetCurrentThreadId();
28+
s_app.pMainApp->m_hThread = ::GetCurrentThread();
29+
s_app.pMainApp->m_hInstance = hInstance;
30+
s_app.pMainApp->m_lpCmdLine = lpCmdLine;
31+
s_app.pMainApp->m_nCmdShow = nCmdShow;
32+
if (!s_app.pMainApp->InitInstance())
33+
return s_app.pMainApp->ExitInstance();
34+
int ret = s_app.pMainApp->Run();
35+
::EndWindowData();
36+
return ret;
37+
}
38+
39+
EXTERN_C BOOL APIENTRY MyDllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
40+
{
41+
switch (dwReason)
42+
{
43+
case DLL_PROCESS_ATTACH:
44+
{
45+
if (!s_app.pDLLApp)
46+
return FALSE;
47+
s_app.pDLLApp->m_hInstance = hInstance;
48+
if (!s_app.pDLLApp->InitInstance())
49+
{
50+
s_app.pDLLApp->ExitInstance();
51+
return FALSE;
52+
}
53+
}
54+
break;
55+
case DLL_THREAD_ATTACH:
56+
break;
57+
case DLL_THREAD_DETACH:
58+
break;
59+
case DLL_PROCESS_DETACH:
60+
s_app.pDLLApp->ExitInstance();
61+
::EndWindowData();
62+
break;
63+
}
64+
return TRUE;
65+
}
66+
67+
CMyThread* WINAPI GetCurThread()
68+
{
69+
return s_app.pMainApp ? (CMyThread*) s_app.pMainApp : (CMyThread*) s_app.pDLLApp;
70+
}
71+
72+
CMyApplication* WINAPI GetCurApp()
73+
{
74+
return s_app.pMainApp;
75+
}
76+
77+
CMyDLLApplication* WINAPI GetCurDLLApp()
78+
{
79+
return s_app.pDLLApp;
80+
}
81+
82+
EXTERN_C HINSTANCE WINAPI MyGetCurrentInstance()
83+
{
84+
if (s_app.pMainApp)
85+
return s_app.pMainApp->m_hInstance;
86+
else if (s_app.pDLLApp)
87+
return s_app.pDLLApp->m_hInstance;
88+
else
89+
return NULL;
90+
}
91+
92+
////////////////////////////////////////////////////////////////////////////////
93+
94+
CMyThread::CMyThread()
95+
{
96+
m_bWinThread = false;
97+
CommonConstruct();
98+
}
99+
100+
CMyThread::CMyThread(bool bWinThread)
101+
{
102+
m_bWinThread = bWinThread;
103+
CommonConstruct();
104+
}
105+
106+
void CMyThread::CommonConstruct()
107+
{
108+
m_dwThreadID = 0;
109+
m_hThread = NULL;
110+
::InitializeCriticalSection(&m_csThread);
111+
}
112+
113+
CMyThread::~CMyThread()
114+
{
115+
EndThread();
116+
::DeleteCriticalSection(&m_csThread);
117+
}
118+
119+
int CMyThread::Run()
120+
{
121+
return 0;
122+
}
123+
124+
UINT __stdcall CMyThread::ThreadProc(void* pv)
125+
{
126+
UINT uRet;
127+
CMyThread* pThread = (CMyThread*) pv;
128+
uRet = (UINT) pThread->Run();
129+
::EnterCriticalSection(&pThread->m_csThread);
130+
bool bNeedEnd = (pThread->m_hThread != NULL);
131+
if (bNeedEnd)
132+
pThread->EndThread();
133+
::LeaveCriticalSection(&pThread->m_csThread);
134+
if (bNeedEnd)
135+
pThread->PostEndThread();
136+
_endthreadex(uRet);
137+
return uRet;
138+
}
139+
140+
bool CMyThread::StartThread()
141+
{
142+
::EnterCriticalSection(&m_csThread);
143+
if (m_hThread)
144+
{
145+
::LeaveCriticalSection(&m_csThread);
146+
return false;
147+
}
148+
::LeaveCriticalSection(&m_csThread);
149+
150+
HANDLE h;
151+
h = (HANDLE) _beginthreadex(NULL, 0, CMyThread::ThreadProc, this,
152+
CREATE_SUSPENDED, (UINT*) &m_dwThreadID);
153+
if (!h)
154+
{
155+
PostEndThread();
156+
return false;
157+
}
158+
m_hThread = h;
159+
::ResumeThread(h);
160+
return true;
161+
}
162+
163+
bool CMyThread::IsThreadExited() const
164+
{
165+
return m_hThread == NULL;
166+
}
167+
168+
bool CMyThread::TerminateThread(DWORD dwExitCode)
169+
{
170+
::EnterCriticalSection(&m_csThread);
171+
if (!m_hThread)
172+
{
173+
::LeaveCriticalSection(&m_csThread);
174+
return true;
175+
}
176+
if (m_dwThreadID == ::GetCurrentThreadId() || !::TerminateThread(m_hThread, dwExitCode))
177+
{
178+
::LeaveCriticalSection(&m_csThread);
179+
return false;
180+
}
181+
EndThread();
182+
::LeaveCriticalSection(&m_csThread);
183+
PostEndThread();
184+
return true;
185+
}
186+
187+
void CMyThread::EndThread()
188+
{
189+
if (m_hThread)
190+
::CloseHandle(m_hThread);
191+
m_hThread = NULL;
192+
m_dwThreadID = 0;
193+
}
194+
195+
////////////////////////////////////////////////////////////////////////////////
196+
197+
CMyWinThread::CMyWinThread()
198+
: CMyThread(true)
199+
{
200+
memset(&m_msg, 0, sizeof(m_msg));
201+
m_msg.message = WM_QUIT;
202+
m_msg.wParam = (WPARAM) -1;
203+
m_msg.lParam = 0;
204+
m_pMainWnd = NULL;
205+
}
206+
207+
int CMyWinThread::ExitInstance()
208+
{
209+
return (int) m_msg.wParam;
210+
}
211+
212+
int CMyWinThread::Run()
213+
{
214+
// メイン メッセージ ループ:
215+
long c;
216+
bool bExit = false;
217+
while (!bExit)
218+
{
219+
if (!m_pMainWnd)
220+
return ExitInstance();
221+
222+
c = 0;
223+
// キューにメッセージが無い間 OnIdle を呼び続ける
224+
while (!::PeekMessage(&m_msg, NULL, 0, 0, PM_NOREMOVE))
225+
{
226+
if (!OnIdle(c++))
227+
break;
228+
}
229+
// キューにメッセージがある限り、それらを処理する
230+
// (OnIdle が false を返して戻った場合、GetMessage で待機する)
231+
while (true)
232+
{
233+
if (!PumpMessage())
234+
{
235+
bExit = true;
236+
break;
237+
}
238+
if (!::PeekMessage(&m_msg, NULL, 0, 0, PM_NOREMOVE))
239+
break;
240+
}
241+
}
242+
return ExitInstance();
243+
}
244+
245+
bool CMyWinThread::OnIdle(long lCount)
246+
{
247+
return false;
248+
}
249+
250+
bool CMyWinThread::PumpMessage()
251+
{
252+
//if (!::PeekMessage(&m_msg, NULL, 0, 0, PM_NOREMOVE))
253+
// return true;
254+
if (!::GetMessage(&m_msg, NULL, 0, 0))
255+
return false;
256+
CMyWindow* pWnd = CMyWindow::FromHandle(m_msg.hwnd);
257+
if (pWnd && pWnd != m_pMainWnd && pWnd->PreTranslateMessage(&m_msg))
258+
return true;
259+
CMyWindow* pWnd2 = CMyWindow::FromHandle(::GetActiveWindow());
260+
if (pWnd2 && pWnd2 != m_pMainWnd && pWnd2 != pWnd && pWnd2->PreTranslateMessage(&m_msg))
261+
return true;
262+
if (!m_pMainWnd || !m_pMainWnd->PreTranslateMessage(&m_msg))
263+
{
264+
::TranslateMessage(&m_msg);
265+
::DispatchMessage(&m_msg);
266+
}
267+
return true;
268+
}
269+
270+
////////////////////////////////////////////////////////////////////////////////
271+
272+
CMyApplication::CMyApplication()
273+
{
274+
if (!s_app.pMainApp)
275+
s_app.pMainApp = this;
276+
}
277+
278+
CMyApplication::~CMyApplication()
279+
{
280+
m_hThread = NULL;
281+
}
282+
283+
////////////////////////////////////////////////////////////////////////////////
284+
285+
CMyDLLApplication::CMyDLLApplication()
286+
{
287+
if (!s_app.pDLLApp)
288+
s_app.pDLLApp = this;
289+
}
290+
291+
CMyDLLApplication::~CMyDLLApplication()
292+
{
293+
m_hThread = NULL;
294+
}

0 commit comments

Comments
 (0)