How can I set object on the bottom of window...

Jun 20, 2011 at 2:30pm
Hi,

I need to put an object on the bottom of window, but it always need to be on the bottom, when you resize window etc...

I found this:
clientWidth, clientHeight


And I would like to use it like this:

1
2
3
4
mBoundingBox.left =  250;
	mBoundingBox.right = 350 ;
	mBoundingBox.top = clientHeight - 100;
	mBoundingBox.bottom = clientHeight;


but when I use it my Square draws itself at the top instead on the bottom
Could someone tell my what am I doing wrong?
I'm using VS 2008.

PS. Sorry for my bad enlish but its not my native language...
Last edited on Jun 20, 2011 at 2:34pm
Jun 20, 2011 at 3:37pm
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 .
Jun 20, 2011 at 3:50pm
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.
Last edited on Jun 20, 2011 at 4:04pm
Jun 21, 2011 at 9:20am
I'm sorry but did I mentioned that i'm really bad at programming?

How to use it? How to seve the window size to a varible?
Something like this:

1
2
3
4
	mBoundingBox.left = GetClientRect - 250;
	mBoundingBox.right = GetClientRect - 150 ;
	mBoundingBox.top = 100;
	mBoundingBox.bottom = 200;


Could smoeone make it clear for me?
Jun 21, 2011 at 12:24pm
1
2
3
4
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. 
Jun 21, 2011 at 1:55pm
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()
Jun 21, 2011 at 4:43pm
Sorry but I still have no idea what should I do...I'm begging you, just tell me what should I write to use it like I want.

I reall appreciate every reply but I'm to stupid to do anything with it, sorry.
Jun 21, 2011 at 5:10pm
You start by getting the dimenstions of your parent window...

1
2
3
4
5
6
7
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 


Now you need to tell us what type of object you are trying to place at the bottom of your window. Is it a button? Is is a bitmap? Etc.
Jun 21, 2011 at 7:09pm
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
Last edited on Jun 21, 2011 at 7:09pm
Jun 21, 2011 at 7:52pm
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 --

http://www.winprog.org/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.
Jun 22, 2011 at 7:58am
But every error is about the code you posted...without the thins you wrote everything was fine. The first error is about this line:

GetClientRect(hParentWnd, &rcParent);

The second, third and fourth as well...

Program:
http://hotfile.com/dl/121594815/de234b1/test.rar.html
Last edited on Jun 22, 2011 at 8:03am
Jun 23, 2011 at 10:41pm
From the CSquareClass.cpp file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#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 
/** */
Topic archived. No new replies allowed.