-
March 13th, 2010, 05:15 AM
#1
C++ Windows programming, full-screen
Hey, I'm trying to get a script where some C++ makes the window turn full-screen... And well, I'm finding it stupidly hard. Everything I search on Google just... Plain doesn't work, outdated code maybe?
Anyway
Code:
#include "stdafx.h"
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow);
bool m_bFullScreen = true;
DWORD dwStyle;
DEVMODE best;
bool FindBestDisplayMode(DEVMODE &best, DWORD width, DWORD height, DWORD bpp)
{
DEVMODE dm = {0};
dm.dmSize = sizeof(DEVMODE);
DWORD n, maxFreq = 0;
bool found = false;
for (n = 0; EnumDisplaySettings(NULL, n, &dm); n++)
{
if ((dm.dmPelsWidth == width) &&
(dm.dmPelsHeight == height) &&
(dm.dmBitsPerPel == bpp))
{
found = true;
if (dm.dmDisplayFrequency > maxFreq)
{
maxFreq = dm.dmDisplayFrequency;
best = dm;
}//if
}//if
}//for
return found;
}//FindBestDisplayMode
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow){
FindBestDisplayMode(best, 800, 600, 32);
if(m_bFullScreen){
if(ChangeDisplaySettings(&best, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL){
MessageBox(NULL, L"Display mode failed", NULL, MB_OK);
m_bFullScreen = false;
}
}
if(m_bFullScreen){
dwStyle = WS_POPUP;
MessageBox(NULL, L"Display mode not failed", NULL, MB_OK);
}
else{
dwStyle = WS_OVERLAPPEDWINDOW;
MessageBox(NULL, L"Display mode failed", NULL, MB_OK);
}
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = L"ClassName";
wc.lpszMenuName = 0;
wc.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wc);
HWND hwnd = CreateWindow(
L"ClassName",
L"Title",
dwStyle,
0, 0,
800, 600,
NULL, NULL,
hInstance, NULL
);
ShowWindow(hwnd, iCmdShow );
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg, NULL, 0, 0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam){
switch(message){
case WM_PAINT:{
HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint(hwnd, &ps);
Ellipse(hdc, 20, 20, 160, 160);
Rectangle(hdc, 50, 50, 90, 90);
Rectangle(hdc, 200, 50, 140, 90);
EndPaint(hwnd, &ps);
}
return 0;
break;
case WM_DESTROY:
PostQuitMessage(0) ;
return 0;
break;
}
return DefWindowProc(hwnd, message, wparam, lparam);
}
That is my code. I had been putting in the DEVMODE manually, but someone told me I should get a function to find out the values for me... Either way outputs the same result, my screen goes black - and then nothing happens. I have to turn my PC off and try again.
(I'm using Visual C++ 2008 Express Edition, running on Windows 7 - just in case that does make a difference)
I would really appreciate a hand, thanks if anyone can help
-
March 13th, 2010, 05:19 AM
#2
Re: C++ Windows programming, full-screen
Just as a note, here's what my manually-inputted DEVMODE code looks like, that still just produced a black screen.
Code:
DEVMODE screen;
DWORD dwStyle, dwExStyle;
memset(&screen,0,sizeof(screen));
screen.dmSize = sizeof(screen);
screen.dmPelsWidth = 800;
screen.dmPelsHeight = 600;
screen.dmBitsPerPel = 32;
screen.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
if(ChangeDisplaySettings(&screen, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL){
dwExStyle = WS_EX_APPWINDOW;
dwStyle = WS_POPUP;
ShowCursor(FALSE);
}
else{
dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
dwStyle = WS_OVERLAPPEDWINDOW;
}
-
March 13th, 2010, 08:42 AM
#3
Re: C++ Windows programming, full-screen
When screen go black like that it's something really bad with the settings. Since you're setting a quite low resolution I would say that the refresh rate is probably way to high. Try hardcoding it to something like 60 Hz just to check if that's the root cause.
-
March 13th, 2010, 09:11 AM
#4
Re: C++ Windows programming, full-screen
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|