//FullScreen Window
#include "stdafx.h"
#include "FullScreenWindow.h"
//***************************************************************************************
CFullScreen *MySelf=NULL;
//***************************************************************************************
CFullScreen::CFullScreen(HINSTANCE hInst)
{
hInstance=hInst;
this->CreateDisplay();
MySelf=this;
IsFullScreen=FALSE;
TitleBar=NULL;
}
CFullScreen::~CFullScreen()
{
if(TitleBar!=NULL)
{
delete TitleBar;
TitleBar=NULL;
}
}
//***************************************************************************************
//#define VWR_WND_CLASS_NAME _T("Kakemonster")
void CFullScreen::CreateDisplay()
{
// Create the window
WNDCLASS wndclass;
wndclass.style = 0;
wndclass.lpfnWndProc = CFullScreen::WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MAINICON));
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(GRAY_BRUSH);
wndclass.lpszMenuName = (const TCHAR *) NULL;
wndclass.lpszClassName = _T("FULLSCREENDEMO");
RegisterClass(&wndclass);
const DWORD winstyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU |
WS_MINIMIZEBOX | WS_THICKFRAME;
m_hWnd = CreateWindow(_T("FULLSCREENDEMO"),
_T("FullScreen Testwindow - Right click to make fullscreen"),
winstyle,
100,
100,
500, // x-size
300, // y-size
NULL, // Parent handle
NULL, // Menu handle
hInstance,
NULL);
//Show window at startup...
ShowWindow(m_hWnd, SW_SHOW);
//Set owner
SetWindowLong(m_hWnd, GWL_USERDATA, (LONG) this);
//Start animation timer
SetTimer(m_hWnd,0,100, NULL);
}
//***************************************************************************************
void CFullScreen::Draw()
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(m_hWnd, &ps);
RECT lpRect;
HBRUSH Brush;
::GetClientRect(m_hWnd,&lpRect);
::SetBkMode(hdc, TRANSPARENT);
if(IsFullScreen==FALSE)
{
Brush=::CreateSolidBrush(RGB(255,255,255));
::FillRect(hdc,&lpRect,Brush);
LPSTR Text="Visit http://lars.werner.no for more sourcecode and utils";
TextOut(hdc,0,lpRect.bottom-20,Text,::lstrlen(Text));
}
else
{
Brush=::CreateSolidBrush(RGB(128,128,128));
::FillRect(hdc,&lpRect,Brush);
LPSTR Text="Visit http://lars.werner.no for more sourcecode and utils";
TextOut(hdc,lpRect.right/2-180,lpRect.bottom/2,Text,::lstrlen(Text));
Text="Use the pin to make the Titlebar hide";
TextOut(hdc,0,lpRect.top+20,Text,::lstrlen(Text));
}
EndPaint(m_hWnd, &ps);
DeleteObject(Brush);
}
//***************************************************************************************
LRESULT CALLBACK CFullScreen::WndProc(HWND hwnd, UINT iMsg,
WPARAM wParam, LPARAM lParam)
{
switch (iMsg)
{
case WM_CREATE:
return 0;
case WM_PAINT:
{
MySelf->Draw();
return 0;
}
case WM_ERASEBKGND:
return 0;
case WM_CLOSE:
{
// Close the worker thread as well
HWND Window=MySelf->GetSafeHwnd();
DestroyWindow(Window);
PostQuitMessage(0);
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
case WM_RBUTTONDOWN:
{
//Create titlebar
if(MySelf!=NULL)
{
if(MySelf->TitleBar==NULL)
MySelf->TitleBar=new CTitleBar(MySelf->hInstance, MySelf->m_hWnd);
MySelf->TitleBar->SetText("http://lars.werner.no");
}
if(MySelf->IsFullScreen==FALSE)
MySelf->SetFullScreen(TRUE); //Set fullscreen on!
else
MySelf->SetFullScreen(FALSE); //Set fullscreen on!
return 0;
}
case WM_SIZE:
if(MySelf!=NULL)
::InvalidateRect(MySelf->m_hWnd, NULL,TRUE);
break;
//Own messages from titlebar!
case tbWM_CLOSE:
{
HWND Window=MySelf->GetSafeHwnd();
DestroyWindow(Window);
PostQuitMessage(0);
return 0;
}
case tbWM_MINIMIZE:
ShowWindow(MySelf->GetSafeHwnd(), SW_MINIMIZE);
break;
case tbWM_MAXIMIZE:
{
if(MySelf->IsFullScreen==FALSE)
MySelf->SetFullScreen(TRUE); //Set fullscreen on!
else
MySelf->SetFullScreen(FALSE); //Set fullscreen on!
return 0;
}
//Menu spesific entries!
case WM_USER+tbWMUSERID:
MessageBox(MySelf->m_hWnd, "Item 0 presset!","NULL",MB_OK);
break;
case WM_USER+tbWMUSERID+1:
MessageBox(MySelf->m_hWnd, "Item 1: CTRL-ALT-DELETE","NULL",MB_OK);
break;
}//Case - end
return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
//***************************************************************************************
void CFullScreen::SetFullScreen(BOOL OnOff)
{
LONG style = GetWindowLong(m_hWnd, GWL_STYLE);
if(OnOff==TRUE)
{
ShowWindow(m_hWnd, SW_MAXIMIZE);
style = GetWindowLong(m_hWnd, GWL_STYLE);
style &= ~(WS_DLGFRAME | WS_THICKFRAME);
SetWindowLong(m_hWnd, GWL_STYLE, style);
int cx = GetSystemMetrics(SM_CXSCREEN);
int cy = GetSystemMetrics(SM_CYSCREEN);
SetWindowPos(m_hWnd, HWND_TOPMOST, -1, -1, cx+3, cy+3, SWP_FRAMECHANGED);
IsFullScreen=TRUE;
TitleBar->DisplayWindow(TRUE, TRUE);
::InvalidateRect(m_hWnd,NULL,TRUE);
}
else //OFF!
{
style |= WS_DLGFRAME | WS_THICKFRAME;
SetWindowLong(m_hWnd, GWL_STYLE, style);
SetWindowPos(m_hWnd, HWND_NOTOPMOST, 0,0,100,100, SWP_NOMOVE | SWP_NOSIZE);
ShowWindow(m_hWnd, SW_NORMAL);
IsFullScreen=FALSE;
TitleBar->DisplayWindow(FALSE, TRUE);
::InvalidateRect(m_hWnd,NULL,TRUE);
}
}
//***************************************************************************************