|
2 | 2 | #include "MaskDesktop.h"
|
3 | 3 | #include <CDEvents.h>
|
4 | 4 | #include <CDAPI.h>
|
5 |
| -#include "MDConfig.h" |
| 5 | +#include "Config.h" |
| 6 | +#include <thread> |
| 7 | +#include <shellapi.h> |
6 | 8 |
|
7 | 9 |
|
8 | 10 | MaskDesktop::MaskDesktop(HMODULE hModule) :
|
9 |
| - m_module(hModule) |
| 11 | + m_module(hModule), |
| 12 | + m_menuID(cd::GetMenuID()) |
10 | 13 | {
|
11 | 14 | // 载入图片
|
12 |
| - CImage img; |
13 |
| - img.Load(g_config.m_imagePath.c_str()); |
14 |
| - m_img.Create(g_config.m_size, g_config.m_size, 32, CImage::createAlphaChannel); |
15 |
| - img.Draw(m_img.GetDC(), -5, -5, g_config.m_size + 10, g_config.m_size + 10); |
16 |
| - m_img.ReleaseDC(); |
| 15 | + InitImg(); |
17 | 16 |
|
18 | 17 | // 监听事件
|
19 | 18 | cd::g_fileListWndProcEvent.AddListener(std::bind(&MaskDesktop::OnFileListWndProc, this, std::placeholders::_1,
|
20 | 19 | std::placeholders::_2, std::placeholders::_3, std::placeholders::_4), m_module);
|
21 | 20 | cd::g_postDrawIconEvent.AddListener(std::bind(&MaskDesktop::OnPostDrawIcon, this, std::placeholders::_1), m_module);
|
| 21 | + cd::g_appendTrayMenuEvent.AddListener(std::bind(&MaskDesktop::OnAppendTrayMenu, this, std::placeholders::_1), m_module); |
| 22 | + cd::g_chooseMenuItemEvent.AddListener(std::bind(&MaskDesktop::OnChooseMenuItem, this, std::placeholders::_1), m_module); |
22 | 23 |
|
23 | 24 | cd::RedrawDesktop();
|
24 | 25 | }
|
25 | 26 |
|
| 27 | +void MaskDesktop::InitImg() |
| 28 | +{ |
| 29 | + CImage img; |
| 30 | + img.Load(g_config.m_imagePath.c_str()); |
| 31 | + if (!m_img.IsNull()) |
| 32 | + m_img.Destroy(); |
| 33 | + m_img.Create(g_config.m_size, g_config.m_size, 32, CImage::createAlphaChannel); |
| 34 | + img.Draw(m_img.GetDC(), -5, -5, g_config.m_size + 10, g_config.m_size + 10); |
| 35 | + m_img.ReleaseDC(); |
| 36 | +} |
| 37 | + |
26 | 38 |
|
27 | 39 | bool MaskDesktop::OnFileListWndProc(UINT message, WPARAM wParam, LPARAM lParam, LRESULT& res)
|
28 | 40 | {
|
@@ -79,4 +91,41 @@ bool MaskDesktop::OnPostDrawIcon(HDC& hdc)
|
79 | 91 | FillRect(hdc, &rect, brush);
|
80 | 92 |
|
81 | 93 | return true;
|
82 |
| -} |
| 94 | +} |
| 95 | + |
| 96 | + |
| 97 | +bool MaskDesktop::OnAppendTrayMenu(HMENU menu) |
| 98 | +{ |
| 99 | + AppendMenu(menu, MF_STRING, m_menuID, APPNAME); |
| 100 | + return true; |
| 101 | +} |
| 102 | + |
| 103 | +bool MaskDesktop::OnChooseMenuItem(UINT menuID) |
| 104 | +{ |
| 105 | + if (menuID != m_menuID) |
| 106 | + return true; |
| 107 | + |
| 108 | + std::thread([this]{ |
| 109 | + SHELLEXECUTEINFOW info = {}; |
| 110 | + info.cbSize = sizeof(info); |
| 111 | + info.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NOASYNC; |
| 112 | + info.lpVerb = L"open"; |
| 113 | + info.lpFile = L"notepad.exe"; |
| 114 | + std::wstring param = cd::GetPluginDir() + L"\\Data\\MaskDesktop.ini"; |
| 115 | + info.lpParameters = param.c_str(); |
| 116 | + info.nShow = SW_SHOWNORMAL; |
| 117 | + ShellExecuteExW(&info); |
| 118 | + |
| 119 | + WaitForSingleObject(info.hProcess, INFINITE); |
| 120 | + CloseHandle(info.hProcess); |
| 121 | + |
| 122 | + cd::ExecInMainThread([this]{ |
| 123 | + Config newConfig; |
| 124 | + int oldSize = g_config.m_size; |
| 125 | + g_config = newConfig; |
| 126 | + if (newConfig.m_size != oldSize) |
| 127 | + InitImg(); |
| 128 | + }); |
| 129 | + }).detach(); |
| 130 | + return false; |
| 131 | +} |
0 commit comments