News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

change the size of a window

Started by Younth, September 10, 2009, 02:39:03 PM

Previous topic - Next topic

Younth

Hello !How can I change the size of a window?
or the right API ?

Astro

#1
Hi,

EDIT: Ignore me - link was totally irrelevent to resizing windows.

Best regards,
Astro.

raymond

Look at the MoveWindow function. It allow you to move the window, or change its dimensions, or both.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

hutch--

You can also have a look at the API SetWindowPos() which has ore options but note that the MoveWindow() API that Ray has mentioned is faster.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

2-Bit Chip

#4
.code

SetWindowDim proc hWnd:DWORD, dwWidth:DWORD, dwHeight:DWORD

    push eax
    push edx

    push 01Ch
    push 040h
    call GlobalAlloc

    push hWnd
    pop dword ptr [eax]
    mov dword ptr [eax+24], 00000000Ah

    push eax
   
    push eax
    push 0h
    push 46h
    push hWnd
    call SendMessage

    xor eax, eax
    mov eax, dwHeight
    shl eax, 16
    mov edx, dwWidth
    or eax, edx
    xchg eax, edx

    pop eax
    push dwWidth
    pop dword ptr [eax+16]
    push dwHeight
    pop dword ptr [eax+20]
    push eax

    push edx
    push 0h
    push 5h
    push hWnd
    call SendMessage

    push 0h
    push 9h
    push hWnd
    call SendMessage
   
    pop edx
    pop eax

    ret

SetWindowDim endp


Can be used as:

invoke SetWindowDim, hWnd, 400, 600

MichaelW

This procedure resizes the specified window so the client area will have the specified width and height. I coded this for dialogs (for which the size is specified in Dialog Template Units instead of pixels) where I needed a specific client size in pixels. There are other methods of doing this, but AFAIK none of them can be depended on to set the width and height to the exact specified values under all versions of Windows. And for application windows, sizing the window for a specific client size when it is created is cumbersome, at best, because you must allow for the title bar and borders.

SetClientSize proc uses ebx hwnd:HWND, pixelWidth:DWORD, pixelHeight:DWORD

    LOCAL rcc:RECT, rcw:RECT

    invoke GetClientRect, hwnd, ADDR rcc
    invoke GetWindowRect, hwnd, ADDR rcw

    mov ecx, rcw.right
    sub ecx, rcw.left       ; ecx = window width - 1

    mov eax, pixelWidth
    dec eax                 ; eax = pixelWidth - 1
    mov ebx, rcc.right      ; ebx = client width - 1
    sub ebx, eax            ; ebx = difference
    sub ecx, ebx            ; adjust width

    mov edx, rcw.bottom
    sub edx, rcw.top        ; edx = window height - 1

    mov eax, pixelHeight
    dec eax                 ; eax = pixelHeight - 1
    mov ebx, rcc.bottom     ; ebx = client height - 1
    sub ebx, eax            ; ebx = difference
    sub edx, ebx            ; adjust height

    invoke MoveWindow, hwnd, rcw.left, rcw.top, ecx, edx, TRUE

    ret

SetClientSize endp

 
eschew obfuscation

Younth

Quote from: hutch-- on September 11, 2009, 02:45:57 AM
You can also have a look at the API SetWindowPos() which has ore options but note that the MoveWindow() API that Ray has mentioned is faster.
Thank you ! hutch,both of these two API I have tried ,however ,they can only make the window smaller,after I checked the function of them,I can't resizing the window bigger,the code below:
.elseif wParam==98
                   invoke   GetClientRect,hWinMain,addr @stRect
                   mov eax,@stRect.right
                   add eax,10
                   mov @stRect.right,eax
                   invoke SetWindowPos,hWinMain,HWND_NOTOPMOST,@stRect.left,@stRect.left,@stRect.right,@stRect.right,NULL
                   ;or  invoke MoveWindow,hWinMain,,@stRect.left,,@stRect.left,,@stRect.right,,@stRect.right,true;I have tried ,both the some result(to be smaller,rather than bigger)
what's wrong?

Younth

ah,Thanks all of  you !
I have solved this matter, by the way,what's the differences between GetWindowRect() and GetClientRect(),when i  try the first one today, it works ,my window changed to be bigger.Wow,it's really wonderful !

raymond

The WindowRect is the size of your entire window. Its maximum size is the size of your screen resolution. The ClientRect is the area of the WindowRect (usually the white space within your window) which does not have whatever other areas you may have specified when you created your window such as:
- borders,
- system menu (usually the blue section at the top of your window),
- your own menu,
- horizontal and/or vertical scroll bars,
etc.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com