News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

AdjustWindowRect

Started by jj2007, September 20, 2023, 10:06:01 AM

Previous topic - Next topic

jj2007

From the series "macros that nobody asked for":

WinMain proc
LOCAL msg:MSG, rc:RECT
  wc equ [ebx.WNDCLASSEX]        ; we use an equate for better readability
  mov ebx, offset wcx
  mov wc.hInstance, rv(GetModuleHandle, 0)
  mov wc.hIcon, rv(LoadIcon, eax, IDI_APPLICATION)
  mov wc.hIconSm, eax        ; the rv macro returns results in eax
  mov wc.hCursor, rv(LoadCursor, NULL, IDC_ARROW)    ; get a cursor
  invoke RegisterClassEx, addr wc        ; the window class needs to be registered
  editWidth=200
  editHeight=100    ; v v remove the 0* to see the difference
  mov hWin, CreateWindowByClientArea(0*WS_EX_CLIENTEDGE, wc.lpszClassName, "Hello World",\
    WS_OVERLAPPEDWINDOW or WS_VISIBLE,\
    (1366-editWidth)/2, (768-editHeight)/2, editWidth, editHeight,\    ; centred
    NULL, rv(LoadMenu, wc.hInstance, 100), wc.hInstance, NULL)
  .While 1
    invoke GetMessage, addr msg, hWin, 0, 0
    inc eax
    shr eax, 1
    .Break .if Zero?    ; 0 (OK) or -1 (error)
    invoke TranslateMessage, addr msg
    invoke DispatchMessage, addr msg
  .Endw
  invoke ExitProcess, msg.wParam
WinMain endp

Suppose you plan to add an edit control in the WM_CREATE handler; it should have the dimensions editWidth=200, editHeight=100 and fit neatly in the main window's client area.

So, instead of CreateWindowEx, you just use CreateWindowByClientArea :cool:

Project attached, pure Masm32 SDK code :biggrin:

NoCforMe

So could you possibly post just the code for CreateWindowByClientArea()? I really don't want to download yet another project just to take a peek at this, which looks like an interesting (macro you say? or function?).

I'm guessing it uses a bit of back and forth between ScreenToClient() and ClientToScreen(), yes?

Thanks.
Assembly language programming should be fun. That's why I do it.

jj2007

#2
David,

This post clearly was not meant for you! We all know about your difficulties to download a 10,686 bytes zip file, and double-click into the only *.asm file inside the archive to see the content.

How are your projects going, any progress?

-------- back to serious stuff: --------

GetMessage function (winuser.h)
QuoteBOOL GetMessage(
  [out]          LPMSG lpMsg,
  [in, optional] HWND  hWnd,
  [in]          UINT  wMsgFilterMin,
  [in]          UINT  wMsgFilterMax
);
...
Return value
Type: BOOL

If the function retrieves a message other than WM_QUIT, the return value is nonzero.

If the function retrieves the WM_QUIT message, the return value is zero.

If there is an error, the return value is -1

The latter is the reason why we use this wonderful trick invented by DednDave:
  .While 1
    invoke GetMessage, addr msg, hWin, 0, 0
    inc eax
    shr eax, 1
    .Break .if Zero?    ; 0 (OK) or -1 (error)
    invoke TranslateMessage, addr msg
    invoke DispatchMessage, addr msg
  .Endw

Now the interesting bit here is that BOOL means "yes or no", "true or false", "zero or non-zero" - in theory. In practice, it seems that Micros*t invented a third option. For GetMessage, BOOL means "true, false, or error". Cool, isn't it? They invented "non-binary" a long time before it became fashionable ;-)

The reason I am asking is invoke AdjustWindowRectEx, ecx, _style, _menu, _exstyle - is any non-zero value true for that API? I've tested it, and it seems so, but can we trust the geniuses in Redmond?

P.S.: Hutch, Dedndave, Antariy, Donkey and myself had a lot of fun optimising the hell out of Windows :biggrin:

NoCforMe

Quote from: jj2007 on September 20, 2023, 06:14:30 PMDavid,

This post clearly was not meant for you! We all know about your difficulties to download a 10,686 bytes zip file, and double-click into the only *.asm file inside the archive to see the content.

As opposed to, say, having that function/macro simply displayed here where I can look at it without having to download anything? Thanks but no thanks.

Do you know how much crap I've got in my temp folder, stuff I've downloaded from here that I now have no idea what it even is?

QuoteHow are your projects going, any progress?

Actually yes, thanks for asking. I'll be posting something here soon. Interesting stuff, I think.
Assembly language programming should be fun. That's why I do it.