News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

window size and ellipse size not compatible ?

Started by gelatine1, January 16, 2015, 02:10:23 AM

Previous topic - Next topic

gelatine1

So I have wrote a program that creates a window and then sets the window size using this call:
invoke SetWindowPos,hWnd,HWND_NOTOPMOST,0,0,ecx,ebx,SWP_NOZORDER or SWP_NOMOVE
at the moment of calling ecx contains 347 and ebx contains 2a8.

In the WM_PAINT message I have a call to the Ellipse function:
invoke Ellipse,dc,0,0,eax,ebx
eax containing 347 and ebx containing 2a8. I have checked in Ollydbg that the values were really the same and this was the result:


I'm especially bugged with this width that doesn't fit. (the window didn't fit on my screen in height so it doesn't matter much)
Why does this happen ?

Thanks in advance

dedndave

window size - includes title bar, borders
client size - doesn't

you could use GetClientRect to fill a RECT structure
RECT.top and left will always be 0 - so, RECT.bottom = client height and RECT.right = client width

i think, to make the elipse fit inside the RECT, subtract 1 from those dimensions

gelatine1

#2
My ellipse dimensions shouldnt change. But my window may change so how do i set the window size such that the client size has the dimensions i want ?
Edit:
I also tried looking into the GetSystemMetrics function and I tried to add the SM_CXBORDER and SM_CXFIXEDFRAME parameters in those function calls to get the width of my borders and add it to the width of the window. But clearly they aren't the ones I need so maybe theres another parameter I could use there ?

jj2007

The proper way to do this is to handle the WM_PAINT message, and to adjust the ellipse rectangle according to the client rect you get there. Attached an example - plain Masm32, less than 50 lines.

gelatine1

nono, My ellipse should have a fixed size. it has to be exactly the dimensions i want it to be. The window should change according to the ellipse, not the other way around like you did.

jj2007

OK. In that case, you need AdjustWindowRect, see attachment.

@Dave: Check the attachment. The behaviour is a bit odd, not exactly what the documentation says. Try to pass the rc values to CreateWindowEx, and measure the pixels of the client rect :(
But MoveWindow does the job.

gelatine1

Exactly that's what I was looking for :exclaim: Thanks

dedndave

you can use GetSystemMetrics
it depends, of course, on the flags used to create the window
but, if you use WS_OVERLAPPEDWINDOW, you get a window with a title and sizing borders....

window width = client width + 2 * ( GetSystemMetrics(SM_CXSIZEFRAME) )

window height = client height + 2 * ( GetSystemMetrics(SM_CYSIZEFRAME) ) + GetSystemMetrics(SM_CYCAPTION)

SM_CYCAPTION is the title bar height
if you add a menu and/or status bar, you have to account for those, too

MichaelW

AdjustWindowRect has limitations, the procedure here does not.
Well Microsoft, here's another nice mess you've gotten us into.

jj2007

Here is a window with WS_OVERLAPPEDWINDOW style and a 500x500 client area. It was much simpler than I thought.

gelatine1

jj2007 How am I supposed to read this .asc file in a descent way (it's readable but theres many random junk in between the code)? What is it ? Why don't you use .asm files ?

jj2007

Quote from: gelatine1 on January 17, 2015, 05:46:13 AMWhat is it ? Why don't you use .asm files ?

It's Rich Text Format, and I use it because I like colouring and formatting my code individually. You can open it in Wordpad, although RichMasm (comes with MasmBasic) is by far the better choice :icon_mrgreen:

dedndave

i use NotePad++
you can open the .asc file, then save it as a .txt file