Skip to content

Commit

Permalink
fix AOE2 textbox position
Browse files Browse the repository at this point in the history
  • Loading branch information
FunkyFr3sh committed Jul 14, 2024
1 parent cd3bef1 commit c850b0d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
7 changes: 7 additions & 0 deletions inc/dd.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ typedef struct CNCDDRAW
DWORD gui_thread_id;
BOOL show_driver_warning;

struct
{
HWND hwnd;
int x;
int y;
} textbox; /* Age Of Empires 2 textbox align */

} CNCDDRAW;

#endif
23 changes: 23 additions & 0 deletions src/dd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,29 @@ HRESULT dd_SetDisplayMode(DWORD dwWidth, DWORD dwHeight, DWORD dwBPP, DWORD dwFl
mouse_lock();
}

if (g_ddraw.textbox.hwnd &&
g_ddraw.textbox.x &&
g_ddraw.textbox.y &&
IsWindow(g_ddraw.textbox.hwnd) &&
GetParent(g_ddraw.textbox.hwnd) == g_ddraw.hwnd)
{
char class_name[MAX_PATH] = { 0 };
GetClassNameA(g_ddraw.textbox.hwnd, class_name, sizeof(class_name) - 1);

if (_strcmpi(class_name, "Edit") == 0)
{
real_SetWindowPos(
g_ddraw.textbox.hwnd,
0,
g_ddraw.textbox.x * g_ddraw.render.scale_w,
g_ddraw.textbox.y * g_ddraw.render.scale_h,
0,
0,
SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER
);
}
}

RedrawWindow(g_ddraw.hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE);

if (g_ddraw.render.viewport.x != 0 || g_ddraw.render.viewport.y != 0)
Expand Down
2 changes: 1 addition & 1 deletion src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ BOOL CALLBACK util_enum_child_proc(HWND hwnd, LPARAM lparam)
dbg_dump_wnd_styles(style, exstyle);
#endif

if (parent != g_ddraw.hwnd || size.right <= 1 || size.bottom <= 1 || strcmp(class_name, "Edit") == 0)
if (parent != g_ddraw.hwnd || size.right <= 1 || size.bottom <= 1 || _strcmpi(class_name, "Edit") == 0)
return TRUE;

if (g_config.fixchilds == FIX_CHILDS_DETECT_HIDE ||
Expand Down
25 changes: 25 additions & 0 deletions src/winapi_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,20 @@ BOOL WINAPI fake_MoveWindow(HWND hWnd, int X, int Y, int nWidth, int nHeight, BO
Y += pt.y;
}
}
else if (hWnd == g_ddraw.textbox.hwnd && IsWindow(hWnd) && GetParent(hWnd) == g_ddraw.hwnd && g_ddraw.width)
{
char class_name[MAX_PATH] = { 0 };
GetClassNameA(hWnd, class_name, sizeof(class_name) - 1);

if (_strcmpi(class_name, "Edit") == 0)
{
g_ddraw.textbox.x = X;
g_ddraw.textbox.y = Y;

X *= g_ddraw.render.scale_w;
Y *= g_ddraw.render.scale_h;
}
}
}

return real_MoveWindow(hWnd, X, Y, nWidth, nHeight, bRepaint);
Expand Down Expand Up @@ -1692,6 +1706,17 @@ HWND WINAPI fake_CreateWindowExA(
hInstance,
lpParam);

/* Age Of Empires 2 */
if (!dwExStyle &&
HIWORD(lpClassName) && _strcmpi(lpClassName, "edit") == 0 &&
!lpWindowName &&
g_ddraw.ref && g_ddraw.width &&
g_ddraw.hwnd && hWndParent == g_ddraw.hwnd &&
hMenu == 1)
{
g_ddraw.textbox.hwnd = hwnd;
}

TRACE("<- CreateWindowExA(hwnd=%p)\n", hwnd);

return hwnd;
Expand Down

0 comments on commit c850b0d

Please sign in to comment.