2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG.
\r
6 * CasparCG is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * CasparCG is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
\r
24 #include "resource.h"
\r
28 using namespace utils;
\r
30 Window::Window() : _hwnd(NULL), _hinstance(NULL), _hdc(NULL)
\r
39 bool Window::Initialize(HINSTANCE hinstance, const TCHAR* windowTitle, const TCHAR* className)
\r
41 _hinstance = hinstance;
\r
42 _classname = className;
\r
44 WNDCLASSEX wndClass; // Window class
\r
45 ZeroMemory(&wndClass, sizeof(wndClass)); // Clear the window class structure
\r
46 wndClass.cbSize = sizeof(WNDCLASSEX);
\r
47 wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_CLASSDC;
\r
48 wndClass.lpfnWndProc = (WNDPROC)WndProc;
\r
49 wndClass.cbClsExtra = 0;
\r
50 wndClass.cbWndExtra = 0;
\r
51 wndClass.hInstance = _hinstance;
\r
52 wndClass.hIcon = LoadIcon(_hinstance, MAKEINTRESOURCE(IDI_ICON1));
\r
53 wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
\r
54 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
\r
55 wndClass.lpszMenuName = NULL;//MAKEINTRESOURCE(IDR_MAINMENU);
\r
56 wndClass.lpszClassName = _classname.c_str();
\r
57 wndClass.hIconSm = 0;
\r
59 if (RegisterClassEx(&wndClass) == 0)// Attemp to register the window class
\r
61 LOG << TEXT("WINDOW ERROR: Failed to register the window class!") << LogStream::Flush;
\r
64 DWORD dwStyle; // Window styles
\r
65 DWORD dwExStyle; // Extended window styles
\r
67 dwStyle = WS_OVERLAPPEDWINDOW | // Creates an overlapping window
\r
68 WS_CLIPCHILDREN | // Doesn"t draw within child windows
\r
69 WS_CLIPSIBLINGS; // Doesn"t draw within sibling windows
\r
70 dwExStyle = WS_EX_APPWINDOW | // Top level window
\r
71 WS_EX_WINDOWEDGE; // Border with a raised edge
\r
73 //adjust window size
\r
78 rMain.bottom = 576;
\r
80 AdjustWindowRect(&rMain, dwStyle, 0);
\r
82 // Attempt to create the actual window
\r
83 _hwnd = CreateWindowEx( dwExStyle, // Extended window styles
\r
84 _classname.c_str(), // Class name
\r
85 windowTitle, // Window title (caption)
\r
86 dwStyle, // Window styles
\r
87 0, 0, // Window position
\r
88 rMain.right - rMain.left,
\r
89 rMain.bottom - rMain.top, // Size of window
\r
90 0, // No parent window
\r
92 _hinstance, // Instance
\r
93 0); // Pass nothing to WM_CREATE
\r
98 LOG << TEXT("WINDOW ERROR: Unable to create window!") << LogStream::Flush;
\r
102 ShowWindow(_hwnd, SW_SHOW);
\r
103 SetForegroundWindow(_hwnd);
\r
107 //TEST: select a more appropriate pixelformat
\r
108 _hdc = ::GetDC(_hwnd);
\r
110 PIXELFORMATDESCRIPTOR pfd =
\r
112 sizeof(PIXELFORMATDESCRIPTOR), //size of struct
\r
113 1, //version number
\r
114 //PFD_DRAW_TO_WINDOW | //Format must support draw to window
\r
115 PFD_DRAW_TO_BITMAP | //Format must support draw to bitmap
\r
116 PFD_DOUBLEBUFFER_DONTCARE | //Format does not have to support doublebuffer
\r
117 PFD_DEPTH_DONTCARE, //Formet does not have to support depthbuffer
\r
118 PFD_TYPE_RGBA, //Request RGBA format
\r
120 0,0,0,0,0,0, //colorbits ignored
\r
121 8, //8-bit alpha-buffer
\r
122 0, //shift bit ignored
\r
123 0, //no accumulation-buffer
\r
124 0,0,0,0, //Accumulation bits ignored
\r
125 0, //no depth-buffer
\r
126 0, //no stencil-buffer
\r
127 0, //no auxiliary-buffer
\r
128 PFD_MAIN_PLANE, //Main drawing layer
\r
130 0,0,0 //Layer masks ignored
\r
133 unsigned int nPixelFormat = ChoosePixelFormat(_hdc, &pfd);
\r
135 if(!SetPixelFormat(_hdc, nPixelFormat, &pfd)) {
\r
139 //END TEST: select a more appropriate pixelformat
\r
141 //TEST: give flash access to a directdraw device
\r
142 IDirectDrawFactory* pDDF = NULL;
\r
144 CComBSTR ddfGUID(_T("{4FD2A832-86C8-11d0-8FCA-00C04FD9189D}"));
\r
146 HRESULT hr = CLSIDFromString((LPOLESTR)ddfGUID, &clsid);
\r
148 hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, GUID_DDFactory, (void **)&pDDF);
\r
150 pDDF->CreateDirectDraw(NULL, _hwnd, DDSCL_NORMAL, NULL, NULL, &pDD_);
\r
153 //END TEST: give flash access to a directdraw device
\r
158 void Window::Destroy()
\r
165 // Attempts to destroy the window
\r
167 DestroyWindow(_hwnd);
\r
171 // Attempts to unregister the window class
\r
172 if (!UnregisterClass(_classname.c_str(), _hinstance))
\r
174 LOG << TEXT("WINDOW ERROR: Unable to unregister window class!") << LogStream::Flush;
\r