From 7639f72273189df60566755c0d5f1e4ab7201b67 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 17 May 2018 20:51:37 +0300 Subject: NewAwaySys, NewEventNotify, NewXstatusNotify, NoHistory, NotesReminders, NotifyAnything, Nudge => CMPlugin --- plugins/NewAwaySysMod/src/AwayOpt.cpp | 2 +- plugins/NewAwaySysMod/src/AwaySys.cpp | 27 +-- plugins/NewAwaySysMod/src/MsgTree.cpp | 4 +- plugins/NewAwaySysMod/src/ReadAwayMsg.cpp | 4 +- plugins/NewAwaySysMod/src/Services.cpp | 2 +- plugins/NewAwaySysMod/src/SetAwayMsg.cpp | 4 +- plugins/NewAwaySysMod/src/stdafx.h | 16 +- plugins/NewEventNotify/src/main.cpp | 43 ++-- plugins/NewEventNotify/src/menuitem.cpp | 6 +- plugins/NewEventNotify/src/stdafx.h | 12 +- plugins/NewXstatusNotify/src/indsnd.cpp | 4 +- plugins/NewXstatusNotify/src/main.cpp | 79 ++++--- plugins/NewXstatusNotify/src/options.cpp | 4 +- plugins/NewXstatusNotify/src/stdafx.h | 12 +- plugins/NoHistory/src/dllmain.cpp | 16 +- plugins/NoHistory/src/icons.cpp | 2 +- plugins/NoHistory/src/options.cpp | 2 +- plugins/NoHistory/src/stdafx.h | 15 +- plugins/NotesAndReminders/src/globals.h | 17 +- plugins/NotesAndReminders/src/main.cpp | 77 +++--- plugins/NotesAndReminders/src/notes.cpp | 6 +- plugins/NotesAndReminders/src/reminders.cpp | 10 +- plugins/NotifyAnything/src/main.cpp | 22 +- plugins/NotifyAnything/src/options.cpp | 2 +- plugins/NotifyAnything/src/stdafx.h | 10 +- plugins/Nudge/src/main.cpp | 354 ++++++++++++++-------------- plugins/Nudge/src/options.cpp | 4 +- plugins/Nudge/src/stdafx.h | 9 +- 28 files changed, 396 insertions(+), 369 deletions(-) (limited to 'plugins') diff --git a/plugins/NewAwaySysMod/src/AwayOpt.cpp b/plugins/NewAwaySysMod/src/AwayOpt.cpp index 918589f4c1..731a5de605 100644 --- a/plugins/NewAwaySysMod/src/AwayOpt.cpp +++ b/plugins/NewAwaySysMod/src/AwayOpt.cpp @@ -1020,7 +1020,7 @@ int OptsDlgInit(WPARAM wParam, LPARAM) { OPTIONSDIALOGPAGE optDi = { sizeof(optDi) }; optDi.position = 920000000; - optDi.hInstance = g_hInstance; + optDi.hInstance = g_plugin.getInst(); optDi.flags = ODPF_BOLDGROUPS; optDi.szTitle.a = OPT_MAINGROUP; diff --git a/plugins/NewAwaySysMod/src/AwaySys.cpp b/plugins/NewAwaySysMod/src/AwaySys.cpp index a29cfd136d..14e0376802 100644 --- a/plugins/NewAwaySysMod/src/AwaySys.cpp +++ b/plugins/NewAwaySysMod/src/AwaySys.cpp @@ -41,9 +41,9 @@ #include "Services.h" #include "version.h" -HINSTANCE g_hInstance; - +CMPlugin g_plugin; int hLangpack; + HANDLE g_hTopToolbarbutton; HGENMENU g_hToggleSOEMenuItem, g_hToggleSOEContactMenuItem, g_hContactMenuItem, g_hReadStatMenuItem; HGENMENU g_hAutoreplyOnContactMenuItem, g_hAutoreplyOffContactMenuItem, g_hAutoreplyUseDefaultContactMenuItem; @@ -75,7 +75,10 @@ HICON GetIcon(int iconId, bool size) return nullptr; } -PLUGININFOEX pluginInfo = { +///////////////////////////////////////////////////////////////////////////////////////// + +PLUGININFOEX pluginInfo = +{ sizeof(PLUGININFOEX), __PLUGIN_NAME, PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), @@ -87,14 +90,6 @@ PLUGININFOEX pluginInfo = { { 0xb2dd9270, 0xce5e, 0x11df, { 0xbd, 0x3d, 0x8, 0x0, 0x20, 0xc, 0x9a, 0x66 } } }; -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID) -{ - g_hInstance = hinstDLL; - return TRUE; -} - -extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_SRAWAY, MIID_LAST }; // TODO: add MIID_WHOISREADING here if there'll be any some time in future.. - extern "C" __declspec(dllexport) PLUGININFOEX *MirandaPluginInfoEx(DWORD) { return &pluginInfo; @@ -102,6 +97,10 @@ extern "C" __declspec(dllexport) PLUGININFOEX *MirandaPluginInfoEx(DWORD) ///////////////////////////////////////////////////////////////////////////////////////// +extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_SRAWAY, MIID_LAST }; + +///////////////////////////////////////////////////////////////////////////////////////// + TCString GetDynamicStatMsg(MCONTACT hContact, char *szProto, DWORD UIN, int iStatus) { // hContact is the contact that requests the status message @@ -260,7 +259,7 @@ int StatusChanged(WPARAM wParam, LPARAM lParam) memset(dat, 0, sizeof(SetAwayMsgData)); dat->szProtocol = (char*)lParam; dat->IsModeless = false; - DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_SETAWAYMSG), nullptr, SetAwayMsgDlgProc, (LPARAM)dat); + DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_SETAWAYMSG), nullptr, SetAwayMsgDlgProc, (LPARAM)dat); } return 0; } @@ -378,7 +377,7 @@ static INT_PTR SetContactStatMsg(WPARAM hContact, LPARAM) dat->hInitContact = hContact; dat->szProtocol = GetContactProto(hContact); dat->IsModeless = false; - DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_SETAWAYMSG), nullptr, SetAwayMsgDlgProc, (LPARAM)dat); + DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_SETAWAYMSG), nullptr, SetAwayMsgDlgProc, (LPARAM)dat); return 0; } @@ -710,7 +709,7 @@ extern "C" int __declspec(dllexport) Load(void) HookEvent(ME_SYSTEM_MODULESLOADED, MirandaLoaded); - Icon_Register(g_hInstance, MOD_NAME, iconList, _countof(iconList), "nas"); + Icon_Register(g_plugin.getInst(), MOD_NAME, iconList, _countof(iconList), "nas"); InitCommonControls(); InitOptions(); // must be called before we hook CallService diff --git a/plugins/NewAwaySysMod/src/MsgTree.cpp b/plugins/NewAwaySysMod/src/MsgTree.cpp index 647f6bbff4..891789651e 100644 --- a/plugins/NewAwaySysMod/src/MsgTree.cpp +++ b/plugins/NewAwaySysMod/src/MsgTree.cpp @@ -369,9 +369,9 @@ LRESULT CALLBACK MsgTreeSubclassProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM if (Order >= 0) { HMENU hMenu; if (TreeCtrl->m_value[Order].Flags & TIF_GROUP) - hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_MSGTREE_CATEGORYMENU)); + hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_MSGTREE_CATEGORYMENU)); else - hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_MSGTREE_MESSAGEMENU)); + hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_MSGTREE_MESSAGEMENU)); _ASSERT(hMenu); HMENU hPopupMenu = GetSubMenu(hMenu, 0); diff --git a/plugins/NewAwaySysMod/src/ReadAwayMsg.cpp b/plugins/NewAwaySysMod/src/ReadAwayMsg.cpp index c65196fc67..45ae7c6dce 100644 --- a/plugins/NewAwaySysMod/src/ReadAwayMsg.cpp +++ b/plugins/NewAwaySysMod/src/ReadAwayMsg.cpp @@ -110,7 +110,7 @@ static INT_PTR CALLBACK ReadAwayMsgDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam break; case WM_SIZE: - Utils_ResizeDialog(hwndDlg, g_hInstance, MAKEINTRESOURCEA(IDD_READAWAYMSG), ReadAwayMsgDlgResize); + Utils_ResizeDialog(hwndDlg, g_plugin.getInst(), MAKEINTRESOURCEA(IDD_READAWAYMSG), ReadAwayMsgDlgResize); break; case WM_CLOSE: @@ -135,6 +135,6 @@ INT_PTR GetContactStatMsg(WPARAM wParam, LPARAM) if (HWND hWnd = WindowList_Find(g_hReadWndList, wParam)) // already have it SetForegroundWindow(hWnd); else - CreateDialogParam(g_hInstance, MAKEINTRESOURCE(IDD_READAWAYMSG), nullptr, ReadAwayMsgDlgProc, wParam); + CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_READAWAYMSG), nullptr, ReadAwayMsgDlgProc, wParam); return 0; } diff --git a/plugins/NewAwaySysMod/src/Services.cpp b/plugins/NewAwaySysMod/src/Services.cpp index c807905c73..1300c7c556 100644 --- a/plugins/NewAwaySysMod/src/Services.cpp +++ b/plugins/NewAwaySysMod/src/Services.cpp @@ -182,5 +182,5 @@ INT_PTR InvokeStatusWindow(WPARAM wParam, LPARAM) dat->IsModeless = true; if (iswi->cbSize > sizeof(NAS_ISWINFOv1)) dat->ISW_Flags = iswi->Flags; - return (INT_PTR)CreateDialogParam(g_hInstance, MAKEINTRESOURCE(IDD_SETAWAYMSG), nullptr, SetAwayMsgDlgProc, (LPARAM)dat); + return (INT_PTR)CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_SETAWAYMSG), nullptr, SetAwayMsgDlgProc, (LPARAM)dat); } diff --git a/plugins/NewAwaySysMod/src/SetAwayMsg.cpp b/plugins/NewAwaySysMod/src/SetAwayMsg.cpp index 1d9f70b544..88fb5f0dcd 100644 --- a/plugins/NewAwaySysMod/src/SetAwayMsg.cpp +++ b/plugins/NewAwaySysMod/src/SetAwayMsg.cpp @@ -1048,7 +1048,7 @@ INT_PTR CALLBACK SetAwayMsgDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA case IDC_SAWAYMSG_OPTIONS: { - HMENU hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_SAM_OPTIONS)); + HMENU hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_SAM_OPTIONS)); _ASSERT(hMenu); HMENU hPopupMenu = GetSubMenu(hMenu, 0); TranslateMenu(hPopupMenu); @@ -1254,7 +1254,7 @@ INT_PTR CALLBACK SetAwayMsgDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA return true; case WM_SIZE: - Utils_ResizeDialog(hwndDlg, g_hInstance, MAKEINTRESOURCEA(IDD_SETAWAYMSG), SetAwayMsgDlgResize, (LPARAM)&g_SetAwayMsgPage); + Utils_ResizeDialog(hwndDlg, g_plugin.getInst(), MAKEINTRESOURCEA(IDD_SETAWAYMSG), SetAwayMsgDlgResize, (LPARAM)&g_SetAwayMsgPage); // means that we sent WM_SIZE message to apply new settings to the dialog; probably it's somewhat a misuse, but who cares ;-P if (!wParam && !lParam) { diff --git a/plugins/NewAwaySysMod/src/stdafx.h b/plugins/NewAwaySysMod/src/stdafx.h index c31cad6418..991bd0aa23 100644 --- a/plugins/NewAwaySysMod/src/stdafx.h +++ b/plugins/NewAwaySysMod/src/stdafx.h @@ -36,8 +36,6 @@ #include #include -#define __NO_CMPLUGIN_NEEDED - #include "newpluginapi.h" #include "m_clist.h" #include "m_system.h" @@ -221,6 +219,15 @@ int ICQStatusToGeneralStatus(int bICQStat); // TODO: get rid of these protocol-s #define MS_AWAYSYS_SETSTATUSMODE "AwaySys/SetStatusMode" // change the status mode. wParam is new mode, lParam is new status message (AwaySys will interpret variables out of it), may be NULL. #define MS_AWAYSYS_IGNORENEXT "AwaySys/IgnoreNextStatusChange" //ignore nest status change +///////////////////////////////////////////////////////////////////////////////////////// + +struct CMPlugin : public PLUGIN +{ + CMPlugin() : + PLUGIN(MOD_NAME) + {} +}; + struct SetAwayMsgData { CString szProtocol; @@ -272,7 +279,6 @@ extern COptPage g_AutoreplyOptPage; extern COptPage g_MoreOptPage; extern COptPage g_SetAwayMsgPage; -extern HINSTANCE g_hInstance; extern int g_Messages_RecentRootID, g_Messages_PredefinedRootID; extern VAR_PARSE_DATA VarParseData; extern bool g_fNoProcessing; @@ -304,8 +310,6 @@ void ShowLog(TCString &LogFilePath); void ShowMsg(wchar_t *szFirstLine, wchar_t *szSecondLine = L"", bool IsErrorMsg = false, int Timeout = 0); #define AWAYSYS_STATUSMSGREQUEST_SOUND "AwaySysStatusMsgRequest" -#define ME_AWAYSYS_WORKAROUND "AwaySys/_CallService" -int _Workaround_CallService(const char *name, WPARAM wParam, LPARAM lParam); // MsgEventAdded.cpp int MsgEventAdded(WPARAM wParam, LPARAM lParam); @@ -343,4 +347,4 @@ static __inline int my_variables_showhelp(HWND hwndDlg, UINT uIDEdit, int flags //icons extern IconItem iconList[]; -HICON GetIcon(int iconId, bool size = false); \ No newline at end of file +HICON GetIcon(int iconId, bool size = false); diff --git a/plugins/NewEventNotify/src/main.cpp b/plugins/NewEventNotify/src/main.cpp index 571abdd1be..973c77ac37 100644 --- a/plugins/NewEventNotify/src/main.cpp +++ b/plugins/NewEventNotify/src/main.cpp @@ -26,14 +26,19 @@ extern PLUGIN_DATA* PopupList[20]; +PLUGIN_OPTIONS pluginOptions; + //--------------------------- //---Some global variables for the plugin CLIST_INTERFACE *pcli; -HINSTANCE g_hInst; -PLUGIN_OPTIONS pluginOptions; +CMPlugin g_plugin; int hLangpack; -PLUGININFOEX pluginInfo = { + +///////////////////////////////////////////////////////////////////////////////////////// + +PLUGININFOEX pluginInfo = +{ sizeof(PLUGININFOEX), __PLUGIN_NAME, PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), @@ -46,12 +51,17 @@ PLUGININFOEX pluginInfo = { {0x3503D584, 0x6234, 0x4BEF, {0xA5, 0x53, 0x6C, 0x1B, 0x9C, 0xD4, 0x71, 0xF2}} }; -//--------------------------- -//---Hooks +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) +{ + return &pluginInfo; +} + +///////////////////////////////////////////////////////////////////////////////////////// +// Hooks //---Called when a new event is added to the database -//wParam: contact-handle -//lParam: dbevent-handle +// wParam: contact-handle +// lParam: dbevent-handle int HookedNewEvent(WPARAM hContact, LPARAM hDbEvent) { @@ -117,17 +127,11 @@ int HookedInit(WPARAM, LPARAM) //---Called when an options dialog has to be created int HookedOptions(WPARAM wParam, LPARAM) { - OptionsAdd(g_hInst, wParam); + OptionsAdd(g_plugin.getInst(), wParam); return 0; } -//--------------------------- -//---Exported Functions - -extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) -{ - return &pluginInfo; -} +///////////////////////////////////////////////////////////////////////////////////////// extern "C" __declspec(dllexport) int Load(void) { @@ -138,21 +142,16 @@ extern "C" __declspec(dllexport) int Load(void) pcli = Clist_GetInterface(); OptionsInit(&pluginOptions); - pluginOptions.hInst = g_hInst; return 0; } +///////////////////////////////////////////////////////////////////////////////////////// + extern "C" __declspec(dllexport) int Unload(void) { return 0; } -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID) -{ - g_hInst = hinstDLL; - return TRUE; -} - //------------------------------------- //---Check Window Message function diff --git a/plugins/NewEventNotify/src/menuitem.cpp b/plugins/NewEventNotify/src/menuitem.cpp index 63be89ce14..d2c04d4d04 100644 --- a/plugins/NewEventNotify/src/menuitem.cpp +++ b/plugins/NewEventNotify/src/menuitem.cpp @@ -40,9 +40,9 @@ static INT_PTR MenuitemNotifyCmd(WPARAM, LPARAM) int MenuitemUpdate(BOOL bStatus) { if (bStatus) - Menu_ModifyItem(hMenuitemNotify, MENUITEM_DISABLE, LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ENABLED))); + Menu_ModifyItem(hMenuitemNotify, MENUITEM_DISABLE, LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_ENABLED))); else - Menu_ModifyItem(hMenuitemNotify, MENUITEM_ENABLE, LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_DISABLED))); + Menu_ModifyItem(hMenuitemNotify, MENUITEM_ENABLE, LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_DISABLED))); return 0; } @@ -56,7 +56,7 @@ int MenuitemInit(BOOL bStatus) SET_UID(mi, 0x7aed93f7, 0x835, 0x4ff6, 0xb1, 0x34, 0xae, 0x0, 0x21, 0x2a, 0xd7, 0x81); mi.root = hRoot; mi.position = 1; - mi.hIcolibItem = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ENABLED)); + mi.hIcolibItem = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_ENABLED)); mi.pszService = MS_NEN_MENUNOTIFY; mi.flags = 0; hMenuitemNotify = Menu_AddMainMenuItem(&mi); diff --git a/plugins/NewEventNotify/src/stdafx.h b/plugins/NewEventNotify/src/stdafx.h index 3a9fe248b7..b36d98cf32 100644 --- a/plugins/NewEventNotify/src/stdafx.h +++ b/plugins/NewEventNotify/src/stdafx.h @@ -32,8 +32,6 @@ #include #include -#define __NO_CMPLUGIN_NEEDED - #include #include #include @@ -150,9 +148,15 @@ //--------------------------- //---Structures +struct CMPlugin : public PLUGIN +{ + CMPlugin() : + PLUGIN(MODULE) + {} +}; + struct PLUGIN_OPTIONS { - HINSTANCE hInst; BOOL bDisable; BOOL bPreview; BOOL bMenuitem; @@ -226,5 +230,3 @@ int MenuitemInit(BOOL bStatus); int MenuitemUpdate(BOOL bStatus); int NumberPopupData(MCONTACT hContact, int eventType); int CheckMsgWnd(MCONTACT hContact); - -extern HINSTANCE g_hInst; diff --git a/plugins/NewXstatusNotify/src/indsnd.cpp b/plugins/NewXstatusNotify/src/indsnd.cpp index 697e59dc34..98bf7c9d6a 100644 --- a/plugins/NewXstatusNotify/src/indsnd.cpp +++ b/plugins/NewXstatusNotify/src/indsnd.cpp @@ -69,7 +69,7 @@ wchar_t *SelectSound(HWND hwndDlg, wchar_t *buff, size_t bufflen) ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = GetParent(hwndDlg); - ofn.hInstance = hInst; + ofn.hInstance = g_plugin.getInst(); wchar_t filter[MAX_PATH]; if (GetModuleHandle(L"bass_interface.dll")) mir_snwprintf(filter, L"%s (*.wav, *.mp3, *.ogg)%c*.wav;*.mp3;*.ogg%c%s (*.*)%c*%c", TranslateT("Sound files"), 0, 0, TranslateT("All files"), 0, 0); @@ -597,7 +597,7 @@ int UserInfoInitialise(WPARAM wParam, LPARAM lParam) if (lParam) { OPTIONSDIALOGPAGE odp = { 0 }; odp.position = 100000000; - odp.hInstance = hInst; + odp.hInstance = g_plugin.getInst(); odp.pszTemplate = MAKEINTRESOURCEA(IDD_INFO_SOUNDS); odp.szTitle.a = LPGEN("Status Notify"); odp.pfnDlgProc = DlgProcSoundUIPage; diff --git a/plugins/NewXstatusNotify/src/main.cpp b/plugins/NewXstatusNotify/src/main.cpp index 09d9025e14..e960275006 100644 --- a/plugins/NewXstatusNotify/src/main.cpp +++ b/plugins/NewXstatusNotify/src/main.cpp @@ -22,8 +22,8 @@ #include "stdafx.h" CLIST_INTERFACE *pcli; - -HINSTANCE hInst; +CMPlugin g_plugin; +int hLangpack; LIST eventListXStatus(10, PtrKeySortT); LIST eventListStatus(10, PtrKeySortT); @@ -35,11 +35,29 @@ HGENMENU hEnableDisableMenu; STATUS StatusList[STATUS_COUNT]; STATUS StatusListEx[STATUSEX_COUNT]; HWND SecretWnd; -int hLangpack; int ContactStatusChanged(MCONTACT hContact, WORD oldStatus, WORD newStatus); -PLUGININFOEX pluginInfoEx = { +IconItem iconList[] = +{ + { LPGEN("Reset"), ICO_RESET, IDI_RESET }, + { LPGEN("Popups"), ICO_POPUP, IDI_POPUP }, + { LPGEN("Sounds"), ICO_SOUND, IDI_SOUND }, + { LPGEN("Notification enabled"), ICO_NOTIFICATION_OFF, IDI_NOTIFICATION_OFF }, + { LPGEN("Notification disabled"), ICO_NOTIFICATION_ON, IDI_NOTIFICATION_ON }, + { LPGEN("Extra status notify"), ICO_XSTATUS, IDI_XSTATUS }, + { LPGEN("Disable all"), ICO_DISABLEALL, IDI_DISABLEALL }, + { LPGEN("Enable all"), ICO_ENABLEALL, IDI_ENABLEALL }, + { LPGEN("Variables"), ICO_VARIABLES, IDI_VARIABLES }, + { LPGEN("Status message notify"), ICO_STATUS_MESSAGE, IDI_STATUS_MESSAGE }, + { LPGEN("Extra status logging"), ICO_LOGGING_XSTATUS, IDI_LOGGING_XSTATUS }, + { LPGEN("Status message logging"), ICO_LOGGING_SMSG, IDI_LOGGING_SMSG } +}; + +///////////////////////////////////////////////////////////////////////////////////////// + +PLUGININFOEX pluginInfoEx = +{ sizeof(PLUGININFOEX), __PLUGIN_NAME, PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), @@ -52,19 +70,17 @@ PLUGININFOEX pluginInfoEx = { { 0xebf19652, 0xe434, 0x4d79, { 0x98, 0x97, 0x91, 0xa0, 0xff, 0x22, 0x6f, 0x51 } } }; -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID) -{ - hInst = hinstDLL; - return TRUE; -} - extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) { return &pluginInfoEx; } +///////////////////////////////////////////////////////////////////////////////////////// + extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_USERONLINE, MIID_LAST }; +///////////////////////////////////////////////////////////////////////////////////////// + BYTE GetGender(MCONTACT hContact) { char *szProto = GetContactProto(hContact); @@ -107,7 +123,8 @@ static int __inline CheckStrW(WCHAR *str, int not_empty, int empty) return not_empty; } -static int CompareStatusMsg(STATUSMSGINFO *smi, DBCONTACTWRITESETTING *cws_new, char *szSetting) { +static int CompareStatusMsg(STATUSMSGINFO *smi, DBCONTACTWRITESETTING *cws_new, char *szSetting) +{ DBVARIANT dbv_old; int ret = -1; @@ -325,7 +342,7 @@ void PlayChangeSound(MCONTACT hContact, const char *name) DBVARIANT dbv; wchar_t stzSoundFile[MAX_PATH] = { 0 }; if (!db_get_ws(hContact, MODULE, name, &dbv)) { - wcsncpy(stzSoundFile, dbv.ptszVal, _countof(stzSoundFile)-1); + wcsncpy(stzSoundFile, dbv.ptszVal, _countof(stzSoundFile) - 1); db_free(&dbv); } @@ -695,7 +712,7 @@ int ProcessStatusMessage(DBCONTACTWRITESETTING *cws, MCONTACT hContact) if (db_get_ws(NULL, MODULE, protoname, &dbVar)) { str = GetStr(&smi, DEFAULT_POPUP_SMSGREMOVED); } - else { + else { str = GetStr(&smi, dbVar.ptszVal); db_free(&dbVar); } @@ -1079,28 +1096,7 @@ void InitMainMenuItem() EnableDisableMenuCommand(0, 0); } -IconItem iconList[] = -{ - { LPGEN("Reset"), ICO_RESET, IDI_RESET }, - { LPGEN("Popups"), ICO_POPUP, IDI_POPUP }, - { LPGEN("Sounds"), ICO_SOUND, IDI_SOUND }, - { LPGEN("Notification enabled"), ICO_NOTIFICATION_OFF, IDI_NOTIFICATION_OFF }, - { LPGEN("Notification disabled"), ICO_NOTIFICATION_ON, IDI_NOTIFICATION_ON }, - { LPGEN("Extra status notify"), ICO_XSTATUS, IDI_XSTATUS }, - { LPGEN("Disable all"), ICO_DISABLEALL, IDI_DISABLEALL }, - { LPGEN("Enable all"), ICO_ENABLEALL, IDI_ENABLEALL }, - { LPGEN("Variables"), ICO_VARIABLES, IDI_VARIABLES }, - { LPGEN("Status message notify"), ICO_STATUS_MESSAGE, IDI_STATUS_MESSAGE }, - { LPGEN("Extra status logging"), ICO_LOGGING_XSTATUS, IDI_LOGGING_XSTATUS }, - { LPGEN("Status message logging"), ICO_LOGGING_SMSG, IDI_LOGGING_SMSG } -}; - -void InitIcolib() -{ - Icon_Register(hInst, LPGEN("New Status Notify"), iconList, _countof(iconList), MODULE); -} - -void InitSound() +static void InitSound() { for (int i = ID_STATUS_MIN; i <= ID_STATUS_MAX; i++) Skin_AddSound(StatusList[Index(i)].lpzSkinSoundName, LPGENW("Status Notify"), StatusList[Index(i)].lpzSkinSoundDesc); @@ -1109,7 +1105,7 @@ void InitSound() Skin_AddSound(StatusListEx[i].lpzSkinSoundName, LPGENW("Status Notify"), StatusListEx[i].lpzSkinSoundDesc); } -int InitTopToolbar(WPARAM, LPARAM) +static int InitTopToolbar(WPARAM, LPARAM) { TTBButton tbb = {}; tbb.pszService = MS_STATUSCHANGE_MENUCOMMAND; @@ -1124,7 +1120,7 @@ int InitTopToolbar(WPARAM, LPARAM) return 0; } -int ModulesLoaded(WPARAM, LPARAM) +static int ModulesLoaded(WPARAM, LPARAM) { InitMainMenuItem(); @@ -1134,7 +1130,7 @@ int ModulesLoaded(WPARAM, LPARAM) SecretWnd = CreateWindowEx(WS_EX_TOOLWINDOW, L"static", L"ConnectionTimerWindow", 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, HWND_DESKTOP, - nullptr, hInst, nullptr); + nullptr, g_plugin.getInst(), nullptr); for (auto &pa : Accounts()) if (pa->IsEnabled()) @@ -1149,11 +1145,15 @@ static int OnShutdown(WPARAM, LPARAM) return 0; } +///////////////////////////////////////////////////////////////////////////////////////// + extern "C" int __declspec(dllexport) Load(void) { mir_getLP(&pluginInfoEx); pcli = Clist_GetInterface(); + Icon_Register(g_plugin.getInst(), LPGEN("New Status Notify"), iconList, _countof(iconList), MODULE); + //"Service" Hook, used when the DB settings change: we'll monitor the "status" setting. HookEvent(ME_DB_CONTACT_SETTINGCHANGED, ContactSettingChanged); @@ -1170,7 +1170,6 @@ extern "C" int __declspec(dllexport) Load(void) HookEvent(ME_CLIST_STATUSMODECHANGE, StatusModeChanged); HookEvent(ME_PROTO_ACK, ProtoAck); - InitIcolib(); LoadOptions(); InitStatusList(); InitSound(); @@ -1193,6 +1192,8 @@ extern "C" int __declspec(dllexport) Load(void) return 0; } +///////////////////////////////////////////////////////////////////////////////////////// + extern "C" int __declspec(dllexport) Unload(void) { DestroyHookableEvent(hHookContactStatusChanged); diff --git a/plugins/NewXstatusNotify/src/options.cpp b/plugins/NewXstatusNotify/src/options.cpp index 4c88c3d10a..1187e17cab 100644 --- a/plugins/NewXstatusNotify/src/options.cpp +++ b/plugins/NewXstatusNotify/src/options.cpp @@ -225,7 +225,7 @@ INT_PTR CALLBACK DlgProcGeneralOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_CONFIGUREAUTODISABLE: - CreateDialog(hInst, MAKEINTRESOURCE(IDD_AUTODISABLE), hwndDlg, DlgProcAutoDisableOpts); + CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_AUTODISABLE), hwndDlg, DlgProcAutoDisableOpts); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); return FALSE; case IDC_AUTODISABLE: @@ -1174,7 +1174,7 @@ int OptionsInitialize(WPARAM wParam, LPARAM) { OPTIONSDIALOGPAGE odp = { 0 }; odp.position = -100000000; - odp.hInstance = hInst; + odp.hInstance = g_plugin.getInst(); odp.flags = ODPF_BOLDGROUPS; odp.szTitle.a = LPGEN("Status Notify"); odp.szGroup.a = LPGEN("Status"); diff --git a/plugins/NewXstatusNotify/src/stdafx.h b/plugins/NewXstatusNotify/src/stdafx.h index 98b7f13614..a4def10dd4 100644 --- a/plugins/NewXstatusNotify/src/stdafx.h +++ b/plugins/NewXstatusNotify/src/stdafx.h @@ -34,8 +34,6 @@ #include #include -#define __NO_CMPLUGIN_NEEDED - #include #include #include @@ -70,6 +68,13 @@ #define MODULE "NewStatusNotify" +struct CMPlugin : public PLUGIN +{ + CMPlugin() : + PLUGIN(MODULE) + {} +}; + #define MAX_STATUSTEXT 36 #define MAX_STANDARDTEXT 36 #define MAX_SKINSOUNDNAME 36 @@ -89,7 +94,7 @@ #define ID_STATUSEX_MAX 6 #define STATUSEX_COUNT ID_STATUSEX_MAX + 1 #define ID_STATUS_EXTRASTATUS 40081 -#define ID_STATUS_STATUSMSG 40082 +#define ID_STATUS_STATUSMSG 40082 #define ID_STATUS_MIN ID_STATUS_OFFLINE #define ID_STATUS_MAX ID_STATUS_OUTTOLUNCH #define ID_STATUS_MAX2 ID_STATUS_STATUSMSG @@ -157,7 +162,6 @@ extern LIST eventListXStatus; extern LIST eventListStatus; extern LIST eventListSMsg; extern TEMPLATES templates; -extern HINSTANCE hInst; extern HGENMENU hEnableDisableMenu; extern STATUS StatusList[STATUS_COUNT]; extern STATUS StatusListEx[STATUSEX_COUNT]; diff --git a/plugins/NoHistory/src/dllmain.cpp b/plugins/NoHistory/src/dllmain.cpp index cbd5db623c..9b03d1d110 100644 --- a/plugins/NoHistory/src/dllmain.cpp +++ b/plugins/NoHistory/src/dllmain.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" -HINSTANCE hInst; int hLangpack = 0; +CMPlugin g_plugin; // add icon to srmm status icons static void SrmmMenu_UpdateIcon(MCONTACT hContact); @@ -41,17 +41,13 @@ PLUGININFOEX pluginInfo = {0xb25e8c7b, 0x292b, 0x495a, {0x9f, 0xb8, 0xa4, 0xc3, 0xd4, 0xee, 0xb0, 0x4b}} }; -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID) -{ - hInst = hinstDLL; - return TRUE; -} - extern "C" __declspec (dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) { return &pluginInfo; } +///////////////////////////////////////////////////////////////////////////////////////// + void RemoveReadEvents(MCONTACT hContact = 0) { DBEVENTINFO info = {}; @@ -240,7 +236,9 @@ void SrmmMenu_Load() HookEvent(ME_MSG_ICONPRESSED, IconPressed); } -int ModulesLoaded(WPARAM, LPARAM) +///////////////////////////////////////////////////////////////////////////////////////// + +static int ModulesLoaded(WPARAM, LPARAM) { // create contact menu item CMenuItem mi; @@ -285,6 +283,8 @@ extern "C" __declspec (dllexport) int Load() return 0; } +///////////////////////////////////////////////////////////////////////////////////////// + extern "C" __declspec (dllexport) int Unload(void) { RemoveReadEvents(); diff --git a/plugins/NoHistory/src/icons.cpp b/plugins/NoHistory/src/icons.cpp index c718ecd356..d5c504abcc 100644 --- a/plugins/NoHistory/src/icons.cpp +++ b/plugins/NoHistory/src/icons.cpp @@ -19,7 +19,7 @@ int ReloadIcons(WPARAM, LPARAM) void InitIcons() { - Icon_Register(hInst, LPGEN("No History"), iconList, _countof(iconList), MODULE); + Icon_Register(g_plugin.getInst(), LPGEN("No History"), iconList, _countof(iconList), MODULE); ReloadIcons(0, 0); diff --git a/plugins/NoHistory/src/options.cpp b/plugins/NoHistory/src/options.cpp index a631c749fa..da4d9555d2 100644 --- a/plugins/NoHistory/src/options.cpp +++ b/plugins/NoHistory/src/options.cpp @@ -221,7 +221,7 @@ int OptInit(WPARAM wParam, LPARAM) OPTIONSDIALOGPAGE odp = { 0 }; odp.flags = ODPF_BOLDGROUPS|ODPF_UNICODE; odp.position = -790000000; - odp.hInstance = hInst; + odp.hInstance = g_plugin.getInst(); odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT); odp.szTitle.w = LPGENW("No History"); odp.szGroup.w = LPGENW("History"); diff --git a/plugins/NoHistory/src/stdafx.h b/plugins/NoHistory/src/stdafx.h index 7ce31be872..295a3b01df 100644 --- a/plugins/NoHistory/src/stdafx.h +++ b/plugins/NoHistory/src/stdafx.h @@ -4,7 +4,6 @@ #include #include -#define __NO_CMPLUGIN_NEEDED #include #include #include @@ -22,13 +21,17 @@ #include "options.h" #include "version.h" -#define MODULE "NoHistory" -#define DBSETTING_REMOVE "RemoveHistory" +#define MODULE "NoHistory" -extern HINSTANCE hInst; +#define DBSETTING_REMOVE "RemoveHistory" -#endif +struct CMPlugin : public PLUGIN +{ + CMPlugin() : + PLUGIN(MODULE) + {} +}; void SrmmMenu_Load(); - +#endif diff --git a/plugins/NotesAndReminders/src/globals.h b/plugins/NotesAndReminders/src/globals.h index c67ece2043..90c0003964 100644 --- a/plugins/NotesAndReminders/src/globals.h +++ b/plugins/NotesAndReminders/src/globals.h @@ -7,7 +7,6 @@ #include #include -#define __NO_CMPLUGIN_NEEDED #include #include #include @@ -29,6 +28,13 @@ #define MODULENAME "StickyNotes" #define SECTIONNAME LPGEN("Notes & Reminders") +struct CMPlugin : public PLUGIN +{ + CMPlugin() : + PLUGIN(MODULENAME) + {} +}; + // normal timer interval for reminder update processing #define REMINDER_UPDATE_INTERVAL 10000 // short timer interval for reminder updates used as long as there are pending alarams in the event queue @@ -40,7 +46,6 @@ #define NR_FONTID_BODY 1 #define NR_FONTID_MAX NR_FONTID_BODY - typedef struct { HFONT hFont; char size; @@ -77,8 +82,8 @@ typedef struct { extern void CreateMsgWindow(void); extern void DestroyMsgWindow(void); -extern STICKYNOTE* NewNote(int Ax,int Ay,int Aw,int Ah,char *Data, - ULARGE_INTEGER *ID,BOOL Visible,BOOL bOnTop,int scrollV); +extern STICKYNOTE* NewNote(int Ax,int Ay,int Aw,int Ah,char *Data, ULARGE_INTEGER *ID,BOOL Visible,BOOL bOnTop,int scrollV); + extern void LoadNotes(BOOL bIsStartup); extern void SaveNotes(void); extern void DeleteNotes(void); @@ -94,8 +99,7 @@ extern BOOL CheckRemindersAndStart(void); extern void InitSettings(void); extern void TermSettings(void); -extern INT_PTR CALLBACK DlgProcOptions(HWND hdlg,UINT message, - WPARAM wParam,LPARAM lParam); +extern INT_PTR CALLBACK DlgProcOptions(HWND hdlg,UINT message, WPARAM wParam,LPARAM lParam); extern void LoadNRFont(int i, LOGFONT *lf, COLORREF *colour); extern BOOL WS_Init(); @@ -104,7 +108,6 @@ extern void WS_CleanUp(); extern LPCSTR GetDateFormatStr(); extern LPCSTR GetTimeFormatStr(); -extern HINSTANCE hinstance; extern HINSTANCE hmiranda; extern BOOL g_CloseAfterAddReminder, g_UseDefaultPlaySound; diff --git a/plugins/NotesAndReminders/src/main.cpp b/plugins/NotesAndReminders/src/main.cpp index f3d2c3af51..9f3cd465fe 100644 --- a/plugins/NotesAndReminders/src/main.cpp +++ b/plugins/NotesAndReminders/src/main.cpp @@ -1,7 +1,7 @@ #include "globals.h" CLIST_INTERFACE *pcli; -HINSTANCE hinstance = nullptr; +CMPlugin g_plugin; HINSTANCE hmiranda = nullptr; int hLangpack; @@ -15,6 +15,8 @@ HMODULE hRichedDll = nullptr; extern TREEELEMENT *g_Stickies; extern TREEELEMENT *RemindersList; +///////////////////////////////////////////////////////////////////////////////////////// + static PLUGININFOEX pluginInfo = { sizeof(PLUGININFOEX), @@ -28,6 +30,12 @@ static PLUGININFOEX pluginInfo = {0x842a6668, 0xf9da, 0x4968, {0xbf, 0xd7, 0xd2, 0xbd, 0x9d, 0xf8, 0x48, 0xee}} // {842A6668-F9DA-4968-BFD7-D2BD9DF848EE} }; +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) +{ + return &pluginInfo; +} + +///////////////////////////////////////////////////////////////////////////////////////// void RegisterFontServiceFonts(); void RegisterKeyBindings(); @@ -110,14 +118,14 @@ IconItem iconList[] = void InitIcons(void) { - Icon_Register(hinstance, LPGEN("Sticky Notes"), iconList, _countof(iconList), MODULENAME); + Icon_Register(g_plugin.getInst(), LPGEN("Sticky Notes"), iconList, _countof(iconList), MODULENAME); } static int OnOptInitialise(WPARAM w, LPARAM) { OPTIONSDIALOGPAGE odp = { 0 }; odp.position = 900002000; - odp.hInstance = hinstance; + odp.hInstance = g_plugin.getInst(); odp.pszTemplate = MAKEINTRESOURCEA(IDD_STNOTEOPTIONS); odp.szTitle.a = SECTIONNAME; odp.szGroup.a = LPGEN("Plugins"); @@ -259,41 +267,7 @@ int OnModulesLoaded(WPARAM, LPARAM) return 0; } -extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) -{ - return &pluginInfo; -} - -extern "C" __declspec(dllexport) int Unload(void) -{ - CloseNotesList(); - CloseReminderList(); - SaveNotes(); - SaveReminders(); - DestroyMsgWindow(); - WS_CleanUp(); - TermSettings(); - - UnhookEvent(hkFontChange); - UnhookEvent(hkColorChange); - - UnhookEvent(hkOptInit); - - IcoLib_ReleaseIcon(g_hReminderIcon); - DeleteObject(hBodyFont); - DeleteObject(hCaptionFont); - - if (hRichedDll) - FreeLibrary(hRichedDll); - - return 0; -} - -BOOL WINAPI DllMain(HINSTANCE hinst, DWORD, LPVOID) -{ - hinstance = hinst; - return TRUE; -} +///////////////////////////////////////////////////////////////////////////////////////// extern "C" __declspec(dllexport) int Load(void) { @@ -321,3 +295,30 @@ extern "C" __declspec(dllexport) int Load(void) return 0; } + +///////////////////////////////////////////////////////////////////////////////////////// + +extern "C" __declspec(dllexport) int Unload(void) +{ + CloseNotesList(); + CloseReminderList(); + SaveNotes(); + SaveReminders(); + DestroyMsgWindow(); + WS_CleanUp(); + TermSettings(); + + UnhookEvent(hkFontChange); + UnhookEvent(hkColorChange); + + UnhookEvent(hkOptInit); + + IcoLib_ReleaseIcon(g_hReminderIcon); + DeleteObject(hBodyFont); + DeleteObject(hCaptionFont); + + if (hRichedDll) + FreeLibrary(hRichedDll); + + return 0; +} diff --git a/plugins/NotesAndReminders/src/notes.cpp b/plugins/NotesAndReminders/src/notes.cpp index 2cfde03695..1f843c520c 100644 --- a/plugins/NotesAndReminders/src/notes.cpp +++ b/plugins/NotesAndReminders/src/notes.cpp @@ -898,7 +898,7 @@ static BOOL DoContextMenu(HWND AhWnd, WPARAM, LPARAM lParam) STICKYNOTE *SN = (STICKYNOTE*)GetProp(AhWnd, "ctrldata"); HMENU hMenuLoad, FhMenu, hSub; - hMenuLoad = LoadMenu(hinstance, "MNU_NOTEPOPUP"); + hMenuLoad = LoadMenu(g_plugin.getInst(), "MNU_NOTEPOPUP"); FhMenu = GetSubMenu(hMenuLoad, 0); if (SN->bOnTop) @@ -1688,7 +1688,7 @@ static BOOL DoListContextMenu(HWND AhWnd, WPARAM wParam, LPARAM lParam, STICKYNO if (hwndListView != GetDlgItem(AhWnd, IDC_LISTREMINDERS)) return FALSE; - HMENU hMenuLoad = LoadMenu(hinstance, "MNU_NOTELISTPOPUP"); + HMENU hMenuLoad = LoadMenu(g_plugin.getInst(), "MNU_NOTELISTPOPUP"); HMENU FhMenu = GetSubMenu(hMenuLoad, 0); MENUITEMINFO mii = { 0 }; @@ -1947,7 +1947,7 @@ static INT_PTR CALLBACK DlgProcViewNotes(HWND Dialog, UINT Message, WPARAM wPara void ListNotes(void) { if (!ListNotesVisible) { - CreateDialog(hinstance, MAKEINTRESOURCE(IDD_LISTREMINDERS), nullptr, DlgProcViewNotes); + CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_LISTREMINDERS), nullptr, DlgProcViewNotes); ListNotesVisible = TRUE; } else BringWindowToTop(LV); diff --git a/plugins/NotesAndReminders/src/reminders.cpp b/plugins/NotesAndReminders/src/reminders.cpp index 1b6b8854cc..e15415e8c4 100644 --- a/plugins/NotesAndReminders/src/reminders.cpp +++ b/plugins/NotesAndReminders/src/reminders.cpp @@ -1938,7 +1938,7 @@ INT_PTR OpenTriggeredReminder(WPARAM, LPARAM l) pReminder->RemVisible = TRUE; - HWND H = CreateDialog(hinstance, MAKEINTRESOURCE(IDD_NOTIFYREMINDER), nullptr, DlgProcNotifyReminder); + HWND H = CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_NOTIFYREMINDER), nullptr, DlgProcNotifyReminder); pReminder->handle = H; mir_snprintf(S2, "%s! - %s", Translate("Reminder"), S1); @@ -1957,7 +1957,7 @@ void NewReminder(void) { if (!NewReminderVisible) { NewReminderVisible = TRUE; - CreateDialog(hinstance, MAKEINTRESOURCE(IDD_ADDREMINDER), nullptr, DlgProcNewReminder); + CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_ADDREMINDER), nullptr, DlgProcNewReminder); } } @@ -1971,7 +1971,7 @@ void EditReminder(REMINDERDATA *p) p->RemVisible = TRUE; NewReminderVisible = 2; pEditReminder = p; - CreateDialog(hinstance, MAKEINTRESOURCE(IDD_ADDREMINDER), nullptr, DlgProcNewReminder); + CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_ADDREMINDER), nullptr, DlgProcNewReminder); } else { BringWindowToTop(p->handle); @@ -2087,7 +2087,7 @@ static BOOL DoListContextMenu(HWND AhWnd, WPARAM wParam, LPARAM lParam, REMINDER { HWND hwndListView = (HWND)wParam; if (hwndListView != GetDlgItem(AhWnd, IDC_LISTREMINDERS)) return FALSE; - HMENU hMenuLoad = LoadMenu(hinstance, "MNU_REMINDERPOPUP"); + HMENU hMenuLoad = LoadMenu(g_plugin.getInst(), "MNU_REMINDERPOPUP"); HMENU FhMenu = GetSubMenu(hMenuLoad, 0); MENUITEMINFO mii = { 0 }; @@ -2284,7 +2284,7 @@ static INT_PTR CALLBACK DlgProcViewReminders(HWND Dialog, UINT Message, WPARAM w void ListReminders(void) { if (!ListReminderVisible) { - CreateDialog(hinstance, MAKEINTRESOURCE(IDD_LISTREMINDERS), nullptr, DlgProcViewReminders); + CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_LISTREMINDERS), nullptr, DlgProcViewReminders); ListReminderVisible = TRUE; } else { diff --git a/plugins/NotifyAnything/src/main.cpp b/plugins/NotifyAnything/src/main.cpp index 2cef244540..a08a7d7dce 100644 --- a/plugins/NotifyAnything/src/main.cpp +++ b/plugins/NotifyAnything/src/main.cpp @@ -24,10 +24,13 @@ volatile bool g_exit_threads, g_firstrun; std::wstring g_mirandaDir; mir_cs g_wsocklock; -HINSTANCE hInst; +CMPlugin g_plugin; int hLangpack; -PLUGININFOEX pluginInfo = { +///////////////////////////////////////////////////////////////////////////////////////// + +PLUGININFOEX pluginInfo = +{ sizeof(PLUGININFOEX), __PLUGIN_NAME, PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), @@ -40,13 +43,13 @@ PLUGININFOEX pluginInfo = { { 0xe92874ec, 0x594a, 0x4a2f, { 0xbd, 0xed, 0xc0, 0xbe, 0x8b, 0x5a, 0x45, 0xd1 } } }; -BOOL WINAPI DllMain(HINSTANCE hi, DWORD, LPVOID) +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) { - hInst = hi; - DisableThreadLibraryCalls(hInst); - return TRUE; + return &pluginInfo; } +///////////////////////////////////////////////////////////////////////////////////////// + enum replace_mode_t { xno, xappend, @@ -962,10 +965,7 @@ void stop_threads() WaitForSingleObject(g_tcp_thread, INFINITE); } -extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) -{ - return &pluginInfo; -} +///////////////////////////////////////////////////////////////////////////////////////// extern "C" int __declspec(dllexport) Load() { @@ -988,6 +988,8 @@ extern "C" int __declspec(dllexport) Load() return 0; } +///////////////////////////////////////////////////////////////////////////////////////// + extern "C" int __declspec(dllexport) Unload(void) { stop_threads(); diff --git a/plugins/NotifyAnything/src/options.cpp b/plugins/NotifyAnything/src/options.cpp index abeea38393..41e983dcba 100644 --- a/plugins/NotifyAnything/src/options.cpp +++ b/plugins/NotifyAnything/src/options.cpp @@ -177,7 +177,7 @@ int OptionsInitialize(WPARAM wParam, LPARAM) odp.szTitle.a = LPGEN("Notify Anything"); odp.szGroup.a = LPGEN("Plugins"); odp.position = 100000000; - odp.hInstance = hInst; + odp.hInstance = g_plugin.getInst(); odp.flags = ODPF_BOLDGROUPS; Options_AddPage(wParam, &odp); return 0; diff --git a/plugins/NotifyAnything/src/stdafx.h b/plugins/NotifyAnything/src/stdafx.h index 730eaecb78..1eaf2a7da5 100644 --- a/plugins/NotifyAnything/src/stdafx.h +++ b/plugins/NotifyAnything/src/stdafx.h @@ -11,7 +11,6 @@ #include #include -#define __NO_CMPLUGIN_NEEDED #include "newpluginapi.h" #include "m_options.h" #include "m_skin.h" @@ -22,10 +21,15 @@ #include "resource.h" #include "version.h" -extern HINSTANCE hInst; - const char PlugName[] = "NotifyAnything"; +struct CMPlugin : public PLUGIN +{ + CMPlugin() : + PLUGIN(PlugName) + {} +}; + //--------------------------- //---Internal Hooks (see main.c) //---(Workaround till CallServiceSync is available) diff --git a/plugins/Nudge/src/main.cpp b/plugins/Nudge/src/main.cpp index 25ab897289..f7a0c6e189 100644 --- a/plugins/Nudge/src/main.cpp +++ b/plugins/Nudge/src/main.cpp @@ -2,7 +2,6 @@ int nProtocol = 0; static HANDLE hPopupClass; -HINSTANCE hInst; HGENMENU g_hContactMenu; OBJLIST arNudges(5); @@ -12,11 +11,17 @@ CNudge GlobalNudge; CLIST_INTERFACE *pcli; int hLangpack = 0; +CMPlugin g_plugin; -//======================== -// MirandaPluginInfo -//======================== -PLUGININFOEX pluginInfo = { +static IconItem iconList[] = +{ + { LPGEN("Nudge as Default"), "Nudge_Default", IDI_NUDGE } +}; + +///////////////////////////////////////////////////////////////////////////////////////// + +PLUGININFOEX pluginInfo = +{ sizeof(PLUGININFOEX), __PLUGIN_NAME, PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), @@ -29,7 +34,14 @@ PLUGININFOEX pluginInfo = { { 0xe47cc215, 0xd28, 0x462d, { 0xa0, 0xf6, 0x3a, 0xe4, 0x44, 0x3d, 0x29, 0x26 } } }; -INT_PTR NudgeShowMenu(WPARAM wParam, LPARAM lParam) +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) +{ + return &pluginInfo; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +static INT_PTR NudgeShowMenu(WPARAM wParam, LPARAM lParam) { bool bEnabled = false; for (auto &p : arNudges) @@ -42,7 +54,7 @@ INT_PTR NudgeShowMenu(WPARAM wParam, LPARAM lParam) return 0; } -INT_PTR NudgeSend(WPARAM hContact, LPARAM lParam) +static INT_PTR NudgeSend(WPARAM hContact, LPARAM lParam) { char *protoName = GetContactProto(hContact); int diff = time(0) - db_get_dw(hContact, "Nudge", "LastSent", time(0) - 30); @@ -81,7 +93,7 @@ void OpenContactList() ShowWindow(hWnd, SW_SHOW); } -int NudgeReceived(WPARAM hContact, LPARAM lParam) +static int NudgeReceived(WPARAM hContact, LPARAM lParam) { char *protoName = GetContactProto(hContact); @@ -186,175 +198,7 @@ int NudgeReceived(WPARAM hContact, LPARAM lParam) return 0; } -extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID) -{ - hInst = hinstDLL; - return TRUE; -} - -extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) -{ - return &pluginInfo; -} - -void LoadProtocols(void) -{ - //Load the default nudge - mir_snprintf(DefaultNudge.ProtocolName, "Default"); - mir_snprintf(DefaultNudge.NudgeSoundname, "Nudge : Default"); - Skin_AddSound(DefaultNudge.NudgeSoundname, LPGENW("Nudge"), LPGENW("Default Nudge")); - DefaultNudge.Load(); - - GlobalNudge.Load(); - - for (auto &pa : Accounts()) - Nudge_AddAccount(pa); - - shake.Load(); -} - -static IconItem iconList[] = -{ - { LPGEN("Nudge as Default"), "Nudge_Default", IDI_NUDGE } -}; - -// Load icons -void LoadIcons(void) -{ - Icon_Register(hInst, LPGEN("Nudge"), iconList, _countof(iconList)); -} - -// Nudge support -static int TabsrmmButtonPressed(WPARAM wParam, LPARAM lParam) -{ - CustomButtonClickData *cbcd = (CustomButtonClickData *)lParam; - - if (!mir_strcmp(cbcd->pszModule, "Nudge")) - NudgeSend(wParam, 0); - - return 0; -} - -static int TabsrmmButtonInit(WPARAM, LPARAM) -{ - HOTKEYDESC hkd = { "srmm_nudge", LPGEN("Send nudge"), BB_HK_SECTION, nullptr, HOTKEYCODE(HOTKEYF_CONTROL, 'N'), LPARAM(hInst) }; - Hotkey_Register(&hkd); - - BBButton bbd = {}; - bbd.pszModuleName = "Nudge"; - bbd.pwszTooltip = LPGENW("Send nudge"); - bbd.dwDefPos = 300; - bbd.bbbFlags = BBBF_ISIMBUTTON | BBBF_CANBEHIDDEN; - bbd.hIcon = iconList[0].hIcolib; - bbd.dwButtonID = 6000; - bbd.pszHotkey = hkd.pszName; - Srmm_AddButton(&bbd); - return 0; -} - -void HideNudgeButton(MCONTACT hContact) -{ - char *szProto = GetContactProto(hContact); - if (!ProtoServiceExists(szProto, PS_SEND_NUDGE)) { - BBButton bbd = {}; - bbd.pszModuleName = "Nudge"; - bbd.dwButtonID = 6000; - bbd.bbbFlags = BBSF_HIDDEN | BBSF_DISABLED; - Srmm_SetButtonState(hContact, &bbd); - } -} - -static int ContactWindowOpen(WPARAM, LPARAM lParam) -{ - MessageWindowEventData *MWeventdata = (MessageWindowEventData*)lParam; - if (MWeventdata->uType == MSG_WINDOW_EVT_OPENING && MWeventdata->hContact) - HideNudgeButton(MWeventdata->hContact); - - return 0; -} - -static int PrebuildContactMenu(WPARAM hContact, LPARAM) -{ - char *szProto = GetContactProto(hContact); - if (szProto != nullptr) { - bool isChat = db_get_b(hContact, szProto, "ChatRoom", false) != 0; - NudgeShowMenu((WPARAM)szProto, !isChat); - } - - return 0; -} - -int ModulesLoaded(WPARAM, LPARAM) -{ - LoadProtocols(); - LoadPopupClass(); - - HookEvent(ME_CLIST_PREBUILDCONTACTMENU, PrebuildContactMenu); - - HookTemporaryEvent(ME_MSG_TOOLBARLOADED, TabsrmmButtonInit); - HookEvent(ME_MSG_BUTTONPRESSED, TabsrmmButtonPressed); - HookEvent(ME_MSG_WINDOWEVENT, ContactWindowOpen); - return 0; -} - -int AccListChanged(WPARAM wParam, LPARAM lParam) -{ - PROTOACCOUNT *proto = (PROTOACCOUNT*)wParam; - if (proto == nullptr) - return 0; - - if (lParam == PRAC_ADDED) - Nudge_AddAccount(proto); - return 0; -} - -extern "C" int __declspec(dllexport) Load(void) -{ - mir_getLP(&pluginInfo); - pcli = Clist_GetInterface(); - - LoadIcons(); - - HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded); - HookEvent(ME_PROTO_ACCLISTCHANGED, AccListChanged); - HookEvent(ME_OPT_INITIALISE, NudgeOptInit); - - // Create function for plugins - CreateServiceFunction(MS_SHAKE_CLIST, ShakeClist); - CreateServiceFunction(MS_SHAKE_CHAT, ShakeChat); - CreateServiceFunction(MS_NUDGE_SEND, NudgeSend); - CreateServiceFunction(MS_NUDGE_SHOWMENU, NudgeShowMenu); - - // Add contact menu entry - CMenuItem mi; - SET_UID(mi, 0xd617db26, 0x22ba, 0x4205, 0x9c, 0x3e, 0x53, 0x10, 0xbc, 0xcf, 0xce, 0x19); - mi.flags = CMIF_NOTOFFLINE | CMIF_UNICODE; - mi.position = -500050004; - mi.hIcolibItem = iconList[0].hIcolib; - mi.name.w = LPGENW("Send &nudge"); - mi.pszService = MS_NUDGE_SEND; - g_hContactMenu = Menu_AddContactMenuItem(&mi); - - // register special type of event - // there's no need to declare the special service for getting text - // because a blob contains only text - DBEVENTTYPEDESCR evtype = { sizeof(evtype) }; - evtype.module = MODULENAME; - evtype.eventType = 1; - evtype.descr = LPGEN("Nudge"); - evtype.eventIcon = iconList[0].hIcolib; - evtype.flags = DETF_HISTORY | DETF_MSGWINDOW; - DbEvent_RegisterType(&evtype); - return 0; -} - -extern "C" int __declspec(dllexport) Unload(void) -{ - arNudges.destroy(); - return 0; -} - -LRESULT CALLBACK NudgePopupProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +static LRESULT CALLBACK NudgePopupProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_COMMAND: @@ -523,3 +367,159 @@ void AutoResendNudge(void *wParam) Sleep(GlobalNudge.resendDelaySec * 1000); NudgeSend((WPARAM)wParam, NULL); } + +static void LoadProtocols(void) +{ + // Load the default nudge + mir_snprintf(DefaultNudge.ProtocolName, "Default"); + mir_snprintf(DefaultNudge.NudgeSoundname, "Nudge : Default"); + Skin_AddSound(DefaultNudge.NudgeSoundname, LPGENW("Nudge"), LPGENW("Default Nudge")); + DefaultNudge.Load(); + + GlobalNudge.Load(); + + for (auto &pa : Accounts()) + Nudge_AddAccount(pa); + + shake.Load(); +} + +// Load icons +void LoadIcons(void) +{ + Icon_Register(g_plugin.getInst(), LPGEN("Nudge"), iconList, _countof(iconList)); +} + +// Nudge support +static int TabsrmmButtonPressed(WPARAM wParam, LPARAM lParam) +{ + CustomButtonClickData *cbcd = (CustomButtonClickData *)lParam; + + if (!mir_strcmp(cbcd->pszModule, "Nudge")) + NudgeSend(wParam, 0); + + return 0; +} + +static int TabsrmmButtonInit(WPARAM, LPARAM) +{ + HOTKEYDESC hkd = { "srmm_nudge", LPGEN("Send nudge"), BB_HK_SECTION, nullptr, HOTKEYCODE(HOTKEYF_CONTROL, 'N'), LPARAM(g_plugin.getInst()) }; + Hotkey_Register(&hkd); + + BBButton bbd = {}; + bbd.pszModuleName = "Nudge"; + bbd.pwszTooltip = LPGENW("Send nudge"); + bbd.dwDefPos = 300; + bbd.bbbFlags = BBBF_ISIMBUTTON | BBBF_CANBEHIDDEN; + bbd.hIcon = iconList[0].hIcolib; + bbd.dwButtonID = 6000; + bbd.pszHotkey = hkd.pszName; + Srmm_AddButton(&bbd); + return 0; +} + +void HideNudgeButton(MCONTACT hContact) +{ + char *szProto = GetContactProto(hContact); + if (!ProtoServiceExists(szProto, PS_SEND_NUDGE)) { + BBButton bbd = {}; + bbd.pszModuleName = "Nudge"; + bbd.dwButtonID = 6000; + bbd.bbbFlags = BBSF_HIDDEN | BBSF_DISABLED; + Srmm_SetButtonState(hContact, &bbd); + } +} + +static int ContactWindowOpen(WPARAM, LPARAM lParam) +{ + MessageWindowEventData *MWeventdata = (MessageWindowEventData*)lParam; + if (MWeventdata->uType == MSG_WINDOW_EVT_OPENING && MWeventdata->hContact) + HideNudgeButton(MWeventdata->hContact); + + return 0; +} + +static int PrebuildContactMenu(WPARAM hContact, LPARAM) +{ + char *szProto = GetContactProto(hContact); + if (szProto != nullptr) { + bool isChat = db_get_b(hContact, szProto, "ChatRoom", false) != 0; + NudgeShowMenu((WPARAM)szProto, !isChat); + } + + return 0; +} + +static int ModulesLoaded(WPARAM, LPARAM) +{ + LoadProtocols(); + LoadPopupClass(); + + HookEvent(ME_CLIST_PREBUILDCONTACTMENU, PrebuildContactMenu); + + HookTemporaryEvent(ME_MSG_TOOLBARLOADED, TabsrmmButtonInit); + HookEvent(ME_MSG_BUTTONPRESSED, TabsrmmButtonPressed); + HookEvent(ME_MSG_WINDOWEVENT, ContactWindowOpen); + return 0; +} + +static int AccListChanged(WPARAM wParam, LPARAM lParam) +{ + PROTOACCOUNT *proto = (PROTOACCOUNT*)wParam; + if (proto == nullptr) + return 0; + + if (lParam == PRAC_ADDED) + Nudge_AddAccount(proto); + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +extern "C" int __declspec(dllexport) Load(void) +{ + mir_getLP(&pluginInfo); + pcli = Clist_GetInterface(); + + LoadIcons(); + + HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded); + HookEvent(ME_PROTO_ACCLISTCHANGED, AccListChanged); + HookEvent(ME_OPT_INITIALISE, NudgeOptInit); + + // Create function for plugins + CreateServiceFunction(MS_SHAKE_CLIST, ShakeClist); + CreateServiceFunction(MS_SHAKE_CHAT, ShakeChat); + CreateServiceFunction(MS_NUDGE_SEND, NudgeSend); + CreateServiceFunction(MS_NUDGE_SHOWMENU, NudgeShowMenu); + + // Add contact menu entry + CMenuItem mi; + SET_UID(mi, 0xd617db26, 0x22ba, 0x4205, 0x9c, 0x3e, 0x53, 0x10, 0xbc, 0xcf, 0xce, 0x19); + mi.flags = CMIF_NOTOFFLINE | CMIF_UNICODE; + mi.position = -500050004; + mi.hIcolibItem = iconList[0].hIcolib; + mi.name.w = LPGENW("Send &nudge"); + mi.pszService = MS_NUDGE_SEND; + g_hContactMenu = Menu_AddContactMenuItem(&mi); + + // register special type of event + // there's no need to declare the special service for getting text + // because a blob contains only text + DBEVENTTYPEDESCR evtype = { sizeof(evtype) }; + evtype.module = MODULENAME; + evtype.eventType = 1; + evtype.descr = LPGEN("Nudge"); + evtype.eventIcon = iconList[0].hIcolib; + evtype.flags = DETF_HISTORY | DETF_MSGWINDOW; + DbEvent_RegisterType(&evtype); + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +extern "C" int __declspec(dllexport) Unload(void) +{ + arNudges.destroy(); + return 0; +} diff --git a/plugins/Nudge/src/options.cpp b/plugins/Nudge/src/options.cpp index c72e07390c..3d1c77c654 100644 --- a/plugins/Nudge/src/options.cpp +++ b/plugins/Nudge/src/options.cpp @@ -213,7 +213,7 @@ static void CreateImageList(HWND hWnd) ImageList_AddIcon(hImList, hIcon); } //ADD default Icon for nudge - HICON hIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_NUDGE), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0); + HICON hIcon = (HICON)LoadImage(g_plugin.getInst(), MAKEINTRESOURCE(IDI_NUDGE), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0); ImageList_AddIcon(hImList, hIcon); DestroyIcon(hIcon); @@ -374,7 +374,7 @@ int NudgeOptInit(WPARAM wParam, LPARAM) { OPTIONSDIALOGPAGE odp = { 0 }; odp.position = -790000000; - odp.hInstance = hInst; + odp.hInstance = g_plugin.getInst(); odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_NUDGE); odp.szTitle.a = LPGEN("Nudge"); odp.szGroup.a = LPGEN("Events"); diff --git a/plugins/Nudge/src/stdafx.h b/plugins/Nudge/src/stdafx.h index a1acd929d2..3c32e9a31c 100644 --- a/plugins/Nudge/src/stdafx.h +++ b/plugins/Nudge/src/stdafx.h @@ -9,7 +9,6 @@ #include #include -#define __NO_CMPLUGIN_NEEDED #include #include #include @@ -75,7 +74,13 @@ void AutoResendNudge(void *wParam) ; /////////////////////////////////////////////////////////////////////////////// // external variables -extern HINSTANCE hInst; +struct CMPlugin : public PLUGIN +{ + CMPlugin() : + PLUGIN(MODULENAME) + {} +}; + extern int nProtocol; extern CShake shake; extern CNudge GlobalNudge; -- cgit v1.2.3