|
@@ -85,7 +85,8 @@ CWxObject::~CWxObject()
|
|
|
|
|
|
// 退出主窗口;
|
|
|
// 注:必须在主窗口销毁前分离;
|
|
|
- DetachWxWnd();
|
|
|
+ if (!m_bAttached)
|
|
|
+ DetachWxWnd();
|
|
|
}
|
|
|
|
|
|
void CWxObject::setInjectionObj(DWORD dwProcId, LPCTSTR lpDynamicLibraryPath)
|
|
@@ -230,7 +231,7 @@ BOOL CWxObject::Attach2MainWnd(CWnd *pMainWnd, BOOL bLoginWnd )
|
|
|
// 获取微信窗口的样式;
|
|
|
DWORD dwStyle = ::GetWindowLong(hWxWnd, GWL_STYLE);
|
|
|
// WS_CLIPSIBLINGS告诉父窗口不要绘制子窗口出现的区域;
|
|
|
- dwStyle |= WS_CLIPSIBLINGS;
|
|
|
+ //dwStyle |= WS_CLIPSIBLINGS;
|
|
|
// 如果窗口隐藏的,显示出来;
|
|
|
dwStyle |= WS_VISIBLE;
|
|
|
// 重新设置窗口样式 ;
|
|
@@ -246,35 +247,54 @@ BOOL CWxObject::Attach2MainWnd(CWnd *pMainWnd, BOOL bLoginWnd )
|
|
|
// 将屏幕坐标转在窗口坐标;
|
|
|
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();
|
|
|
- }
|
|
|
+ CRect rcDisplay = rect;
|
|
|
+ if (0)
|
|
|
+ {// 居中显示;
|
|
|
+ if (m_rcWxWnd.Width() >= rect.Width())
|
|
|
+ {
|
|
|
+ rcDisplay.left = 0;
|
|
|
+ rcDisplay.right = rect.right;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ rcDisplay.left = (rect.Width() - m_rcWxWnd.Width()) / 2;
|
|
|
+ rcDisplay.right = rcDisplay.left + m_rcWxWnd.Width();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (m_rcWxWnd.Height() >= rect.Height())
|
|
|
+ {
|
|
|
+ rcDisplay.top = 0;
|
|
|
+ rcDisplay.bottom = rect.bottom;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ rcDisplay.top = (rect.Height() - m_rcWxWnd.Height()) / 2;
|
|
|
+ rcDisplay.bottom = rcDisplay.top + m_rcWxWnd.Height();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 注意:MoveWindow/SetWindowPos使用的是父窗口的坐标,如果父窗口为NULL,则使用的是屏幕坐标;
|
|
|
+ //::MoveWindow(hWxWnd, rcDisplay.left, rcDisplay.top, rcDisplay.Width(), rcDisplay.Height(), true);
|
|
|
+ ::SetWindowPos(hWxWnd, NULL, rcDisplay.left, rcDisplay.top, rcDisplay.Width(), rcDisplay.Height(), WM_WINDOWPOSCHANGING|SWP_SHOWWINDOW | SWP_HIDEWINDOW);
|
|
|
|
|
|
- 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, rcDisplay.left, rcDisplay.top, rcDisplay.Width(), rcDisplay.Height(), true);
|
|
|
+ //::SetWindowPos(hWxWnd, NULL, rcDisplay.left, rcDisplay.top, rcDisplay.Width(), rcDisplay.Height(), WM_MOVE| WM_SIZE| WM_WINDOWPOSCHANGING| WM_NCCALCSIZE | SWP_SHOWWINDOW);
|
|
|
}
|
|
|
|
|
|
- // 注意: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);
|
|
|
+#ifdef _DEBUG
|
|
|
+ pMainWnd->ClientToScreen(&rect);
|
|
|
+ WriteTextLog(_T("rect=[%d,%d,%d,%d]"), rect.left, rect.top, rect.right, rect.bottom);
|
|
|
+ //pMainWnd->ScreenToClient(&m_rcWxWnd);
|
|
|
+ WriteTextLog(_T("m_rcWxWnd=[%d,%d,%d,%d]"), m_rcWxWnd.left, m_rcWxWnd.top, m_rcWxWnd.right, m_rcWxWnd.bottom);
|
|
|
+ WriteTextLog(_T("rcCenter=[%d,%d,%d,%d]"), rcDisplay.left, rcDisplay.top, rcDisplay.right, rcDisplay.bottom);
|
|
|
+#endif
|
|
|
|
|
|
+
|
|
|
//窗口重绘,(因创建exe时,设置为SW_HIDE,导致exe窗口会被父窗口覆盖一部分)
|
|
|
- //Invalidate();
|
|
|
+ pMainWnd->Invalidate();
|
|
|
::UpdateWindow(hWxWnd);
|
|
|
::ShowWindow(hWxWnd, SW_SHOW);
|
|
|
|
|
@@ -308,7 +328,9 @@ BOOL CWxObject::EnumWindowsProc(HWND hwnd, LPARAM lParam)
|
|
|
pWndInfo->dwThreadId = dwThreadId;
|
|
|
::GetWindowText(hwnd, szWndName, MAX_PATH);
|
|
|
::GetClassName(hwnd, szClassName, MAX_PATH);
|
|
|
-
|
|
|
+#ifdef _DEBUG
|
|
|
+ WriteTextLog(_T("窗口名称:%s, 窗口类名:%s, 线程ID:%d,句柄:%p"), szWndName, szClassName, dwThreadId, hwnd);
|
|
|
+#endif
|
|
|
if (_tcscmp(szWndName, pWndInfo->szWndName) == 0 && _tcscmp(szClassName, pWndInfo->szClassName) == 0)
|
|
|
{
|
|
|
::GetWindowRect(hwnd, &pWndInfo->rcWnd);
|