Browse Source

1、居中显示exe未完成。
2、WxMgr类未完成。

Jeff 6 years ago
parent
commit
f9740be160

+ 32 - 7
source/hook/WeChats/CWxObject.cpp

@@ -1,6 +1,6 @@
 #include "stdafx.h"
 #include "CWxObject.h"
-
+#include <math.h>
 
 #define WX_MAIN_WND_NAME _T("微信")
 #define WX_MAIN_WND_CLASS_NAME _T("WeChatMainWndForPC")
@@ -234,16 +234,41 @@ BOOL CWxObject::Attach2MainWnd(CWnd *pMainWnd, BOOL bLoginWnd )
 
 		CRect rect;
 		pMainWnd->GetWindowRect(&rect);
-		// 设置背景透明;
+		// 设置父窗口;
 		::SetParent(hWxWnd, pMainWnd->m_hWnd);//set parent of ms paint to our dialog.
 		// 擦除背景;
 		//SetWindowLong(hWxWnd, GWL_STYLE, WS_VISIBLE);//eraze title of ms paint window.
 		//Positioning ms paint.
-		pMainWnd->ScreenToClient(&m_rcWxWnd);
-		::MoveWindow(hWxWnd, m_rcWxWnd.left, m_rcWxWnd.top, m_rcWxWnd.right, m_rcWxWnd.bottom, true);
-		//ClientToScreen(&rect);
-		//ScreenToClient(&rect);
-		//::SetWindowPos(hWxWnd, NULL, rect.left, rect.top, rect.right, rect.bottom, SWP_SHOWWINDOW | SWP_HIDEWINDOW);
+		// 将屏幕坐标转在窗口坐标;
+		pMainWnd->ScreenToClient(&rect);
+		// 居中显示;
+		CRect rcCenter = rect;
+		if (m_rcWxWnd.Width() >= rect.Width())
+		{
+			rcCenter.left = 0;
+			rcCenter.right = rect.right;
+		}
+		else
+		{
+			rcCenter.left = (rect.Width() - m_rcWxWnd.Width()) / 2;
+			rcCenter.right = rcCenter.left + m_rcWxWnd.Width();
+		}
+
+		if (m_rcWxWnd.Height() >= rect.Height())
+		{
+			rcCenter.top = 0;
+			rcCenter.bottom = rect.bottom;
+		}
+		else
+		{
+			rcCenter.top = (rect.Height() - m_rcWxWnd.Height()) / 2;
+			rcCenter.bottom = rcCenter.bottom + m_rcWxWnd.Height();
+		}
+
+		// 注意:MoveWindow/SetWindowPos使用的是父窗口的坐标,如果父窗口为NULL,则使用的是屏幕坐标;
+		//::MoveWindow(hWxWnd, rcCenter.left, rcCenter.top, rcCenter.right, rcCenter.bottom, true);
+		::SetWindowPos(hWxWnd, NULL, rcCenter.left, rcCenter.top, rcCenter.right, rcCenter.bottom, SWP_SHOWWINDOW | SWP_HIDEWINDOW);
+
 		//窗口重绘,(因创建exe时,设置为SW_HIDE,导致exe窗口会被父窗口覆盖一部分)
 		//Invalidate();
 		::UpdateWindow(hWxWnd);

+ 1 - 1
source/hook/WeChats/Global.cpp

@@ -914,7 +914,7 @@ BOOL MySystemShutdown()
 	return TRUE;
 }
 
-BOOL getWeChatPath()
+BOOL GetWeChatPath()
 {
 	// 通过注册表获取微信安装目录;
 	HKEY hKey = NULL;

+ 1 - 1
source/hook/WeChats/Global.h

@@ -57,7 +57,7 @@ extern BOOL MySystemShutdown();
 
 
 //////////////////////////////////////////////////////////////////////////
-extern BOOL getWeChatPath();
+extern BOOL GetWeChatPath();
 extern BOOL OpenWeChat();
 
 #endif

+ 0 - 15
source/hook/WeChats/WeChats.cpp

@@ -199,21 +199,6 @@ BOOL CWeChatsApp::InitInstance()
 		return FALSE;
 	}
 
-// 	HANDLE hObject = CreateMutex(NULL, FALSE, _T("CYLGLAppXiao"));
-// 	if (GetLastError() == ERROR_ALREADY_EXISTS)
-// 	{
-// 		return FALSE;
-// 	}
-// 	GetProcessModules(::GetCurrentProcess(), _T("Mutant"), _T("_WeChat_Instance_Identity_Mutex_Name"));
-
-
-	
-// 	int nCount = 3;
-// 	getWeChatPath();
-// 	for (int i = 0; i < nCount; i++)
-// 		OpenWeChat();
-
-
 #if 0
 	TCHAR szDllPath[MAX_PATH];
 	ZeroMemory(szDllPath,MAX_PATH);

+ 2 - 1
source/hook/WeChats/WeChats.vcxproj

@@ -144,6 +144,7 @@
     </ClCompile>
     <ClCompile Include="WeChats.cpp" />
     <ClCompile Include="WeChatsDlg.cpp" />
+    <ClCompile Include="WxMgr.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\pb\msg.pb.h" />
@@ -161,13 +162,13 @@
     <ClInclude Include="CWxObject.h" />
     <ClInclude Include="Global.h" />
     <ClInclude Include="IClient.h" />
-    <ClInclude Include="InjectInterface.h" />
     <ClInclude Include="Injection.h" />
     <ClInclude Include="Resource.h" />
     <ClInclude Include="stdafx.h" />
     <ClInclude Include="targetver.h" />
     <ClInclude Include="WeChats.h" />
     <ClInclude Include="WeChatsDlg.h" />
+    <ClInclude Include="WxMgr.h" />
   </ItemGroup>
   <ItemGroup>
     <Image Include="res\WeChats.ico" />

+ 12 - 9
source/hook/WeChats/WeChats.vcxproj.filters

@@ -24,9 +24,6 @@
     <ClCompile Include="Global.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
-    <ClCompile Include="Injection.cpp">
-      <Filter>源文件</Filter>
-    </ClCompile>
     <ClCompile Include="stdafx.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
@@ -75,17 +72,17 @@
     <ClCompile Include="CWxObject.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
+    <ClCompile Include="WxMgr.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
+    <ClCompile Include="Injection.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Global.h">
       <Filter>头文件</Filter>
     </ClInclude>
-    <ClInclude Include="InjectInterface.h">
-      <Filter>头文件</Filter>
-    </ClInclude>
-    <ClInclude Include="Injection.h">
-      <Filter>头文件</Filter>
-    </ClInclude>
     <ClInclude Include="Resource.h">
       <Filter>头文件</Filter>
     </ClInclude>
@@ -143,6 +140,12 @@
     <ClInclude Include="CWxObject.h">
       <Filter>头文件</Filter>
     </ClInclude>
+    <ClInclude Include="WxMgr.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
+    <ClInclude Include="Injection.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <Image Include="res\WeChats.ico">

+ 39 - 32
source/hook/WeChats/WeChatsDlg.cpp

@@ -170,40 +170,47 @@ void CWeChatsDlg::OnBnClickedOpenWx()
 	//vector<DWORD> vtPID = FindAllProcess(_T("AliIM.exe"));
 	if (vtPID.size() != 0)
 	{
-		CWxObject wxobj(*vtPID.begin(), _T("E:\\bin\\WeChats2017\\hook.dll"));
-		//if (wxobj.FindWxMainWnd())
-		if (wxobj.FindWxLoginWnd())
+		CWxObject wxobj(*vtPID.begin(), g_szDynamicLibraryPath);
+		if (wxobj.FindWxMainWnd())
 		{
-			//g_hWxWnd = wxobj.GetWxMainWnd();
-			g_hWxWnd = wxobj.GetWxLoginWnd();
-			if (g_hWxWnd != NULL)
-			{
-				// 获取微信窗口的样式;
-				DWORD dwStyle = ::GetWindowLong(g_hWxWnd, GWL_STYLE);
-				// WS_CLIPSIBLINGS告诉父窗口不要绘制子窗口出现的区域;
-				dwStyle |= WS_CLIPSIBLINGS; 
-				// 重新设置窗口样式 ;
-				::SetWindowLong(g_hWxWnd, GWL_STYLE, dwStyle);
-
-				CRect rect;
-				GetDlgItem(WX_RECT)->GetWindowRect(&rect);
-				// 设置背景透明;
-				::SetParent(g_hWxWnd, GetDlgItem(WX_RECT)->m_hWnd);//set parent of ms paint to our dialog.
-				//::SetParent(hWxWnd, m_hWnd);
-				// 擦除背景;
-				//SetWindowLong(hWxWnd, GWL_STYLE, WS_VISIBLE);//eraze title of ms paint window.
-				//Positioning ms paint.
-				ScreenToClient(wxobj.m_rcWnd);
-				::MoveWindow(g_hWxWnd, wxobj.m_rcWnd.left, wxobj.m_rcWnd.top, wxobj.m_rcWnd.right, wxobj.m_rcWnd.bottom, true);
-				//ClientToScreen(&rect);
-				//ScreenToClient(&rect);
-				//::SetWindowPos(hWxWnd, NULL, rect.left, rect.top, rect.right, rect.bottom, SWP_SHOWWINDOW | SWP_HIDEWINDOW);
-				//窗口重绘,(因创建exe时,设置为SW_HIDE,导致exe窗口会被父窗口覆盖一部分)
-				//Invalidate();
-				::UpdateWindow(g_hWxWnd);
-				::ShowWindow(g_hWxWnd, SW_SHOW);
-			}
+			wxobj.InjectDynamicLibrary();
+			wxobj.Attach2MainWnd(GetDlgItem(WX_RECT), FALSE);
+			Sleep(10000);
+			wxobj.DetachWxWnd();
 		}
+		//if (wxobj.FindWxMainWnd())
+		//if (wxobj.FindWxLoginWnd())
+		//{
+		//	//g_hWxWnd = wxobj.GetWxMainWnd();
+		//	g_hWxWnd = wxobj.GetWxLoginWnd();
+		//	if (g_hWxWnd != NULL)
+		//	{
+		//		// 获取微信窗口的样式;
+		//		DWORD dwStyle = ::GetWindowLong(g_hWxWnd, GWL_STYLE);
+		//		// WS_CLIPSIBLINGS告诉父窗口不要绘制子窗口出现的区域;
+		//		dwStyle |= WS_CLIPSIBLINGS; 
+		//		// 重新设置窗口样式 ;
+		//		::SetWindowLong(g_hWxWnd, GWL_STYLE, dwStyle);
+
+		//		CRect rect;
+		//		GetDlgItem(WX_RECT)->GetWindowRect(&rect);
+		//		// 设置背景透明;
+		//		::SetParent(g_hWxWnd, GetDlgItem(WX_RECT)->m_hWnd);//set parent of ms paint to our dialog.
+		//		//::SetParent(hWxWnd, m_hWnd);
+		//		// 擦除背景;
+		//		//SetWindowLong(hWxWnd, GWL_STYLE, WS_VISIBLE);//eraze title of ms paint window.
+		//		//Positioning ms paint.
+		//		ScreenToClient(wxobj.m_rcWnd);
+		//		::MoveWindow(g_hWxWnd, wxobj.m_rcWnd.left, wxobj.m_rcWnd.top, wxobj.m_rcWnd.right, wxobj.m_rcWnd.bottom, true);
+		//		//ClientToScreen(&rect);
+		//		//ScreenToClient(&rect);
+		//		//::SetWindowPos(hWxWnd, NULL, rect.left, rect.top, rect.right, rect.bottom, SWP_SHOWWINDOW | SWP_HIDEWINDOW);
+		//		//窗口重绘,(因创建exe时,设置为SW_HIDE,导致exe窗口会被父窗口覆盖一部分)
+		//		//Invalidate();
+		//		::UpdateWindow(g_hWxWnd);
+		//		::ShowWindow(g_hWxWnd, SW_SHOW);
+		//	}
+		//}
 	}
 #endif
 }

+ 29 - 0
source/hook/WeChats/WxMgr.cpp

@@ -0,0 +1,29 @@
+#include "stdafx.h"
+#include "WxMgr.h"
+#include "Global.h"
+
+CWxMgr::CWxMgr()
+{
+}
+
+
+CWxMgr::~CWxMgr()
+{
+}
+
+BOOL CWxMgr::AttachUnMgrWxProc()
+{
+	vector<DWORD> vtWxProcId = FindAllProcess(WECHAT);
+	for ( DWORD pid:vtWxProcId)
+	{
+		if ( m_mapWx.count(pid) == 0)
+		{
+			CWxObject wxObj(pid, g_szDynamicLibraryPath);
+			wxObj.InjectDynamicLibrary();
+			wxObj.FindWxMainWnd();
+			m_mapWx.insert(pair<DWORD, CWxObject>(pid, wxObj));
+		}
+	}
+
+	return TRUE;
+}

+ 23 - 0
source/hook/WeChats/WxMgr.h

@@ -0,0 +1,23 @@
+#ifndef __WX_MRG__
+#define __WX_MRG__
+
+#include <map>
+#include "CWxObject.h"
+
+#pragma once
+
+
+class CWxMgr
+{
+public:
+	CWxMgr();
+	~CWxMgr();
+
+private:
+	std::map<DWORD, CWxObject> m_mapWx;
+	BOOL AttachUnMgrWxProc();
+public:
+	BOOL OpenWeChat();
+};
+
+#endif //__WX_MRG__