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:
(http://oi61.tinypic.com/2ro48c5.jpg)
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
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
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 ?
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.
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.
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.
Exactly that's what I was looking for :exclaim: Thanks
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
AdjustWindowRect has limitations, the procedure here (http://masm32.com/board/index.php?topic=1484.msg15303#msg15303) does not.
Here is a window with WS_OVERLAPPEDWINDOW style and a 500x500 client area. It was much simpler than I thought.
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 ?
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 (http://masm32.com/board/index.php?topic=94.0)) is by far the better choice :icon_mrgreen:
i use NotePad++
you can open the .asc file, then save it as a .txt file