diff options
Diffstat (limited to 'last_contact/LastContact.cpp')
-rw-r--r-- | last_contact/LastContact.cpp | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/last_contact/LastContact.cpp b/last_contact/LastContact.cpp new file mode 100644 index 0000000..3cce9bd --- /dev/null +++ b/last_contact/LastContact.cpp @@ -0,0 +1,195 @@ +/*
+Miranda plugin template, originally by Richard Hughes
+http://miranda-icq.sourceforge.net/
+
+This file is placed in the public domain. Anybody is free to use or
+modify it as they wish with no restriction.
+There is no warranty.
+*/
+
+#include "common.h"
+#include "options.h"
+
+HINSTANCE hInst;
+PLUGINLINK *pluginLink;
+MM_INTERFACE mmi;
+
+HANDLE hEventWindow;
+
+//typedef LRESULT (CALLBACK *WNDPROC)(HWND, UINT, WPARAM, LPARAM);
+
+HANDLE hLastContact = 0;
+HWND hWndLastContact = 0;
+
+int vk = 'M', mod = VK_MENU;
+
+PLUGININFO pluginInfo={
+ sizeof(PLUGININFO),
+ MODULE,
+ PLUGIN_MAKE_VERSION(0,0,0,1),
+ "Re-open the last open message window using a configurable hot key.",
+ "Scott Ellis",
+ "mail@scottellis.com.au",
+ "© 2006 Scott Ellis",
+ "http://scottellis.com.au",
+ 0, //not transient
+ 0 //doesn't replace anything built-in
+};
+
+extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
+{
+ hInst=hinstDLL;
+ return TRUE;
+}
+
+extern "C" __declspec(dllexport) PLUGININFO* MirandaPluginInfo(DWORD mirandaVersion)
+{
+ return &pluginInfo;
+}
+
+void PlaceOnTop(HWND hwnd) {
+ // set window style
+ LONG ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
+ ex_style |= WS_EX_TOPMOST;
+ SetWindowLong(hwnd, GWL_EXSTYLE, ex_style);
+
+ if(DBGetContactSettingByte(0, MODULE, "MakeChildFullScreen", 0)) {
+ // make window child of any full-screen topmost windows
+ int w = GetSystemMetrics(SM_CXSCREEN);
+ int h = GetSystemMetrics(SM_CYSCREEN);
+
+ HWND hWnd = 0;
+ while (hWnd = FindWindowEx(NULL, hWnd, NULL, NULL)) {
+ if(!IsWindowVisible(hWnd) || IsIconic(hWnd))
+ continue;
+
+ if (!(GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOPMOST))
+ continue;
+
+ // not sure if this could be done more simply using 'IsZoomed'?
+ RECT WindowRect;
+ GetWindowRect(hWnd, &WindowRect);
+ if ((w != (WindowRect.right - WindowRect.left)) || (h != (WindowRect.bottom - WindowRect.top)))
+ continue;
+
+ SetParent(hwnd, hWnd);
+ break;
+ }
+ }
+}
+
+int WindowEvent(WPARAM wParam, LPARAM lParam) {
+ MessageWindowEventData *ed = (MessageWindowEventData *)lParam;
+
+ /*
+ // ignore chat room contacts?
+ char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)ed->hContact, 0);
+ if(proto && DBGetContactSettingByte(ed->hContact, proto, "ChatRoom", 0)) return 0;
+ */
+
+ switch(ed->uType) {
+ case MSG_WINDOW_EVT_OPENING:
+ hLastContact = ed->hContact;
+ break;
+ case MSG_WINDOW_EVT_OPEN:
+ // if there's a full-screen app running, make the window its child
+ hWndLastContact = ed->hwndWindow;
+ if(options.make_topmost) {
+ HWND hwnd = hWndLastContact, parent = 0;
+ while((parent = GetParent(hwnd)) != 0) hwnd = parent;
+ PlaceOnTop(hwnd);
+ }
+ break;
+ case MSG_WINDOW_EVT_CLOSING:
+ case MSG_WINDOW_EVT_CLOSE:
+ // care factor?
+ break;
+ }
+
+ return 0;
+}
+
+int ModulesLoaded(WPARAM wParam,LPARAM lParam) {
+ if(ServiceExists(MS_UPDATE_REGISTER)) {
+ // register with updater
+ Update update = {0};
+ char szVersion[16];
+
+ update.cbSize = sizeof(Update);
+
+ update.szComponentName = pluginInfo.shortName;
+ update.pbVersion = (BYTE *)CreateVersionString(pluginInfo.version, szVersion);
+ update.cpbVersion = strlen((char *)update.pbVersion);
+
+ update.szUpdateURL = UPDATER_AUTOREGISTER;
+
+ // these are the three lines that matter - the archive, the page containing the version string, and the text (or data)
+ // before the version that we use to locate it on the page
+ // (note that if the update URL and the version URL point to standard file listing entries, the backend xml
+ // data will be used to check for updates rather than the actual web page - this is not true for beta urls)
+ update.szBetaUpdateURL = "http://www.scottellis.com.au/miranda_plugins/last_contact.zip";
+ update.szBetaVersionURL = "http://www.scottellis.com.au/miranda_plugins/ver_last_contact.html";
+ update.pbBetaVersionPrefix = (BYTE *)MODULE " version ";
+
+ update.cpbBetaVersionPrefix = strlen((char *)update.pbBetaVersionPrefix);
+
+ CallService(MS_UPDATE_REGISTER, 0, (WPARAM)&update);
+ }
+
+ hEventWindow = HookEvent(ME_MSG_WINDOWEVENT, WindowEvent);
+
+ return 0;
+}
+
+int Shutdown(WPARAM wParam, LPARAM lParam) {
+ if(hEventWindow) UnhookEvent(hEventWindow);
+ return 0;
+}
+
+void CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD) {
+ if(GetAsyncKeyState(vk)
+ && (options.mod_alt == false || GetAsyncKeyState(VK_MENU))
+ && (options.mod_shift == false || GetAsyncKeyState(VK_SHIFT))
+ && (options.mod_ctrl == false || GetAsyncKeyState(VK_CONTROL))
+ && hLastContact)
+ {
+ if(options.hide_if_visible && IsWindow(hWndLastContact) && IsWindowVisible(hWndLastContact)) {
+ PostMessage(hWndLastContact, WM_COMMAND, 1023, 0); // chat close tab
+ PostMessage(hWndLastContact, WM_COMMAND, IDCANCEL, 0); // srmm/scriver close session button
+ PostMessage(hWndLastContact, WM_COMMAND, 1025, 0); // tabsrmm close session button
+ } else {
+ CallService(MS_MSG_SENDMESSAGE, (WPARAM)hLastContact, 0);
+ }
+ }
+}
+
+UINT_PTR timer_id;
+
+extern "C" int __declspec(dllexport) Load(PLUGINLINK *link)
+{
+ pluginLink = link;
+
+ mir_getMMI(&mmi);
+
+ HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded);
+ HookEvent(ME_SYSTEM_PRESHUTDOWN, Shutdown);
+
+ InitOptions();
+
+ // clear the key pressed flags
+ GetAsyncKeyState(vk);
+ if(options.mod_alt) GetAsyncKeyState(VK_MENU);
+ if(options.mod_shift) GetAsyncKeyState(VK_SHIFT);
+ if(options.mod_ctrl) GetAsyncKeyState(VK_CONTROL);
+
+ timer_id = SetTimer(0, 0, 500, TimerProc);
+
+ return 0;
+}
+
+extern "C" int __declspec(dllexport) Unload(void)
+{
+ KillTimer(0, timer_id);
+ return 0;
+}
+
|