You need to obtain the current dimensions first into the clientWidth and clientHeight variables. Use GetClientRect() to obtain the rectangle corresponding to the inner area of your window. See http://msdn.microsoft.com/en-us/library/ms633503(VS.85).aspx .
Stuff you find in your "friends" code might as well be garbage That was a little harsh, what I mean to say is that your friend may not be using the best method to accomplish this task. You still have to get the windows rectangle and to do that you use "GetClientRect()".
This thread is continued from Beginners for anyone who is interested. The OP doesn't seem to want to do things the right way.
RECT dims;
GetClientRect(hWndOfTheMainWindowHere, &dims);
//At this point, dims contains the inner dimensions of your main window.
//dims.bottom - dims.top will tell you the inner height.
After you use GetClientRect() to obtain the necessary coordinates, you are also going to have to set the WM_SIZE notification to keep track of the window's size and postion and then move your control accordingly using MoveWindow()
Do I need some kind of #include for this? Becouse I got tons of errors.
And I junst need to draw a rectangle on the bottom of window. I'm writing a game and at the bottom there needs to be a cannon...
Errors:
1 2 3 4 5 6 7
CSquareClass.cpp
c:\users\maniek\downloads\test8\test\test\csquareclass.cpp(13) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\users\maniek\downloads\test8\test\test\csquareclass.cpp(13) : error C2365: 'GetClientRect' : redefinition; previous definition was 'function'
c:\program files\microsoft sdks\windows\v6.0a\include\winuser.h(7206) : see declaration of 'GetClientRect'
c:\users\maniek\downloads\test8\test\test\csquareclass.cpp(13) : error C2078: too many initializers
c:\users\maniek\downloads\test8\test\test\csquareclass.cpp(13) : error C2440: 'initializing' : cannot convert from 'RECT *' to 'int'
There is no context in which this conversion is possible
Those errors simply reveal that you don't know basic C. I'm sorry, but you really need to learn the basics of C and Windows programming. Here is an online tutorial --
In the first error you have apparently declared a variable with no type.
In the second error you have mangled GetClientRect() somehow, unless you have a more severe error and the compiler just defaulted to that.
See those error numbers? Such as C4430? Look those up in the help file and see what it tells you.
You can try to post your entire code here and perhaps we can wade through it, but you REALLY, REALLY, REALLY need to take that tutorial. Unless I'm missing something.
#include "stdafx.h"
#include "CSquareClass.h"
//protected methods
void CSquare::doPaint(HDC ahdc)
{
Rectangle(ahdc, mBoundingBox.left, mBoundingBox.top, mBoundingBox.right, mBoundingBox.bottom);
}
/*** error - THE FOLLOWING FEW LINES OF CODE ARE IN THE MIDDLE OF NOWHERE
WHY ARE THEY HERE?????
THEY SHOULD BE IN A FUNCTION */
HWND hParentWnd;
RECT rcParent;
GetClientRect(hParentWnd, &rcParent);
int iWidth=rcParent.right; // technically rcParent.right-rcParent.left
int iHeight=rcParent.bottom; // technically rcParent.bottom-rcParent.top
/** */