summaryrefslogtreecommitdiff
path: root/plugins/Quotes/src/QuoteChart.cpp
blob: 16c6bfc1da0dba6ab0c53bc4b63b25f8991e2a07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "StdAfx.h"

#ifdef CHART_IMPLEMENT

namespace
{
	class CMyJob : private boost::noncopyable
	{
	private:
		CMyJob(LPCTSTR pszName = nullptr): m_hJob(::CreateJobObject(nullptr,pszName))
		{
			if(m_hJob)
			{
				JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli = { 0 };
				jeli.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
				if(0 == ::SetInformationJobObject(m_hJob,JobObjectExtendedLimitInformation,&jeli,sizeof(jeli)))
				{
#ifdef OUTPUT_TO_DEBUG_VIEWER
					::OutputDebugString(_T("Error occurred during the job initialization\n"));
#endif
				}
			}

		}
		~CMyJob()
		{
			if(m_hJob)
			{
				::CloseHandle(m_hJob);
			}
		}

	public:
		static CMyJob& GetInstance()
		{
			static CMyJob g_job(_T("MirandaJob_E12D5E9C_00E7_4FFA_9831_F35E45C6EBDA"));
			return g_job;
		}

		bool AssignProcess(HANDLE hProcess)
		{
			if(m_hJob && hProcess)
			{
				auto b = (TRUE == ::AssignProcessToJobObject(m_hJob,hProcess));
				return b;
			}

			return false;
		}

	private:
		HANDLE m_hJob;
	};

}

INT_PTR QuotesMenu_Chart(WPARAM wp, LPARAM /*lp*/)
{
#ifdef _UNICODE
	MCONTACT hContact = static_cast<MCONTACT>(wp);
	if (NULL == hContact)
		return 0;

	auto sLogFileName = GetContactLogFileName(hContact);

	if(auto hWnd = ::FindWindow(nullptr,_T("Miranda Quotes Chart")))
	{
		COPYDATASTRUCT copydata_struct;
		copydata_struct.cbData = static_cast<DWORD>(sLogFileName.size()*sizeof(TCHAR));
		copydata_struct.lpData = const_cast<void*>(static_cast<const void*>(sLogFileName.c_str()));
		copydata_struct.dwData = 0x1945;

		SendMessage(hWnd,WM_COPYDATA,0,reinterpret_cast<LPARAM>(&copydata_struct));
	}
	else
	{
		STARTUPINFO			si;
		PROCESS_INFORMATION	pi;
		ZeroMemory(&si, sizeof(si));
		si.cb			= sizeof(si);
		si.dwFlags		= STARTF_USESHOWWINDOW;
		si.wShowWindow	= SW_SHOWNORMAL;
		ZeroMemory(&pi, sizeof(pi));

		auto sCmdLine = CreateFilePath(_T("QuotesChart.exe"));
		sCmdLine += _T(" \"");
		sCmdLine += sLogFileName;
		sCmdLine += _T("\"");
		if(::CreateProcess(nullptr,const_cast<LPTSTR>(sCmdLine.c_str()),nullptr,nullptr,FALSE,0,nullptr,nullptr,&si,&pi))
		{
			CMyJob::GetInstance().AssignProcess(pi.hProcess);

			::CloseHandle(pi.hThread);
			::CloseHandle(pi.hProcess);
		}
	}
#endif
	return 0;
}

#endif //CHART_IMPLEMENT