Skip to content

Commit

Permalink
if dlgproc is null don't pass wm_initdialog to the wndproc (otya128#1239
Browse files Browse the repository at this point in the history
)
  • Loading branch information
cracyc authored Jan 2, 2023
1 parent 30b1f07 commit 67e9228
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
11 changes: 2 additions & 9 deletions user/dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ typedef struct
void free_proc_thunk(DLGPROCTHUNK *thunk);
BYTE get_aflags(HMODULE16 hModule);

typedef struct
{
HMENU16 hMenu16;
DLGPROC16 dlgProc;
} dialog_data;

/* Dialog control information */
typedef struct
{
Expand Down Expand Up @@ -677,13 +671,12 @@ static void init_proc_thunk()
MAX_THUNK = 4096 / sizeof(DLGPROCTHUNK);
thunk_array = VirtualAlloc(NULL, MAX_THUNK * sizeof(DLGPROCTHUNK), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
}
HMENU get_dialog_hmenu(HWND hWnd)
dialog_data *get_dialog_data(HWND hWnd)
{
DLGPROC dlgproc = GetWindowLongPtrA(hWnd, DWLP_DLGPROC);
if (thunk_array <= dlgproc && thunk_array + MAX_THUNK > dlgproc)
{
DLGPROCTHUNK *thunk = (DLGPROCTHUNK*)dlgproc;
return HMENU_32(((dialog_data*)thunk->param)->hMenu16);
return (dialog_data*)(((DLGPROCTHUNK *)dlgproc)->param);
}
return 0;
}
Expand Down
17 changes: 14 additions & 3 deletions user/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -5223,7 +5223,8 @@ void register_wow_handlers(void)
}

BOOL is_dialog(HWND hwnd);
HMENU get_dialog_hmenu(HWND hWnd);
dialog_data *get_dialog_data(HWND hWnd);
void free_proc_thunk(void *thunk);
LRESULT CALLBACK WindowProc16(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
HWND16 hWnd16 = HWND_16(hDlg);
Expand All @@ -5234,9 +5235,19 @@ LRESULT CALLBACK WindowProc16(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
/* some programs don't call DlgProc */
if (Msg == WM_INITDIALOG && is_dialog(hDlg))
{
if (!GetMenu(hDlg))
dialog_data *dd = get_dialog_data(hDlg);
if (dd)
{
SetMenu(hDlg, get_dialog_hmenu(hDlg));
if (!GetMenu(hDlg))
SetMenu(hDlg, HMENU_32(dd->hMenu16));
if (!dd->dlgProc)
{
void *thunk = (void *)GetWindowLongPtrA(hDlg, DWLP_DLGPROC);
SetWindowLongPtrA(hDlg, DWLP_DLGPROC, NULL);
HeapFree(GetProcessHeap(), 0, dd);
free_proc_thunk(thunk);
return TRUE;
}
}
}
WNDPROC16 wndproc16 = (WNDPROC16)GetWndProc16(hWnd16);
Expand Down
6 changes: 6 additions & 0 deletions user/user_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ typedef struct tagDIALOGINFO
UINT flags; /* EndDialog() called for this dialog */
} DIALOGINFO;

typedef struct
{
HMENU16 hMenu16;
DLGPROC16 dlgProc;
} dialog_data;

#define DF_END 0x0001
#define DF_OWNERENABLED 0x0002

Expand Down

0 comments on commit 67e9228

Please sign in to comment.