From 754665d1ae053678088144bb833bda76a0d95794 Mon Sep 17 00:00:00 2001
From: Mataes <mataes2007@gmail.com>
Date: Thu, 17 May 2018 20:57:34 +0300
Subject: KeyboardNotify, ListeningTO, MagneticWindows, MenuItemEx: cmplugin
 adaptation

---
 plugins/MagneticWindows/src/MagneticWindows.cpp | 43 +++++++++----------------
 plugins/MagneticWindows/src/Options.cpp         | 20 ++++++------
 plugins/MagneticWindows/src/stdafx.h            | 18 +++++++----
 3 files changed, 37 insertions(+), 44 deletions(-)

(limited to 'plugins/MagneticWindows')

diff --git a/plugins/MagneticWindows/src/MagneticWindows.cpp b/plugins/MagneticWindows/src/MagneticWindows.cpp
index c7f2d7f986..c244dd19b5 100644
--- a/plugins/MagneticWindows/src/MagneticWindows.cpp
+++ b/plugins/MagneticWindows/src/MagneticWindows.cpp
@@ -27,10 +27,10 @@ PLUGININFOEX pluginInfo = {
 	__AUTHORWEB,
 	UNICODE_AWARE,
 	// {08C01613-24C8-486F-BDAE-2C3DDCAF9347}
-	{0x8c01613, 0x24c8, 0x486f, { 0xbd, 0xae, 0x2c, 0x3d, 0xdc, 0xaf, 0x93, 0x47 }} 
+	{0x8c01613, 0x24c8, 0x486f, { 0xbd, 0xae, 0x2c, 0x3d, 0xdc, 0xaf, 0x93, 0x47 }}
 };
 
-HINSTANCE hInst;
+CMPlugin g_plugin;
 int hLangpack;
 CLIST_INTERFACE *pcli;
 
@@ -55,21 +55,21 @@ INT_PTR SnapPluginWindowStop(WPARAM wParam, LPARAM)
 
 int PluginMessageWindowEvent(WPARAM, LPARAM lParam)
 {
-	MessageWindowEventData *Data = (MessageWindowEventData*) lParam;
-	
+	MessageWindowEventData *Data = (MessageWindowEventData*)lParam;
+
 	switch (Data->uType) {
-	case MSG_WINDOW_EVT_OPEN: 
-		{
-			HWND hWnd = Data->hwndWindow;
-			HWND hWndParent = GetParent(hWnd);
-			while ((hWndParent != 0) && (hWndParent != GetDesktopWindow()) && (IsWindowVisible(hWndParent))) {			
-				hWnd = hWndParent;
-				hWndParent = GetParent(hWnd);			
-			}
-
-			WindowOpen(hWnd);
+	case MSG_WINDOW_EVT_OPEN:
+	{
+		HWND hWnd = Data->hwndWindow;
+		HWND hWndParent = GetParent(hWnd);
+		while ((hWndParent != 0) && (hWndParent != GetDesktopWindow()) && (IsWindowVisible(hWndParent))) {
+			hWnd = hWndParent;
+			hWndParent = GetParent(hWnd);
 		}
-		break;
+
+		WindowOpen(hWnd);
+	}
+	break;
 
 	case MSG_WINDOW_EVT_CLOSING:
 		WindowClose(Data->hwndWindow);
@@ -114,7 +114,7 @@ extern "C" int __declspec(dllexport) Load()
 {
 	mir_getLP(&pluginInfo);
 	pcli = Clist_GetInterface();
-	
+
 	HookEvent(ME_SYSTEM_MODULESLOADED, SnapPluginStart);
 	HookEvent(ME_SYSTEM_PRESHUTDOWN, SnapPluginShutDown);
 	HookEvent(ME_OPT_INITIALISE, InitOptions);
@@ -131,14 +131,3 @@ extern "C" int __declspec(dllexport) Unload()
 {
 	return 0;
 }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// DLL MAIN
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-
-BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID)
-{
-	hInst = hinstDLL;
-	return TRUE;
-}
diff --git a/plugins/MagneticWindows/src/Options.cpp b/plugins/MagneticWindows/src/Options.cpp
index 2c9de31cf1..650948fda6 100644
--- a/plugins/MagneticWindows/src/Options.cpp
+++ b/plugins/MagneticWindows/src/Options.cpp
@@ -14,8 +14,8 @@ INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
 	case WM_INITDIALOG:
 		TranslateDialogDefault(hwndDlg);
 
-		CheckDlgButton(hwndDlg, IDC_CHK_SNAP, Options.DoSnap?BST_CHECKED:BST_UNCHECKED);
-		SendDlgItemMessage(hwndDlg, IDC_SLIDER_SNAPWIDTH, TBM_SETRANGE, FALSE, MAKELONG(1,32));
+		CheckDlgButton(hwndDlg, IDC_CHK_SNAP, Options.DoSnap ? BST_CHECKED : BST_UNCHECKED);
+		SendDlgItemMessage(hwndDlg, IDC_SLIDER_SNAPWIDTH, TBM_SETRANGE, FALSE, MAKELONG(1, 32));
 		SendDlgItemMessage(hwndDlg, IDC_SLIDER_SNAPWIDTH, TBM_SETPOS, TRUE, Options.SnapWidth);
 
 		mir_snwprintf(str, TranslateT("%d pix"), Options.SnapWidth);
@@ -24,8 +24,8 @@ INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
 		EnableWindow(GetDlgItem(hwndDlg, IDC_SLIDER_SNAPWIDTH), Options.DoSnap);
 		EnableWindow(GetDlgItem(hwndDlg, IDC_TXT_SNAPWIDTH), Options.DoSnap);
 
-		CheckDlgButton(hwndDlg, IDC_CHK_SCRIVERWORKAROUND, Options.ScriverWorkAround?BST_CHECKED:BST_UNCHECKED);
-		break;		
+		CheckDlgButton(hwndDlg, IDC_CHK_SCRIVERWORKAROUND, Options.ScriverWorkAround ? BST_CHECKED : BST_UNCHECKED);
+		break;
 
 	case WM_HSCROLL:
 		mir_snwprintf(str, TranslateT("%d pix"), SendDlgItemMessage(hwndDlg, IDC_SLIDER_SNAPWIDTH, TBM_GETPOS, 0, 0));
@@ -34,7 +34,7 @@ INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
 		break;
 
 	case WM_COMMAND:
-		switch( LOWORD(wParam)) {
+		switch (LOWORD(wParam)) {
 		case IDC_CHK_SNAP:
 			if (HIWORD(wParam) == BN_CLICKED) {
 				EnableWindow(GetDlgItem(hwndDlg, IDC_SLIDER_SNAPWIDTH), IsDlgButtonChecked(hwndDlg, IDC_CHK_SNAP));
@@ -52,10 +52,10 @@ INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
 		break;
 
 	case WM_NOTIFY:  //Here we have pressed either the OK or the APPLY button.
-		switch(((LPNMHDR)lParam)->idFrom) {
+		switch (((LPNMHDR)lParam)->idFrom) {
 		case 0:
 			switch (((LPNMHDR)lParam)->code) {
-			case PSN_RESET:							
+			case PSN_RESET:
 				LoadOptions();
 				break;
 
@@ -68,8 +68,8 @@ INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
 				db_set_b(NULL, MODULE_NAME, "SnapWidth", Options.SnapWidth);
 				db_set_b(NULL, MODULE_NAME, "ScriverWorkAround", Options.ScriverWorkAround);
 				break;
-			} 
-		} 
+			}
+		}
 		break;
 	}
 	return 0;
@@ -80,7 +80,7 @@ int InitOptions(WPARAM wParam, LPARAM)
 	OPTIONSDIALOGPAGE Opt = { sizeof(Opt) };
 	Opt.pfnDlgProc = OptionsDlgProc;
 	Opt.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_MAGNETICWINDOWS);
-	Opt.hInstance = hInst;
+	Opt.hInstance = g_plugin.getInst();
 	Opt.szGroup.a = LPGEN("Customize");
 	Opt.szTitle.a = LPGEN("Magnetic Windows");
 	Opt.flags = ODPF_BOLDGROUPS;
diff --git a/plugins/MagneticWindows/src/stdafx.h b/plugins/MagneticWindows/src/stdafx.h
index 2ca9697411..ba6c7229ce 100644
--- a/plugins/MagneticWindows/src/stdafx.h
+++ b/plugins/MagneticWindows/src/stdafx.h
@@ -2,8 +2,6 @@
 #include <commctrl.h>
 #include <stdio.h>
 
-#define __NO_CMPLUGIN_NEEDED
-
 #include <newpluginapi.h>
 #include <m_clistint.h>
 #include <m_message.h>
@@ -20,15 +18,21 @@
 #include "Version.h"
 
 typedef
-	struct {
-		int MouseX, MouseY;
-		bool SnappedX, SnappedY;
-	} TWorkingVariables;
+struct {
+	int MouseX, MouseY;
+	bool SnappedX, SnappedY;
+} TWorkingVariables;
 
 
 
 #define MODULE_NAME "MagneticWindows"
-extern HINSTANCE hInst;
+
+struct CMPlugin : public PLUGIN<CMPlugin>
+{
+	CMPlugin() :
+		PLUGIN<CMPlugin>(MODULE_NAME)
+	{}
+};
 
 void WindowStart();
 bool WindowOpen(HWND);
-- 
cgit v1.2.3