HWND WINAPI OnCreateWindowExW(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam) { //typedef HWND (WINAPI* OnCreateWindowExW_t)(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam); ORIGINAL_EX(CreateWindowExW); HWND hWnd = NULL; BOOL bAttachGui = FALSE, bStyleHidden = FALSE; DWORD lStyle = dwStyle, lStyleEx = dwExStyle; if (CheckCanCreateWindow(NULL, lpClassName, dwStyle, dwExStyle, hWndParent, bAttachGui, bStyleHidden) && F(CreateWindowExW) != NULL) { if (bAttachGui) { x = grcConEmuClient.left; y = grcConEmuClient.top; nWidth = grcConEmuClient.right - grcConEmuClient.left; nHeight = grcConEmuClient.bottom - grcConEmuClient.top; } hWnd = F(CreateWindowExW)(dwExStyle, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam); DWORD dwErr = GetLastError(); if (hWnd && bAttachGui) { OnGuiWindowAttached(hWnd, hMenu, NULL, lpClassName, lStyle, lStyleEx, bStyleHidden); SetLastError(dwErr); } } _ASSERTRESULT(hWnd!=NULL); return hWnd; }
HWND WINAPI OnGetWindow(HWND hWnd, UINT uCmd) { //typedef HWND (WINAPI* OnGetWindow_t)(HWND hWnd, UINT uCmd); ORIGINAL_EX(GetWindow); HWND lhRc = NULL; if (ghConEmuWndDC) { if (ghAttachGuiClient) { if ((hWnd == ghAttachGuiClient || hWnd == ghConEmuWndDC) && (uCmd == GW_OWNER)) { hWnd = ghConEmuWnd; } } else if ((hWnd == ghConEmuWndDC) && (uCmd == GW_OWNER)) { hWnd = ghConEmuWnd; } } if (F(GetWindow)) { lhRc = F(GetWindow)(hWnd, uCmd); if (ghAttachGuiClient && (uCmd == GW_OWNER) && (lhRc == ghConEmuWndDC)) { _ASSERTE(lhRc != ghConEmuWndDC); lhRc = ghAttachGuiClient; } } _ASSERTRESULT(lhRc!=NULL); return lhRc; }
BOOL WINAPI OnGetWindowRect(HWND hWnd, LPRECT lpRect) { //typedef BOOL (WINAPI* OnGetWindowRect_t)(HWND hWnd, LPRECT lpRect); ORIGINAL_EX(GetWindowRect); BOOL lbRc = FALSE; if ((hWnd == ghConWnd) && ghConEmuWndDC) { //EMenu gui mode issues (center in window). "Remove" Far window from mouse cursor. hWnd = ghConEmuWndDC; } if (F(GetWindowRect) != NULL) lbRc = F(GetWindowRect)(hWnd, lpRect); //if (ghConEmuWndDC && lpRect) //{ // //EMenu text mode issues. "Remove" Far window from mouse cursor. // POINT ptCur = {0}; // GetCursorPos(&ptCur); // lpRect->left += ptCur.x; // lpRect->right += ptCur.x; // lpRect->top += ptCur.y; // lpRect->bottom += ptCur.y; //} _ASSERTRESULT(lbRc); return lbRc; }
BOOL WINAPI OnGetMessageW(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax) { //typedef BOOL (WINAPI* OnGetMessageW_t)(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax); ORIGINAL_EX(GetMessageW); BOOL lRc = 0; if (F(GetMessageW)) lRc = F(GetMessageW)(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); if (lRc && ghAttachGuiClient) PatchGuiMessage(true, lpMsg->hwnd, lpMsg->message, lpMsg->wParam, lpMsg->lParam); _ASSERTRESULT(TRUE); return lRc; }
BOOL WINAPI OnSetWindowPos(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags) { //typedef BOOL (WINAPI* OnSetWindowPos_t)(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags); ORIGINAL_EX(SetWindowPos); BOOL lbRc = FALSE; if (ghConEmuWndDC && (hWnd == ghConEmuWndDC || hWnd == ghConEmuWnd)) { _ASSERTRESULT(FALSE); return TRUE; // обманем. приложениям запрещено "двигать" ConEmuDC } if (ghConEmuWndDC && ghAttachGuiClient && hWnd == ghAttachGuiClient) { // GUI приложениями запрещено самостоятельно двигаться внутри ConEmu OnSetGuiClientWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags); } if (F(SetWindowPos)) lbRc = F(SetWindowPos)(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags); _ASSERTRESULT(lbRc); return lbRc; }
LONG_PTR WINAPI OnSetWindowLongPtrW(HWND hWnd, int nIndex, LONG_PTR dwNewLong) { //typedef LONG_PTR (WINAPI* OnSetWindowLongPtrW_t)(HWND hWnd, int nIndex, LONG_PTR dwNewLong); ORIGINAL_EX(SetWindowLongPtrW); LONG_PTR lRc = 0; if (ghConEmuWndDC && (hWnd == ghConEmuWndDC || hWnd == ghConEmuWnd)) { _ASSERTRESULT(FALSE); SetLastError(ERROR_INVALID_HANDLE); lRc = 0; // обманем. приложениям запрещено менять ConEmuDC } else if (F(SetWindowLongPtrW)) { lRc = F(SetWindowLongPtrW)(hWnd, nIndex, dwNewLong); } return lRc; }
HWND WINAPI OnGetAncestor(HWND hWnd, UINT gaFlags) { //typedef HWND (WINAPI* OnGetAncestor_t)(HWND hWnd, UINT gaFlags); ORIGINAL_EX(GetAncestor); HWND lhRc = NULL; #ifdef LOG_GETANCESTOR if (ghAttachGuiClient) { wchar_t szInfo[1024]; getWindowInfo(hWnd, szInfo); lstrcat(szInfo, L"\n"); DebugString(szInfo); } #endif //if (ghConEmuWndDC && hWnd == ghConEmuWndDC) //{ // hWnd = ghConEmuWnd; //} if (ghConEmuWndDC) { #ifdef _DEBUG if ((GetKeyState(VK_CAPITAL) & 1)) { int nDbg = 0; } #endif if (ghAttachGuiClient) { // Обмануть GUI-клиента, пусть он думает, что он "сверху" if (hWnd == ghAttachGuiClient || hWnd == ghConEmuWndDC) { hWnd = ghConEmuWnd; } #if 0 else { wchar_t szName[255]; GetClassName(hWnd, szName, countof(szName)); if (wcsncmp(szName, L"WindowsForms", 12) == 0) { GetWindowText(hWnd, szName, countof(szName)); if (wcsncmp(szName, L"toolStrip", 8) == 0 || wcsncmp(szName, L"menuStrip", 8) == 0) { hWnd = ghConEmuWndDC; } } } #endif } else if (hWnd == ghConEmuWndDC) { hWnd = ghConEmuWnd; } } if (F(GetAncestor)) { lhRc = F(GetAncestor)(hWnd, gaFlags); if (ghAttachGuiClient && (gaFlags == GA_ROOTOWNER || gaFlags == GA_ROOT) && lhRc == ghConEmuWnd) { lhRc = ghAttachGuiClient; } } _ASSERTRESULT(lhRc); return lhRc; }