| View previous topic :: View next topic |
| Author |
Message |
Wiw3K Grandmaster Cheater
Reputation: 0
Joined: 09 Jul 2006 Posts: 762 Location: Poland.
|
Posted: Mon Feb 09, 2009 2:19 pm Post subject: [WinApi C++]How to make Fixed Window Size?[NVM]Other Q. |
|
|
as title says
+
i tried to make after you start app , it appears on center of screen.
found something about SM_CXSCREEN, but it doesnt appear at center of screen
Last edited by Wiw3K on Mon Feb 09, 2009 5:38 pm; edited 1 time in total |
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Mon Feb 09, 2009 2:25 pm Post subject: |
|
|
| GetSystemMetrics (namely SM_CXSCREEN / SM_CYSCREEN) and a little math.
|
|
| Back to top |
|
 |
Wiw3K Grandmaster Cheater
Reputation: 0
Joined: 09 Jul 2006 Posts: 762 Location: Poland.
|
Posted: Mon Feb 09, 2009 4:10 pm Post subject: |
|
|
dam , cant find it how to center my window after popup...
i have this, ok so if i delete /2 (there can be any number), my app appear somewhere , i cant see it.
GetSystemMetrics(SM_CXSCREEN)/2,
GetSystemMetrics(SM_CYSCREEN)/2,
but i want to the Center of Screen
halp
|
|
| Back to top |
|
 |
talkerzero Grandmaster Cheater
Reputation: 1
Joined: 24 Jul 2008 Posts: 560 Location: California
|
Posted: Mon Feb 09, 2009 4:16 pm Post subject: |
|
|
This code assumes that hWnd is the handle to the window you want to center.
| Code: | RECT window;
GetWindowRect(hWnd, &window);
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
int wndHeight = window.bottom - window.top;
int wndWidth = window.right - window.left;
SetWindowPos(hWnd, 0, (screenWidth/2) - (wndWidth/2), (screenHeight/2) - (wndHeight/2), newWidth, newHeight, 0); |
Last edited by talkerzero on Mon Feb 09, 2009 5:03 pm; edited 1 time in total |
|
| Back to top |
|
 |
Wiw3K Grandmaster Cheater
Reputation: 0
Joined: 09 Jul 2006 Posts: 762 Location: Poland.
|
Posted: Mon Feb 09, 2009 4:39 pm Post subject: |
|
|
@up
wow so this way this works
error C2065: 'newWidth' : undeclared identifier
error C2065: 'newHeight' : undeclared identifier
erm
---edit---
i declared them
int newHeight;
int newWidth;
and everything works exept my window doesnt appear on screen but OFFscreen xD
|
|
| Back to top |
|
 |
talkerzero Grandmaster Cheater
Reputation: 1
Joined: 24 Jul 2008 Posts: 560 Location: California
|
Posted: Mon Feb 09, 2009 5:02 pm Post subject: |
|
|
Shit, I messed up my variables. In SetWindowPos change newWidth and newHeight to wndWidth and wndHeight.
With the old code, it's not moving them offscreen, it's setting their width and height to 0.
Here ya go. This should work fine.
| Code: | RECT window;
GetWindowRect(hWnd, &window);
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
int wndHeight = window.bottom - window.top;
int wndWidth = window.right - window.left;
SetWindowPos(hWnd, 0, (screenWidth/2) - (wndWidth/2), (screenHeight/2) - (wndHeight/2), wndWidth, wndHeight, 0); |
|
|
| Back to top |
|
 |
Wiw3K Grandmaster Cheater
Reputation: 0
Joined: 09 Jul 2006 Posts: 762 Location: Poland.
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Mon Feb 09, 2009 5:27 pm Post subject: |
|
|
Are you fucking serious?
It tells you what the hell is wrong right in the error.
You called it when hWnd is not initialized, and hell from the images you gave, it looks like you havent even registered the windows class.
You might wanna call it after hWnd is given a return from CreateWindowEx.
You can even call it in WM_CREATE if you want.
Or you can just not even use SetWindowPos and create the window at those very coordinates.
_________________
|
|
| Back to top |
|
 |
Wiw3K Grandmaster Cheater
Reputation: 0
Joined: 09 Jul 2006 Posts: 762 Location: Poland.
|
Posted: Mon Feb 09, 2009 5:29 pm Post subject: |
|
|
NVM FIXED.
my fault , i forgot to change something heh Thanks alot guys
btw.
how to make if i hold mouse button , my custom cursor(already have) will change to other custom and after i let it go it change back ?
on button click , change Ico ? this way?
|
|
| Back to top |
|
 |
Zerith Master Cheater
Reputation: 1
Joined: 07 Oct 2007 Posts: 468
|
Posted: Mon Feb 09, 2009 5:40 pm Post subject: |
|
|
| Who would've guessed the API would be SetCursor!
|
|
| Back to top |
|
 |
Wiw3K Grandmaster Cheater
Reputation: 0
Joined: 09 Jul 2006 Posts: 762 Location: Poland.
|
Posted: Mon Feb 09, 2009 6:12 pm Post subject: |
|
|
1. I Want Load Cursor from .bmp.
i did it this way
defined
| Code: | HCURSOR hCurs1;
//Load Cursor
hCurs1 = LoadCursorFromFileA("OnClick.png"); |
then in whole app
| Code: | if (WM_LBUTTONUP)
{
SetCursor(hCurs1);
} |
No Errors but nothing happen after i click left mouse
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Mon Feb 09, 2009 6:49 pm Post subject: |
|
|
wouldn't OnClick wanna be WM_LBUTTONDOWN.... ?
check GetLastError? See if hCurs1 is valid? It supports PNG?
_________________
|
|
| Back to top |
|
 |
|