Click to See Complete Forum and Search --> : Please Help Me.
AAG
Mar 10th, 2001, 06:37 PM
Can Anybody Tell Me How To Center A Win32 Form On Startup. I don't know if your supposed to get the width of the desktop and subtract the width of the appwindow, and divide by 2, and then do the same for the height. i would appreciate any code on centering my appwindow. it doesn't have a titlebar, so i would like for it to be centered as i haven't made an option to move it. thanx for any input on the subject.
AAG
Wak
Mar 10th, 2001, 08:03 PM
Don't quote me on this, but I'm pretty sure you can Pass either WS_CENTERED or WS_CENTER when using CreateWindowEx and the window will be centered. Hope it works. :)
AAG
Mar 10th, 2001, 08:51 PM
i had already tried WS_CENTER and WS_CENTERED. The function is unkown. thanx for the effort though. Can somebody please tell me the correct way to center a window. thanx
Wak
Mar 10th, 2001, 11:31 PM
If you use a resource, it has a flag there that you can add, which is Center form?? Tick it, then open the resource in note pad, and see how it works. Just a suggestion. :)
AAG
Mar 10th, 2001, 11:44 PM
thanx for the help though
YoungBuck
Mar 11th, 2001, 12:19 AM
Use the GetSystemMetrics function and use the formula you stated above, i.e.....
int wdth;
int hgt;
int x;
int y;
//other code here
wdth = 420;
hgt = 300;
x = (GetSystemMetrics(SM_CXSCREEN) / 2) - (wdth / 2);
y = (GetSystemMetrics(SM_CYSCREEN) / 2) - (hgt / 2);
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"The title of my window",
WS_OVERLAPPEDWINDOW,
x, y, wdth, hgt,
NULL, NULL, g_hInst, NULL);
// rest of the code here
WOW! I think I answered a C++ question. WOO-HOO!!
AAG
Mar 11th, 2001, 01:04 AM
Thanx alot man :) it worked great :) i owe u one.
Wak
Mar 11th, 2001, 05:03 AM
How bout this one then.
How do I get what would be equivalent to Me.Left in vb??
Thanx in advance...
YoungBuck
Mar 11th, 2001, 09:37 AM
GetWindowRect retrieves the coordinates of a window as it relates to the screen....
RECT me;
GetWindowRect(hwnd, me);
cout << me.left << endl;
2 in 24 hours YEE-HAW!! hehe :D
parksie
Mar 11th, 2001, 10:02 AM
RECT me;
GetWindowRect(hwnd, &me);
cout << me.left << endl;
Two minor problems...it must be the address of me, and since you're in a window you don't have a console :p
char buf[40];
MessageBox(hwnd, itoa(me.left, buf, 10), "Left!", MB_OK);
YoungBuck
Mar 11th, 2001, 10:17 AM
LOL Thanks for stealing my thunder parksie :rolleyes: :D :p
AAG
Mar 11th, 2001, 05:17 PM
thankx again :)
AAG
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.