summaryrefslogtreecommitdiff
path: root/plugins/MsgPopup
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-12-03 13:42:46 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-12-03 13:42:46 +0000
commit5a8c0ced3f1fd3e523512696b615174e3a074d6e (patch)
treed70de01d710fbccedfd9d3e86da81d196f3dafd8 /plugins/MsgPopup
parent49eb819ca5e9a4824b437813a11900b780bd8102 (diff)
adaptation for 64 bits
git-svn-id: http://svn.miranda-ng.org/main/trunk@11229 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MsgPopup')
-rw-r--r--plugins/MsgPopup/src/Version.h16
-rw-r--r--plugins/MsgPopup/src/main.cpp180
-rw-r--r--plugins/MsgPopup/src/options.cpp150
3 files changed, 154 insertions, 192 deletions
diff --git a/plugins/MsgPopup/src/Version.h b/plugins/MsgPopup/src/Version.h
index c241a6e827..e2b52c3a6c 100644
--- a/plugins/MsgPopup/src/Version.h
+++ b/plugins/MsgPopup/src/Version.h
@@ -1,14 +1,14 @@
-#define __MAJOR_VERSION 0
-#define __MINOR_VERSION 1
-#define __RELEASE_NUM 1
-#define __BUILD_NUM 3
+#define __MAJOR_VERSION 0
+#define __MINOR_VERSION 1
+#define __RELEASE_NUM 2
+#define __BUILD_NUM 1
#include <stdver.h>
#define __PLUGIN_NAME "Message popup"
#define __FILENAME "MsgPopup.dll"
-#define __DESCRIPTION "Plugin replaces message boxes (those having only OK button) with popups."
-#define __AUTHOR "StDenis"
+#define __DESCRIPTION "Plugin replaces message boxes (those having only OK button) with popups."
+#define __AUTHOR "StDenis"
#define __AUTHOREMAIL "stdenformiranda@fromru.com"
-#define __AUTHORWEB "http://miranda-ng.org/p/MsgPopup/"
-#define __COPYRIGHT "© 2004 Denis Stanishevskiy"
+#define __AUTHORWEB "http://miranda-ng.org/p/MsgPopup/"
+#define __COPYRIGHT "© 2004 Denis Stanishevskiy"
diff --git a/plugins/MsgPopup/src/main.cpp b/plugins/MsgPopup/src/main.cpp
index ce936d1c61..f372f30eeb 100644
--- a/plugins/MsgPopup/src/main.cpp
+++ b/plugins/MsgPopup/src/main.cpp
@@ -19,6 +19,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+
#include "common.h"
HINSTANCE hInst;
@@ -58,39 +59,38 @@ MSGBOXPROC prevMessageBox;
void popupMessage(LPCTSTR lpText, LPCTSTR lpCaption, UINT uType)
{
- POPUPDATAT ppd = {0};
+ POPUPDATAT ppd = { 0 };
int iIcon;
int indx;
- switch(uType & 0xF0)
- {
- case MB_ICONHAND:
- indx = 1;
- iIcon = OIC_HAND;
- break;
- case MB_ICONEXCLAMATION:
- indx = 2;
- iIcon = OIC_BANG;
- break;
- case MB_ICONQUESTION:
- indx = 3;
- iIcon = OIC_QUES;
- break;
- default:
- indx = 0;
- iIcon = OIC_NOTE;
- break;
-
+ switch (uType & 0xF0) {
+ case MB_ICONHAND:
+ indx = 1;
+ iIcon = OIC_HAND;
+ break;
+ case MB_ICONEXCLAMATION:
+ indx = 2;
+ iIcon = OIC_BANG;
+ break;
+ case MB_ICONQUESTION:
+ indx = 3;
+ iIcon = OIC_QUES;
+ break;
+ default:
+ indx = 0;
+ iIcon = OIC_NOTE;
+ break;
+
}
ppd.colorBack = options.BG[indx];
ppd.colorText = options.FG[indx];
- ppd.iSeconds = options.Timeout[indx];
+ ppd.iSeconds = options.Timeout[indx];
ppd.lchIcon = (HICON)LoadImage(NULL, MAKEINTRESOURCE(iIcon), IMAGE_ICON, SM_CXSMICON, SM_CYSMICON, LR_SHARED);
mir_tstrcpy(ppd.lptzContactName, lpCaption);
mir_tstrcpy(ppd.lptzText, lpText);
PUAddPopupT(&ppd);
- if(options.Sound)
+ if (options.Sound)
MessageBeep(uType);
}
@@ -99,62 +99,51 @@ int WINAPI newMessageBox(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uTyp
if (CallService(MS_POPUP_QUERY, PUQS_GETSTATUS, 0) == CALLSERVICE_NOTFOUND || (uType & 0x0F))
return prevMessageBox(hWnd, lpText, lpCaption, uType);
- popupMessage(lpText, lpCaption,uType);
+ popupMessage(lpText, lpCaption, uType);
return IDOK;
}
BOOL g_HookError = FALSE;
BOOL g_HookError2 = FALSE;
-int g_mod = 0;
+int g_mod = 0;
-void HookOnImport(HMODULE hModule, char *lpszImpModName, DWORD lpOrigFunc, DWORD lpNewFunc)
+void HookOnImport(HMODULE hModule, char *lpszImpModName, PVOID lpOrigFunc, PVOID lpNewFunc)
{
ULONG ulSize;
- PIMAGE_IMPORT_DESCRIPTOR pImportDesc = (PIMAGE_IMPORT_DESCRIPTOR) ImageDirectoryEntryToData(
- hModule,
- TRUE,
- IMAGE_DIRECTORY_ENTRY_IMPORT,
- &ulSize);
- if(pImportDesc == NULL) return;
-
- for(; pImportDesc->Name; pImportDesc++)
- {
+ PIMAGE_IMPORT_DESCRIPTOR pImportDesc = (PIMAGE_IMPORT_DESCRIPTOR)
+ ImageDirectoryEntryToData(hModule, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &ulSize);
+ if (pImportDesc == NULL)
+ return;
+
+ for (; pImportDesc->Name; pImportDesc++) {
char *pszModName = (char *)((PBYTE)hModule + pImportDesc->Name);
-
- if (mir_strcmpi(lpszImpModName, pszModName) == 0)
- {
- PIMAGE_THUNK_DATA pThunk = (PIMAGE_THUNK_DATA)((PBYTE)hModule + pImportDesc->FirstThunk);
-
- for (; pThunk->u1.Function; pThunk++)
- {
- DWORD* ppfn = (DWORD*) &pThunk->u1.Function;
-
- if(*ppfn == lpOrigFunc)
- {
- DWORD oldProtect;
-
- g_mod++;
-
- if(!VirtualProtect((LPVOID)ppfn, 4, PAGE_EXECUTE_READWRITE, &oldProtect))
- {
- if(!g_HookError)
- {
- TCHAR buf[200];
-
- g_HookError = TRUE;
- mir_sntprintf(buf, SIZEOF(buf), TranslateT("VirtualProtect failed. Code %d\nTry to call the author"), GetLastError());
- prevMessageBox(0, buf, TranslateT("Error"), MB_OK);
- }
- }
- *(DWORD*)ppfn = lpNewFunc;
- if(*(DWORD*)ppfn != lpNewFunc)
- {
- if(!g_HookError2)
- {
- g_HookError2 = TRUE;
- prevMessageBox(0, TranslateT("Hmm. Something goes wrong. I can't write into the memory.\nAnd as you can see, there are no any exception raised...\nTry to call the author"), TranslateT("Error"), MB_OK);
- }
- }
+ if (mir_strcmpi(lpszImpModName, pszModName) != 0)
+ continue;
+
+ PIMAGE_THUNK_DATA pThunk = (PIMAGE_THUNK_DATA)((PBYTE)hModule + pImportDesc->FirstThunk);
+ for (; pThunk->u1.Function; pThunk++) {
+ PVOID* ppfn = (PVOID*)&pThunk->u1.Function;
+ if (*ppfn != lpOrigFunc)
+ continue;
+
+ DWORD oldProtect;
+
+ g_mod++;
+
+ if (!VirtualProtect((LPVOID)ppfn, sizeof(void*), PAGE_EXECUTE_READWRITE, &oldProtect)) {
+ if (!g_HookError) {
+ TCHAR buf[200];
+
+ g_HookError = TRUE;
+ mir_sntprintf(buf, SIZEOF(buf), TranslateT("VirtualProtect failed. Code %d\nTry to call the author"), GetLastError());
+ prevMessageBox(0, buf, TranslateT("Error"), MB_OK);
+ }
+ }
+ *(PVOID*)ppfn = lpNewFunc;
+ if (*(PVOID*)ppfn != lpNewFunc) {
+ if (!g_HookError2) {
+ g_HookError2 = TRUE;
+ prevMessageBox(0, TranslateT("Hmm. Something goes wrong. I can't write into the memory.\nAnd as you can see, there are no any exception raised...\nTry to call the author"), TranslateT("Error"), MB_OK);
}
}
}
@@ -163,37 +152,31 @@ void HookOnImport(HMODULE hModule, char *lpszImpModName, DWORD lpOrigFunc, DWORD
void HookAPI()
{
- DWORD lpMessageBox = (DWORD)GetProcAddress(GetModuleHandle(_T("USER32.DLL")), "MessageBoxW");
- DWORD lpPopupMsgBox = (DWORD)newMessageBox;
+ PVOID lpMessageBox = (PVOID)GetProcAddress(GetModuleHandle(_T("USER32.DLL")), "MessageBoxW");
+ PVOID lpPopupMsgBox = (PVOID)newMessageBox;
prevMessageBox = (MSGBOXPROC)lpMessageBox;
- BOOL bFound = FALSE;
- HANDLE hModuleSnap = NULL;
- MODULEENTRY32 me32 = {0};
-
- hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId());
- if(hModuleSnap == INVALID_HANDLE_VALUE)
- return;
-
- me32.dwSize = sizeof(MODULEENTRY32);
- if(Module32First(hModuleSnap, &me32))
- {
- do
- {
- HookOnImport(me32.hModule, "USER32.DLL", lpMessageBox, lpPopupMsgBox);
- }
- while (!bFound && Module32Next(hModuleSnap, &me32));
- }
- CloseHandle (hModuleSnap);
+ HANDLE hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId());
+ if (hModuleSnap == INVALID_HANDLE_VALUE)
+ return;
- return;
+ MODULEENTRY32 me32 = { 0 };
+ me32.dwSize = sizeof(MODULEENTRY32);
+
+ BOOL bFound = FALSE;
+ if (Module32First(hModuleSnap, &me32)) {
+ do {
+ HookOnImport(me32.hModule, "USER32.DLL", lpMessageBox, lpPopupMsgBox);
+ }
+ while (!bFound && Module32Next(hModuleSnap, &me32));
+ }
+ CloseHandle(hModuleSnap);
}
int HookedInit(WPARAM wParam, LPARAM lParam)
{
HookAPI();
-
return 0;
}
@@ -214,13 +197,8 @@ int HookedOptions(WPARAM wParam, LPARAM lParam)
void LoadConfig()
{
- char szNameFG[4];
- char szNameBG[4];
- char szNameTO[4];
- int indx;
-
- for(indx = 0; indx < 4; indx++)
- {
+ for (int indx = 0; indx < 4; indx++) {
+ char szNameFG[4], szNameBG[4], szNameTO[4];
mir_snprintf(szNameFG, SIZEOF(szNameFG), "FG%d", indx);
mir_snprintf(szNameBG, SIZEOF(szNameBG), "BG%d", indx);
mir_snprintf(szNameTO, SIZEOF(szNameTO), "TO%d", indx);
@@ -228,17 +206,17 @@ void LoadConfig()
options.BG[indx] = db_get_dw(NULL, SERVICENAME, szNameBG, optionsDefault.BG[indx]);
options.Timeout[indx] = db_get_dw(NULL, SERVICENAME, szNameTO, (DWORD)optionsDefault.Timeout[indx]);
}
- options.Sound = db_get_b(NULL, SERVICENAME, "Sound", (DWORD)optionsDefault.Sound);
+ options.Sound = db_get_b(NULL, SERVICENAME, "Sound", (DWORD)optionsDefault.Sound);
}
+
extern "C" __declspec(dllexport) int Load(void)
{
mir_getLP(&pluginInfo);
HookEvent(ME_SYSTEM_MODULESLOADED, HookedInit);
- HookEvent(ME_OPT_INITIALISE, HookedOptions);
+ HookEvent(ME_OPT_INITIALISE, HookedOptions);
LoadConfig();
-
return 0;
}
diff --git a/plugins/MsgPopup/src/options.cpp b/plugins/MsgPopup/src/options.cpp
index 1921fce2f6..3fe5552085 100644
--- a/plugins/MsgPopup/src/options.cpp
+++ b/plugins/MsgPopup/src/options.cpp
@@ -22,15 +22,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "common.h"
int idOptionControls[4][3] = {
- IDC_ASTERISK_FG,IDC_ASTERISK_BG,IDC_TIMEOUT1,
- IDC_ERROR_FG,IDC_ERROR_BG,IDC_TIMEOUT2,
- IDC_EXCLAMATION_FG,IDC_EXCLAMATION_BG,IDC_TIMEOUT3,
- IDC_QUESTION_FG,IDC_QUESTION_BG,IDC_TIMEOUT4
+ IDC_ASTERISK_FG, IDC_ASTERISK_BG, IDC_TIMEOUT1,
+ IDC_ERROR_FG, IDC_ERROR_BG, IDC_TIMEOUT2,
+ IDC_EXCLAMATION_FG, IDC_EXCLAMATION_BG, IDC_TIMEOUT3,
+ IDC_QUESTION_FG, IDC_QUESTION_BG, IDC_TIMEOUT4
};
-static int __inline DBWriteContactSettingDwordDef(MCONTACT hContact,const char *szModule,const char *szSetting,DWORD val, DWORD defValue)
+static int __inline DBWriteContactSettingDwordDef(MCONTACT hContact, const char *szModule, const char *szSetting, DWORD val, DWORD defValue)
{
- if(val == db_get_dw(hContact, szModule, szSetting, defValue))
+ if (val == db_get_dw(hContact, szModule, szSetting, defValue))
return 0;
else
return db_set_dw(hContact, szModule, szSetting, val);
@@ -38,96 +38,80 @@ static int __inline DBWriteContactSettingDwordDef(MCONTACT hContact,const char *
INT_PTR CALLBACK OptionsDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
- switch (message)
- {
- case WM_INITDIALOG:
- {
- int indx;
+ switch (message) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hWnd);
+ for (int indx = 0; indx < 4; indx++) {
+ SendDlgItemMessage(hWnd, idOptionControls[indx][0], CPM_SETCOLOUR, 0, options.FG[indx]);
+ SendDlgItemMessage(hWnd, idOptionControls[indx][1], CPM_SETCOLOUR, 0, options.BG[indx]);
+ SetDlgItemInt(hWnd, idOptionControls[indx][2], options.Timeout[indx], TRUE);
+ }
+ CheckDlgButton(hWnd, IDC_MESSAGEBEEP, options.Sound ? BST_CHECKED : BST_UNCHECKED);
+ return TRUE;
- TranslateDialogDefault(hWnd);
- for(indx = 0; indx < 4; indx++)
- {
- SendDlgItemMessage(hWnd, idOptionControls[indx][0], CPM_SETCOLOUR, 0, options.FG[indx]);
- SendDlgItemMessage(hWnd, idOptionControls[indx][1], CPM_SETCOLOUR, 0, options.BG[indx]);
- SetDlgItemInt(hWnd, idOptionControls[indx][2], options.Timeout[indx], TRUE);
- }
- CheckDlgButton(hWnd, IDC_MESSAGEBEEP, options.Sound?BST_CHECKED:BST_UNCHECKED);
- return TRUE;
+ case WM_COMMAND:
+ int indx, value;
+ BOOL Translated;
+ if (LOWORD(wParam) == IDC_PREVIEW) {
+ MessageBox(0, TranslateT("Message with question"), TranslateTS(_T(SERVICENAME) _T(" - demo")), MB_ICONQUESTION);
+ MessageBox(0, TranslateT("Message with exclamation"), TranslateTS(_T(SERVICENAME) _T(" - demo")), MB_ICONEXCLAMATION);
+ MessageBox(0, TranslateT("Message with error"), TranslateTS(_T(SERVICENAME) _T(" - demo")), MB_ICONSTOP);
+ MessageBox(0, TranslateT("Message with asterisk"), TranslateTS(_T(SERVICENAME) _T(" - demo")), MB_ICONASTERISK);
+
+ return FALSE;
}
- case WM_COMMAND:
- {
- int indx, value;
- BOOL Translated;
- if(LOWORD(wParam) == IDC_PREVIEW)
- {
- MessageBox(0, TranslateT("Message with question"), TranslateTS(_T(SERVICENAME) _T(" - demo")), MB_ICONQUESTION);
- MessageBox(0, TranslateT("Message with exclamation"), TranslateTS(_T(SERVICENAME) _T(" - demo")), MB_ICONEXCLAMATION);
- MessageBox(0, TranslateT("Message with error"), TranslateTS(_T(SERVICENAME) _T(" - demo")), MB_ICONSTOP);
- MessageBox(0, TranslateT("Message with asterisk"), TranslateTS(_T(SERVICENAME) _T(" - demo")), MB_ICONASTERISK);
-
- return FALSE;
- }
- if(LOWORD(wParam) == IDC_MESSAGEBEEP)
- {
- options.Sound = IsDlgButtonChecked(hWnd, IDC_MESSAGEBEEP) == BST_CHECKED;
- }
- else
- for(indx = 0; indx < 4; indx++)
- {
- if(LOWORD(wParam) == idOptionControls[indx][0])
- {
- if(HIWORD(wParam) != CPN_COLOURCHANGED) return FALSE;
+
+ if (LOWORD(wParam) == IDC_MESSAGEBEEP)
+ options.Sound = IsDlgButtonChecked(hWnd, IDC_MESSAGEBEEP) == BST_CHECKED;
+ else {
+ for (indx = 0; indx < 4; indx++) {
+ if (LOWORD(wParam) == idOptionControls[indx][0]) {
+ if (HIWORD(wParam) != CPN_COLOURCHANGED) return FALSE;
options.FG[indx] = SendDlgItemMessage(hWnd, LOWORD(wParam), CPM_GETCOLOUR, 0, 0);
}
- else
- if(LOWORD(wParam) == idOptionControls[indx][1])
- {
- if(HIWORD(wParam) != CPN_COLOURCHANGED) return FALSE;
+ else if (LOWORD(wParam) == idOptionControls[indx][1]) {
+ if (HIWORD(wParam) != CPN_COLOURCHANGED) return FALSE;
options.BG[indx] = SendDlgItemMessage(hWnd, LOWORD(wParam), CPM_GETCOLOUR, 0, 0);
}
- else
- if(LOWORD(wParam) == idOptionControls[indx][2])
- {
- if(HIWORD(wParam) != EN_CHANGE) return FALSE;
- if((HWND)lParam != GetFocus()) return FALSE;
+ else if (LOWORD(wParam) == idOptionControls[indx][2]) {
+ if (HIWORD(wParam) != EN_CHANGE) return FALSE;
+ if ((HWND)lParam != GetFocus()) return FALSE;
value = (DWORD)GetDlgItemInt(hWnd, LOWORD(wParam), &Translated, TRUE);
- if(Translated) options.Timeout[indx] = value;
+ if (Translated)
+ options.Timeout[indx] = value;
}
}
- SendMessage(GetParent(hWnd), PSM_CHANGED, 0,0);
- break;
}
- case WM_NOTIFY:
- switch (((LPNMHDR)lParam)->code)
- {
- case PSN_RESET:
- LoadConfig();
- return FALSE;
-
- case PSN_APPLY:
- {
- char szNameFG[4];
- char szNameBG[4];
- char szNameTO[4];
- int indx;
-
- for(indx = 0; indx < 4; indx++)
- {
- mir_snprintf(szNameFG, SIZEOF(szNameFG), "FG%d", indx);
- mir_snprintf(szNameBG, SIZEOF(szNameBG), "BG%d", indx);
- mir_snprintf(szNameTO, SIZEOF(szNameTO), "TO%d", indx);
-
- DBWriteContactSettingDwordDef(NULL, SERVICENAME, szNameFG, options.FG[indx], optionsDefault.FG[indx]);
- DBWriteContactSettingDwordDef(NULL, SERVICENAME, szNameBG, options.BG[indx], optionsDefault.BG[indx]);
- DBWriteContactSettingDwordDef(NULL, SERVICENAME, szNameTO, options.Timeout[indx], (DWORD)optionsDefault.Timeout[indx]);
- }
- DBWriteContactSettingDwordDef(NULL,SERVICENAME,"Sound",options.Sound,optionsDefault.Sound);
-
- break;
- }
+ SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0);
+ break;
+
+ case WM_NOTIFY:
+ switch (((LPNMHDR)lParam)->code) {
+ case PSN_RESET:
+ LoadConfig();
+ return FALSE;
+
+ case PSN_APPLY:
+ char szNameFG[4];
+ char szNameBG[4];
+ char szNameTO[4];
+ int indx;
+
+ for (indx = 0; indx < 4; indx++) {
+ mir_snprintf(szNameFG, SIZEOF(szNameFG), "FG%d", indx);
+ mir_snprintf(szNameBG, SIZEOF(szNameBG), "BG%d", indx);
+ mir_snprintf(szNameTO, SIZEOF(szNameTO), "TO%d", indx);
+
+ DBWriteContactSettingDwordDef(NULL, SERVICENAME, szNameFG, options.FG[indx], optionsDefault.FG[indx]);
+ DBWriteContactSettingDwordDef(NULL, SERVICENAME, szNameBG, options.BG[indx], optionsDefault.BG[indx]);
+ DBWriteContactSettingDwordDef(NULL, SERVICENAME, szNameTO, options.Timeout[indx], (DWORD)optionsDefault.Timeout[indx]);
}
+ DBWriteContactSettingDwordDef(NULL, SERVICENAME, "Sound", options.Sound, optionsDefault.Sound);
+
break;
+ }
+ break;
}
return FALSE;
}