-
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
-
Possible Answer
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. :)
-
Already tried that.
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
-
Maybe this then
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. :)
-
already tried that.
thanx for the help though
-
Use the GetSystemMetrics function and use the formula you stated above, i.e.....
PHP Code:
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!!
-
Thanx :)
Thanx alot man :) it worked great :) i owe u one.
-
KULE
How bout this one then.
How do I get what would be equivalent to Me.Left in vb??
Thanx in advance...
-
GetWindowRect retrieves the coordinates of a window as it relates to the screen....
PHP Code:
RECT me;
GetWindowRect(hwnd, me);
cout << me.left << endl;
2 in 24 hours YEE-HAW!! hehe :D
-
Code:
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
Code:
char buf[40];
MessageBox(hwnd, itoa(me.left, buf, 10), "Left!", MB_OK);
-
LOL Thanks for stealing my thunder parksie :rolleyes: :D :p
-
thanx for your replies.