Thanks a ton IronBlayde! That was EXACTLY what I was looking for.
Now for another Win32 question (we really need that Win32 forum!)... I'm still very new at Win32 so bear with me... How can you control the size of the window at creation? Basically, how do you create a full screen window?
Let me clarify some... The only way I know to get the current resolution is to call GetDeviceCaps(hdc, VALUE). As you can see, GetDeviceCaps needs an initialized HDC. For those following along at home, the HDC is initialized like so: hdc = GetDC(hWnd). The clincher is that hWnd is not initialized until you call CreateWindow(blah blah blah...)... which is where I need the values from GetDeviceCaps! So how can I get the values from GetDeviceCaps if the required variables aren't yet initialized? I'm sure theres another method for getting the current resolution, I'm just too new at Win32...
Edited by - Orpheum on September 28, 2000 8:42:10 PM
How do you lock a window's size?
Well you are obviously using the CreateWindow() function, so you are familiar with it. You will notice that the sixth and seventh paramaters to the CreateWindow() function define the window's width and height, respectively.
You CAN still use GetDeviceCaps() function to fill in the width and heigth parameters. However, as you pointed out, the GetDeviceCaps() needs requires a handle to a device context (HDC), and GetDC() requires a handle to a window (HWND). You had the right idea, though. But instead of trying to supply the GetDC() function the handle to the window you are creating, you can pass NULL, or 0 (zero), and it will return the device context (DC) of the entire screen.
Edited by - Steel on September 28, 2000 9:50:00 PM
You CAN still use GetDeviceCaps() function to fill in the width and heigth parameters. However, as you pointed out, the GetDeviceCaps() needs requires a handle to a device context (HDC), and GetDC() requires a handle to a window (HWND). You had the right idea, though. But instead of trying to supply the GetDC() function the handle to the window you are creating, you can pass NULL, or 0 (zero), and it will return the device context (DC) of the entire screen.
HDC hdcScreen;int iWidth;int iHeight;hdcScreen = GetDC(0);iWidth = GetDeviceCaps(hdcScreen, HORZRES);iHeight = GetDeviceCaps(hdcScreen, VERTRES);// You can then pass iWidth and iHeight to the CreateWindow function.
Edited by - Steel on September 28, 2000 9:50:00 PM
It''s even possible to create a window that covers everything, including the Taskbar (anyone can still access it by pressing Ctrl + Esc of course). However, this requires that you create a window with no borders, no control menu (as well as min/max buttons), and no title bar. But it makes a great effect for full screen windows using GDI.
To make such a window, specify ONLY the WS_POPUP style in the CreateWindow() function. Instead of passing iWidth and iHeight to CreateWindow(), just pass zeros. Then pass the iWidth and iHeight variables to the SetWindowPos() function.
To make such a window, specify ONLY the WS_POPUP style in the CreateWindow() function. Instead of passing iWidth and iHeight to CreateWindow(), just pass zeros. Then pass the iWidth and iHeight variables to the SetWindowPos() function.
hwndMain = CreateWindow(szWndClassName, szAppName, WS_POPUP, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 0, 0, 0);SetWindowPos(hwndMain, HWND_TOP, 0, 0, iWidth, iHeight, SWP_SHOWWINDOW);
One more thing you might want to know... when you specify the width and height of a window, that includes the dimensions of the Windows controls (borders, title bar, etc.) If you want to specify the size for the client area, which is usually what I'm after, you need to mess with it a little. Suppose you want a window whose upper-left corner is at position (x, y), and you want a client area of xWidth by yHeight.
First, create the window with those parameters specified in the appropriate places in the call to CreateWindowEx(). The window will be a little too small, because your desired client area is the window plus all the controls. To blow it up to the correct size, use this:
The 'hwnd' in this code is the handle to your window returned by CreateWindowEx(). The first call, AdjustWindowRectEx(), calculates the RECT that defines the full window size, based on your desired client size. The second call, MoveWindow(), resizes the window to reflect the new size.
-Ironblayde
Aeon Software
Edited by - Ironblayde on September 28, 2000 10:24:27 PM
First, create the window with those parameters specified in the appropriate places in the call to CreateWindowEx(). The window will be a little too small, because your desired client area is the window plus all the controls. To blow it up to the correct size, use this:
RECT rcWindowRect = {x, y, x+xWidth, y+yHeight};AdjustWindowRectEx(&rcWindowRect, GetWindowStyle(hwnd), GetMenu(hwnd) != NULL, GetWindowExStyle(hwnd));MoveWindow(hwnd, x, y, rcWindowRect.right - rcWindowRect.left, rcWindowRect.bottom - rcWindowRect.top, TRUE);
The 'hwnd' in this code is the handle to your window returned by CreateWindowEx(). The first call, AdjustWindowRectEx(), calculates the RECT that defines the full window size, based on your desired client size. The second call, MoveWindow(), resizes the window to reflect the new size.
-Ironblayde
Aeon Software
Edited by - Ironblayde on September 28, 2000 10:24:27 PM
"Your superior intellect is no match for our puny weapons!"
Steel - You''re idea of calling GetDC(0) does not work... Doing so, and then calling GetDeviceCaps gives me a window of size 320x240. I''m running at 1024x768 so I know thats incorrect. Any other ideas anyone?
There is no spoon.
Ah, baskuenen, that''s what I was looking for! (Couldn''t remember the name of that function).
It didn''t work Orpheum? Check for errors. Not only does it work for me, but this is one of two methods Microsoft documents for such work (the other is the one baskeunen offered; it''s better!).
It didn''t work Orpheum? Check for errors. Not only does it work for me, but this is one of two methods Microsoft documents for such work (the other is the one baskeunen offered; it''s better!).
Sweet! One bug down, a million to go! Are the File and About menu''s part of the WS_POPUP style? I have a full screen display now, with the exception of the File etc bar. I used the "Create a Hello World" app option when creating my project, and then just modified the hell out of it, but even if I comment out the WM_COMMAND messages, those menu''s still appear. Where are they "installed" at? I commented out most of the damn project but they are still there. I dont know what an AccelTable is, but I''m THINKING that its about all that could be causing those menu''s to still appear. I''m working in a test bed (I''m at work), and my project at home doesn''t have those menu''s (I chose empty project there). I dont get to go home for awhile, and I dont want to wait to find out what the cause is... its driving me up the wall!
There is no spoon.
You have a menubar and you want to get rid of it? Search for a call to SetMenu and/or set the lpszMenuName member of you WNDCLASS/WNDCLASSEX structure to NULL (must be somewhere before a call to RegisterClass(Ex)).
An AccelTable is normally only used with menus. You know shortcuts like Ctrl-N to open a new browser window? They are saved in an AccelTable.
WM_COMMAND messages are only sent to notify you about a button/menu triggered. Windows gives a d*mn if or how you process the message (in truth, it cannot know what you do with them).
Check the Win32 SDK help about those WS_ styles (search somewhere in CreateWindow). If I remember correctly most of them are understandable if you just started out Windows programming and they can give you a slightly better idea of what is happening (well, at least it worked for me when I started Windows programming [with Turbo Pascal for Windows 1.5 { good old times! } ] )
An AccelTable is normally only used with menus. You know shortcuts like Ctrl-N to open a new browser window? They are saved in an AccelTable.
WM_COMMAND messages are only sent to notify you about a button/menu triggered. Windows gives a d*mn if or how you process the message (in truth, it cannot know what you do with them).
Check the Win32 SDK help about those WS_ styles (search somewhere in CreateWindow). If I remember correctly most of them are understandable if you just started out Windows programming and they can give you a slightly better idea of what is happening (well, at least it worked for me when I started Windows programming [with Turbo Pascal for Windows 1.5 { good old times! } ] )
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement