Author Topic: When AdjustWindowRectEx fails  (Read 545 times)


  • Moderator
  • Member
  • *****
  • Posts: 730
  • ObjAsm Developer
    • ObjAsm
When AdjustWindowRectEx fails
« on: January 31, 2021, 09:11:21 PM »
I found another good post here
Basically AdjustWindowRectEx doesn't know anything about the menu you're using, so it fails when the menu bar is folded.
The code shown corrects this behavior.  :thumbsup:

Here is the assembler translation.  :biggrin:
I replaced the old code in ObjMem.lib with this one:
Code: [Select]
SetClientSize proc uses xbx hWnd:HWND, dCx:DWORD, dCy:DWORD
  local hMenu:HMENU, rcWindow:RECT, rcTemp:RECT

  mov hMenu, $invoke(GetMenu, hWnd)
  mov rcWindow.left, 0
  mov, 0
  m2m rcWindow.right, dCx, eax
  m2m rcWindow.bottom, dCy, eax

  ;First convert the client rectangle to a window rectangle
  ;the menu-wrap-agnostic way.
  invoke GetWindowLongPtr, hWnd, GWL_STYLE
  mov ebx, eax
  invoke GetWindowLongPtr, hWnd, GWL_EXSTYLE
  lea xcx, rcWindow
  mov edx, ebx
  xor ebx, ebx
  .if hMenu != 0
    inc ebx
  invoke AdjustWindowRectEx, xcx, edx, ebx, eax

  ;If there is a menu, then check how much wrapping occurs when we set a
  ;window to the width specified by AdjustWindowRect and an infinite amount
  ;of height. An infinite height allows us to see every single menu wrap.
  .if ebx != 0
    s2s rcTemp, rcWindow, xax, xcx, xdx, xmm0, xmm1, xmm2, xmm3
    mov rcTemp.bottom, 7FFFh                            ;"Infinite" height
    invoke SendMessage, hWnd, WM_NCCALCSIZE, FALSE, addr rcTemp

    ;Adjust our previous calculation to compensate for menu wrapping.
    mov eax,
    add rcWindow.bottom, eax

    mov eax, rcWindow.right
    sub eax, rcWindow.left
    mov ebx, rcWindow.bottom
    sub ebx,
    invoke SetWindowPos, hWnd, NULL, 0, 0, eax, ebx, SWP_NOMOVE or SWP_NOZORDER
SetClientSize endp