らんだむな記憶

blogというものを体験してみようか!的なー

はめきん(9)

ダメぽかったら一時的に情報をキャッシュして後から突っ込んだらいいかなと思ったけどダメぽい。うーん。

diff --git a/dll/winproc.cpp b/dll/winproc.cpp
index a168187..299685e 100644
--- a/dll/winproc.cpp
+++ b/dll/winproc.cpp
@@ -219,6 +219,16 @@ void ExplainMsg(char *ApiName, HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam
 	OutTrace("%s[%x]: WinMsg=[0x%x]%s(%x,%x) %s\n", ApiName, hwnd, Msg, ExplainWinMessage(Msg), wParam, lParam, sPos);
 }
 
+struct TmpMsg {
+	int valid;
+	HWND hwnd;
+	UINT message;
+	WPARAM wparam;
+	LPARAM lparam;
+};
+
+static TmpMsg NullMsg;
+
 LRESULT CALLBACK extWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
 {
 	POINT prev, curr;
@@ -235,6 +245,9 @@ LRESULT CALLBACK extWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp
 	static BOOL TimeShiftToggle=TRUE;
 	extern void DDrawScreenShot(int);
 
+	static TmpMsg lbuttonDown = NullMsg;
+	static TmpMsg rbuttonDown = NullMsg;
+
 	if(DoOnce){
 		DoOnce=FALSE;
 		IsToBeLocked=(dxw.dwFlags1 & LOCKWINPOS);
@@ -396,6 +409,7 @@ LRESULT CALLBACK extWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp
 		}
 		break;
 	case WM_ACTIVATE:
+		OutTraceC("WindowProc: *** WM_ACTIVATE ***\n");
 		// turn DirectInput bActive flag on & off .....
 		dxw.bActive = (LOWORD(wparam) == WA_ACTIVE || LOWORD(wparam) == WA_CLICKACTIVE) ? 1 : 0;
 	case WM_NCACTIVATE:
@@ -473,7 +487,39 @@ LRESULT CALLBACK extWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp
 			GetHookInfo()->CursorX=LOWORD(lparam);
 			GetHookInfo()->CursorY=HIWORD(lparam);
 		}
+
+		if (message == WM_LBUTTONDOWN) {
+			lbuttonDown.hwnd    = hwnd;
+			lbuttonDown.message = message;
+			lbuttonDown.wparam  = wparam;
+			lbuttonDown.lparam  = lparam;
+		}
+		else if (message == WM_RBUTTONDOWN) {
+			rbuttonDown.hwnd    = hwnd;
+			rbuttonDown.message = message;
+			rbuttonDown.wparam  = wparam;
+			rbuttonDown.lparam  = lparam;
+		}
+		else if (message == WM_LBUTTONUP) {
+			lbuttonDown = NullMsg;
+		}
+		else if (message == WM_RBUTTONUP) {
+			rbuttonDown = NullMsg;
+		}
 		break;	
+	case WM_NCLBUTTONDOWN:
+	{
+		int x = LOWORD(lparam);
+		int y = HIWORD(lparam);
+		OutTraceC("WindowProc: WM_NCLBUTTONDOWN: Oops... hwnd=%x, (%d, %d)\n", hwnd, x, y);
+		if (lbuttonDown.hwnd) {
+			lbuttonDown.valid = 1;
+		}
+		else if (rbuttonDown.hwnd) {
+			rbuttonDown.valid = 1;
+		}
+	}
+		break;
 	case WM_SETFOCUS:
 		OutTraceDW("WindowProc: hwnd=%x GOT FOCUS\n", hwnd);
 		if(dxw.dwFlags1 & CLIPCURSOR) dxw.SetClipCursor();
@@ -623,5 +669,20 @@ LRESULT CALLBACK extWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp
 	sprintf(sMsg,"ASSERT: WindowProc mismatch hwnd=%x\n", hwnd);
 	OutTraceDW(sMsg);
 	if (IsAssertEnabled) MessageBox(0, sMsg, "WindowProc", MB_OK | MB_ICONEXCLAMATION);	
-	return (*pDefWindowProcA)(hwnd, message, wparam, lparam);
-}
\ No newline at end of file
+	LRESULT result = (*pDefWindowProcA)(hwnd, message, wparam, lparam);
+	if (message == WM_ACTIVATE) {
+		if (lbuttonDown.valid) {
+			GetHookInfo()->CursorX=LOWORD(lbuttonDown.lparam);
+			GetHookInfo()->CursorY=HIWORD(lbuttonDown.lparam);
+			(*pDefWindowProcA)(lbuttonDown.hwnd, lbuttonDown.message, lbuttonDown.wparam, lbuttonDown.lparam);
+			lbuttonDown = NullMsg;
+		}
+		else if (rbuttonDown.valid) {
+			GetHookInfo()->CursorX=LOWORD(rbuttonDown.lparam);
+			GetHookInfo()->CursorY=HIWORD(rbuttonDown.lparam);
+			(*pDefWindowProcA)(rbuttonDown.hwnd, rbuttonDown.message, rbuttonDown.wparam, rbuttonDown.lparam);
+			rbuttonDown = NullMsg;
+		}
+	}
+	return result;
+}