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

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
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.
Last edited on
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?
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. 
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()
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.
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.
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
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.
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
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.