-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSamplePlugin.cpp
More file actions
154 lines (122 loc) · 3.31 KB
/
SamplePlugin.cpp
File metadata and controls
154 lines (122 loc) · 3.31 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "SamplePlugin.h"
#include <string>
#include <tchar.h>
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
SamplePlugin app;
if(app.Initialize())
{
return app.Run();
}
return 0;
}
BOOL SamplePlugin::Initialize()
{
if(!dex)
{
dex = new Dexpot(_T("SamplePlugin"));
dex->RegisterEventHandler(this);
}
if(dex->Connect())
{
return TRUE;
}
return FALSE;
}
int SamplePlugin::Run()
{
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
void SamplePlugin::OnLoad()
{
TCHAR DexpotPath[MAX_PATH];
TCHAR Message[2 * MAX_PATH];
dex->GetDexpotHome(DexpotPath, MAX_PATH * sizeof(TCHAR));
_stprintf_s(Message, 2 * MAX_PATH, _T("Dexpot sample plugin has loaded.\nHere are some facts:\n\nDesktop count: %i\nCurrent desktop: %i\nDexpot path: %s"),
dex->GetDesktopCount(), dex->GetCurrentDesktop(), DexpotPath);
MessageBox(NULL, Message, _T("Dexpot Sample Plugin"), MB_OK | MB_ICONINFORMATION);
dex->RegisterOption(DEX_OPTION_TYPE_INTEGER, OPTION_INITIALIZED, _T("Initialized"));
dex->RegisterOption(DEX_OPTION_TYPE_STRING, OPTION_SOMEOPTION, _T("SomeOption"));
dex->RegisterHotkey(HOTKEY_SAYHELLO, _T("Say Hello"));
dex->LoadSettings();
if(!OptionsInitialized)
{
OptionsInitialized = 1;
dex->SetOptionValue(OPTION_INITIALIZED, OptionsInitialized);
dex->SetOptionValue(OPTION_SOMEOPTION, _T("Default value of SomeOption"));
dex->SetHotkeyValue(HOTKEY_SAYHELLO, MOD_WIN, VK_F8);
dex->SaveSettings();
}
dex->InsertMainMenuItem(MENUCOMMAND_QUIT, _T(" Quit Sample Plugin"), NULL);
}
void SamplePlugin::OnSetIntegerOption(INT32 Id, INT32 Value)
{
if(Id == OPTION_INITIALIZED)
{
OptionsInitialized = Value;
}
}
void SamplePlugin::OnSetStringOption(INT32 Id, LPTSTR Value)
{
if(Id == OPTION_SOMEOPTION)
{
std::wstring SomeOption = _T("Value of SomeOption: ");
SomeOption += std::wstring(Value);
MessageBox(NULL, SomeOption.c_str(), _T("Dexpot Sample Plugin"), MB_OK);
}
}
void SamplePlugin::OnHotkey(INT32 Id, WORD Hotkey, WORD Modifier)
{
if(Id == HOTKEY_SAYHELLO)
{
MessageBox(NULL, _T("Hello!"), _T("Dexpot Sample Plugin"), MB_OK | MB_ICONINFORMATION);
}
}
void SamplePlugin::OnMenuCommand(INT32 Id)
{
if(Id == MENUCOMMAND_QUIT)
{
OnShutdown();
}
}
void SamplePlugin::OnShutdown()
{
dex->Disconnect();
PostQuitMessage(0);
}
void SamplePlugin::OnSwitched(INT32 FromDesktop, INT32 ToDesktop, WORD Flags, WORD Trigger)
{
if(Trigger != dex->GetPluginID())
{
TCHAR Buffer[128];
dex->GetDesktopTitle(FromDesktop, Buffer, 128 * sizeof(TCHAR));
std::wstring FromDesktopName = Buffer;
dex->GetDesktopTitle(ToDesktop, Buffer, 128 * sizeof(TCHAR));
std::wstring ToDesktopName = Buffer;
std::wstring message = _T("");
message += _T("You have switched from ") + FromDesktopName + _T(" to ") + ToDesktopName + _T(".");
message += _T("\nWanna switch back?");
if(MessageBox(NULL, message.c_str(), _T("Dexpot Sample Plugin"), MB_YESNOCANCEL | MB_ICONQUESTION) == IDYES)
{
dex->SwitchDesktop(FromDesktop, 0);
}
}
}
void SamplePlugin::OnConfigure()
{
MessageBox(NULL, _T("Insert plugin settings dialog here."), _T("Dexpot Sample Plugin"), MB_OK);
}
SamplePlugin::SamplePlugin(void)
{
dex = NULL;
}
SamplePlugin::~SamplePlugin(void)
{
delete dex;
}