Display: C/C++ Version
The C/C++ version of Display uses CreateWindowEx() instead of CreateWindow() to create the 800x600 borderless window. Further, it calls ShowWindow() in the WM_CREATE handler to make the window visible before calling fg_modetest() or fg_modeset().
/****************************************************************************\
* *
* Display.c *
* *
* This program resizes the desktop to 800x600 using the fg_modeset() *
* function. *
* *
\****************************************************************************/
#include <fgwin.h>
#define vbWidth 800
#define vbHeight 600
LRESULT CALLBACK WindowProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdParam, int iCmdShow)
{
static char szAppName[] = "FGdisplay";
HWND hWnd;
MSG msg;
WNDCLASSEX wndclass;
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wndclass.lpfnWndProc = WindowProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground = NULL;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
wndclass.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
RegisterClassEx(&wndclass);
hWnd = CreateWindowEx(
WS_EX_TOPMOST, // extended window style
szAppName, // window class name
"Change Display Settings", // window caption
WS_POPUP, // window style
0, // initial x position
0, // initial y position
vbWidth, // initial x size
vbHeight, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL); // creation parameters
ShowWindow(hWnd,iCmdShow);
UpdateWindow(hWnd);
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
/****************************************************************************\
* *
* WindowProc() *
* *
\****************************************************************************/
HDC hDC;
HPALETTE hPal;
int hVB;
LRESULT CALLBACK WindowProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
switch (iMsg)
{
case WM_CREATE:
ShowWindow(hWnd,SW_SHOWNORMAL);
if (fg_modetest(vbWidth,vbHeight,fg_colors()) != 0)
{
MessageBox(hWnd,"Cannot set 800x600 desktop","Error",MB_OK|MB_ICONSTOP);
DestroyWindow(hWnd);
return 0;
}
fg_modeset(vbWidth,vbHeight,fg_colors(),1);
hDC = GetDC(hWnd);
fg_setdc(hDC);
hPal = fg_defpal();
fg_realize(hPal);
fg_vbinit();
hVB = fg_vballoc(vbWidth,vbHeight);
fg_vbopen(hVB);
fg_vbcolors();
fg_setcolor(19);
fg_fillpage();
return 0;
case WM_KEYDOWN:
switch(wParam)
{
case VK_ESCAPE:
case VK_F12:
DestroyWindow(hWnd);
break;
}
return 0;
case WM_PAINT:
BeginPaint(hWnd,&ps);
fg_vbpaste(0,vbWidth-1,0,vbHeight-1,0,vbHeight-1);
EndPaint(hWnd,&ps);
return 0;
case WM_SETFOCUS:
fg_realize(hPal);
InvalidateRect(hWnd,NULL,TRUE);
return 0;
case WM_DESTROY:
fg_vbclose();
fg_vbfree(hVB);
fg_vbfin();
DeleteObject(hPal);
ReleaseDC(hWnd,hDC);
fg_modeset(0,0,0,0);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd,iMsg,wParam,lParam);
}
|