00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "screen.h"
00020 #include "MyDebug.h"
00021 #include "openGL_tools.h"
00022
00023 #define DEBUG_SCREEN(methode) MyDebug::SendEvent("screen",methode##"[t:%s,style:%d,styleEx:%d,dXNorm:%d,%d,dXCli:%d,%d]",(char *)title,dwStyle,dwExStyle,dxNormal,dyNormal,dxClient,dyClient)
00024
00025
00026 #define TEST(varType,msg) if ((dwStyle&varType)==varType) { for (int i=0;i<level;i++) message<<"| "; message<<msg<<"\n"; }
00027 #define TEST_EX(varType,msg) if ((dwExStyle&varType)==varType) { for (int i=0;i<level;i++) message<<"| "; message<<msg<<"\n"; }
00028
00029
00030 #define WS_EX_COMPOSITED 0x02000000L
00031 #define WS_EX_NOACTIVATE 0x08000000L
00032 #define WS_EX_LAYERED 0x00080000
00033
00034 void Screen::ComputeDeltaClientToWindow()
00035 {
00036 RECT rectClient,rectWindow;
00037 GetClientRect(hWnd,&rectClient);
00038 GetWindowRect(hWnd,&rectWindow);
00039
00040 dxWC=(rectWindow.right-rectWindow.left)-(rectClient.right-rectClient.left);
00041 dyWC=(rectWindow.bottom-rectWindow.top)-(rectClient.bottom-rectClient.top);
00042 }
00043
00044 #include <winuser.h>
00045 void Screen::MsgInfoType()
00046 {
00047 MyString message;
00048
00049 int level=0;
00050 message.Format("Type=%ld, Ex=%ld\n",dwStyle,dwExStyle);
00051 message<<"STYLE:\n"; level++;
00052 BOOL overlappedWindow = (dwStyle&WS_OVERLAPPEDWINDOW)==WS_OVERLAPPEDWINDOW;
00053 BOOL popupWind = (dwStyle&WS_POPUPWINDOW)==WS_POPUPWINDOW;
00054 BOOL caption = (dwStyle&WS_CAPTION)==WS_CAPTION;
00055 TEST(WS_OVERLAPPEDWINDOW,"overlappedWindow: Creates an overlapped window.");
00056 TEST(WS_POPUPWINDOW,"popupWindow: Creates a pop-up window.");
00057 if (popupWind||overlappedWindow) level++;
00058 TEST(WS_CAPTION,"caption: title bar.");
00059 if (caption) level++;
00060 TEST(WS_BORDER,"border: thin-line border.");
00061 if (caption) level--;
00062 TEST(WS_OVERLAPPED,"overlapped: window has a title bar and a border.");
00063 TEST(WS_POPUP,"popupWindow: simple window (cannot used with the WS_CHILD).");
00064 TEST(WS_SYSMENU,"sysmenu: add menu on its title bar. (use WS_CAPTION).");
00065 TEST(WS_THICKFRAME,"tickFrame: add a sizing border.");
00066 TEST(WS_MAXIMIZEBOX,"maximizeBox: add max button. (use WS_SYSMENU , cannot WS_EX_CONTEXTHELP)");
00067 TEST(WS_MINIMIZEBOX,"minimizeBox: add min button. (use WS_SYSMENU , cannot WS_EX_CONTEXTHELP)");
00068 if (popupWind||overlappedWindow) level--;
00069 TEST(WS_CHILD ,"child: A window with this style cannot have a menu bar. (cannot used WS_POPUP)");
00070 TEST(WS_CLIPCHILDREN,"clipChildren: used when creating the parent window");
00071 TEST(WS_CLIPSIBLINGS,"clipSiblings: clips child windows relative to each other)");
00072 TEST(WS_DISABLED,"disable: initially disabled. He cannot receive input from the user. (cf EnableWindow)");
00073 TEST(WS_VISIBLE,"visible: initially visible.");
00074 TEST(WS_DLGFRAME,"dlgFrame: window that has a border of a style typically used with dialog boxes. (cannot have a title bar)");
00075 TEST(WS_GROUP,"group: Specifies the first control of a group of controls. (cf WS_TABSTOP style)");
00076 TEST(WS_TABSTOP,"tabStop: can receive the keyboard focus when the user presses the TAB key. (cf WS_TABSTOP style)");
00077 TEST(WS_HSCROLL,"hScroll: add horizontal scroll bar.");
00078 TEST(WS_VSCROLL,"vScroll: add vertical scroll bar.");
00079 TEST(WS_MAXIMIZE,"maxmize: initially maximized.");
00080 TEST(WS_MINIMIZE,"minimize: initially minimized.");
00081
00082 message<<"STYLE_EX:\n";
00083
00084 TEST_EX(WS_EX_RIGHT,"right: the window has generic.");
00085 TEST_EX(WS_EX_LEFT,"left: left-aligned properties.");
00086
00087 DWORD paletteWindow = (dwStyle&WS_EX_PALETTEWINDOW)==WS_EX_PALETTEWINDOW;
00088 DWORD overlappedWindowEx = (dwStyle&WS_EX_PALETTEWINDOW)==WS_EX_PALETTEWINDOW;
00089 TEST_EX(WS_EX_PALETTEWINDOW,"paletteWindow: combines WS_EX_WINDOWEDGE, WS_EX_TOOLWINDOW, WS_EX_TOPMOST.");
00090 TEST_EX(WS_EX_OVERLAPPEDWINDOW,"overlappedWindow: combines WS_EX_CLIENTEDGE and WS_EX_WINDOWEDGE.");
00091 if (paletteWindow||overlappedWindowEx) level++;
00092 TEST_EX(WS_EX_WINDOWEDGE,"windowEdge: specifies that a window has a border with a raised edge.");
00093 TEST_EX(WS_EX_TOOLWINDOW,"toolWindow: creates a floating toolbar. (not appear in the taskbar.");
00094 TEST_EX(WS_EX_TOPMOST,"topMost: should be placed above all non-topmost windows and should stay above them.");
00095 TEST_EX(WS_EX_CLIENTEDGE,"clientEdge: border with a sunken edge.");
00096 if (paletteWindow||overlappedWindowEx) level--;
00097 TEST_EX(WS_EX_ACCEPTFILES,"acceptFiles: accepts drag-drop files.");
00098 TEST_EX(WS_EX_APPWINDOW,"appWindow: forces a top-level window onto the taskbar when the window is visible.");
00099 TEST_EX(WS_EX_COMPOSITED,"composited: paints all descendants of a window in bottom-to-top painting order using double-buffering. ");
00100 TEST_EX(WS_EX_CONTEXTHELP,"contextHelp: Add a question mark in the title bar ( cannot use WS_MAXIMIZEBOX or WS_MINIMIZEBOX)");
00101 TEST_EX(WS_EX_CONTROLPARENT,"controlParent: contains itself a child windows that should take part in dialog box navigation.");
00102 TEST_EX(WS_EX_DLGMODALFRAME,"dlgModalFrame: use double border.");
00103 TEST_EX(WS_EX_LAYERED,"layered: layered window. (cannot used with child)");
00104 TEST_EX(WS_EX_LAYOUTRTL,"layoutRTL: Arabic and Hebrew versions." );
00105 TEST_EX(WS_EX_LTRREADING,"ltrReading: text is displayed using left-to-right reading-order properties. This is the default.");
00106 TEST_EX(WS_EX_LEFTSCROLLBAR,"leftsScrollBar: use if the shell language is right-to-left reading order alignment.");
00107 TEST_EX(WS_EX_MDICHILD,"Creates a multiple-document interface (MDI) child window.");
00108 TEST_EX(WS_EX_NOACTIVATE,"noActivate: this top-level Window does not become the foreground window when the user clicks it. (does not appear on the taskbar cf.: WS_EX_APPWINDOW) [Windows 2000/XP]");
00109 TEST_EX(WS_EX_NOINHERITLAYOUT,"noInheritLayout: does not pass its window layout to its child windows. [Windows 2000/XP]");
00110 TEST_EX(WS_EX_NOPARENTNOTIFY,"noParentNotify: specifies that a child window does not send the WM_PARENTNOTIFY message to its parent window.");
00111 TEST_EX(WS_EX_RIGHTSCROLLBAR,"rightsScrollBar: vertical scroll bar (if present) is to the right of the client area.");
00112 TEST_EX(WS_EX_STATICEDGE,"staticEdge: three-dimensional border style intended to be used for items that do not accept user input.");
00113 TEST_EX(WS_EX_TRANSPARENT,"transparent: appears transparent because the bits of underlying sibling windows have already been painted.");
00114 MessageBox(NULL,message,"Info: style window",0);
00115 }
00116
00117 Screen::Screen()
00118 {
00119 DEBUG_SCREEN("Constructor");
00120 hWnd=NULL;
00121 hWndInsertAfter=NULL;
00122 hInst=NULL;
00123 dwStyle=WS_POPUP;
00124 dwExStyle=NULL;
00125 dxNormal = dyNormal = dxClient= dyClient = 0;
00126 dxFull = GetSystemMetrics(SM_CXSCREEN);
00127 dyFull = GetSystemMetrics(SM_CYSCREEN);
00128 xNormal=yNormal=0;
00129 enableTitle=FALSE;
00130 enableFullScreen=FALSE;
00131 enableFullScreenOld=-1;
00132 hDC = NULL;
00133 hGLRC = NULL;
00134 }
00135
00136 Screen::~Screen()
00137 {
00138 DEBUG_SCREEN("Destructor");
00139 Destroy();
00140 }
00141
00142 BOOL Screen::Setup(WNDCLASS *wc,char *_className,char *_title)
00143 {
00144 className=_className;
00145 title=_title;
00146 wc->lpszClassName = TEXT (className);
00147 if (!::RegisterClass(wc))
00148 {
00149 MyString msg;
00150 msg<<"Can't register window \""<<className<<"\"";
00151 MessageBox (NULL,msg,"RegisterClass - Failed",MB_OK);
00152 return FALSE;
00153 }
00154 DEBUG_SCREEN("Setup");
00155 return TRUE;
00156 }
00157
00159 BOOL Screen::SwapBuffers()
00160 {
00161 return ::SwapBuffers(hDC);
00162 }
00163
00165 BOOL Screen::Create(HINSTANCE hInstance)
00166 {
00167 hInst = hInstance;
00168 SetFullScreen();
00169
00170 hWnd = CreateWindowEx(dwExStyle,className,title, dwStyle,0,0,dxClient,dyClient,NULL, NULL, hInst,NULL);
00171 if (!hWnd)
00172 {
00173 MyString msg;
00174 msg<<"Can't create window \""<<title<<"\"";
00175 MessageBox (NULL,msg,"CreateWindow - Failed",MB_OK);
00176 return FALSE;
00177 }
00178 if (!enableFullScreen) ApplySize();
00179 SetTopMost();
00180 DEBUG_SCREEN("Create");
00181 return TRUE;
00182 }
00183
00184 void Screen::Destroy()
00185 {
00186 DEBUG_SCREEN("Destroy");
00187 SendMessage(hWnd,WM_QUIT,0,0);
00188 if (hWnd) UnregisterClass(className,hInst);
00189 hWnd=NULL;
00190 if (hGLRC)
00191 {
00192 wglMakeCurrent(NULL, NULL);
00193 wglDeleteContext(hGLRC);
00194 }
00195 if (hDC) { ReleaseDC(hWnd, hDC); hDC = NULL; }
00196
00197 }
00198
00199 void Screen::Show(BOOL enable)
00200 {
00201 if (enable) ShowWindow(hWnd,SW_SHOW);
00202 else ShowWindow(hWnd,SW_HIDE);
00203 DEBUG_SCREEN("Show");
00204 }
00205
00206 void Screen::Update(BOOL applySize)
00207 {
00208 SetFullScreen();
00209 ApplyStyles();
00210 if (enableTitle) SetWindowText(hWnd,title);
00211 SetTopMost();
00212 if (applySize) ApplySize();
00213 DEBUG_SCREEN("Update");
00214 }
00215
00217 void Screen::ApplySize()
00218 {
00219 ComputeDeltaClientToWindow();
00220 int dx,dy;
00221 dx=dxClient+dxWC;
00222 dy=dyClient+dyWC;
00223 SetWindowPos(hWnd,NULL,0,0,dx,dy,SWP_NOZORDER|(enableFullScreen?0:SWP_NOMOVE));
00224 DEBUG_SCREEN("ApplySize");
00225 }
00226
00227 #include "windowTools.h"
00228
00236 void Screen::SetFullScreen()
00237 {
00238 BOOL result=FALSE;
00239
00240 if (enableFullScreenOld!=enableFullScreen)
00241 {
00242 enableFullScreenOld=enableFullScreen;
00243 if (enableFullScreen)
00244 {
00245 dxNormal=dxClient;
00246 dyNormal=dyClient;
00247 dxClient=dxFull;
00248 dyClient=dyFull;
00249
00250 GetWindowPos(hWnd,&xNormal,&yNormal);
00251 }
00252 else
00253 {
00254 dxClient=dxNormal;
00255 dyClient=dyNormal;
00256
00257 SetWindowPos(hWnd,NULL,xNormal,yNormal,0,0,SWP_NOZORDER|SWP_NOSIZE);
00258 }
00259 }
00260 if (enableFullScreen||!enableTitle) SetStyle(WS_POPUP);
00261 else SetStyle (WS_OVERLAPPEDWINDOW);
00262
00263
00264 DEBUG_SCREEN("SetFullScreen");
00265 }
00266
00267 void Screen::BindOpenGL(BOOL useAccumulation)
00268 {
00269
00270
00271 static PIXELFORMATDESCRIPTOR pfd =
00272 {
00273 sizeof(PIXELFORMATDESCRIPTOR),
00274 1,
00275 PFD_DRAW_TO_WINDOW |
00276 PFD_SUPPORT_OPENGL |
00277 PFD_DOUBLEBUFFER,
00278 PFD_TYPE_RGBA,
00279 24,
00280 0, 0, 0, 0, 0, 0,
00281 0,
00282 0,
00283 useAccumulation?24:0,
00284 useAccumulation?8:0,
00285 useAccumulation?8:0,
00286 useAccumulation?8:0,
00287 0,
00288 24,
00289 0,
00290 0,
00291 PFD_MAIN_PLANE,
00292 0,
00293 0, 0, 0
00294 };
00295
00296 hDC = GetDC(hWnd);
00297
00298
00299 int pixelFormat = OpenGL_InitMultisample(hWnd);
00300 if (!pixelFormat) pixelFormat = ChoosePixelFormat(hDC, &pfd);
00301
00302 SetPixelFormat(hDC, pixelFormat, &pfd);
00303 hGLRC = wglCreateContext(hDC);
00304 wglMakeCurrent(hDC, hGLRC);
00305 }
00306
00307 void Screen::SetTitle(char *_title)
00308 {
00309 title=_title;
00310 }
00311
00312 void Screen::SetTopMost()
00313 {
00314 hWndInsertAfter = enableFullScreen? HWND_TOPMOST : NULL;
00315 SetWindowPos(hWnd,hWndInsertAfter,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
00316 }
00317
00318 void Screen::SetSize(int dx,int dy,BOOL always)
00319 {
00320 if (!enableFullScreen||always)
00321 {
00322 dxClient = dx;
00323 dyClient = dy;
00324 dxNormal = dx;
00325 dyNormal = dy;
00326 DEBUG_SCREEN("SetSize");
00327 }
00328 }
00329
00330 void Screen::ChangeStyle(int set,DWORD dwStyleChange)
00331 {
00332 dwStyle|=dwStyleChange;
00333 if (!set) dwStyle-=dwStyleChange;
00334 }
00335
00336 void Screen::ChangeStyleEx(int set,DWORD dwStyleChange)
00337 {
00338 dwExStyle|=dwStyleChange;
00339 if (!set) dwExStyle-=dwStyleChange;
00340 }
00341
00342 void Screen::ApplyStyles()
00343 {
00344 ApplyStyle();
00345 ApplyStyleEx();
00346 SetWindowPos(hWnd,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED);
00347 }
00348
00349 void Screen::SetStyle(DWORD _dwStyle)
00350 {
00351 dwStyle=_dwStyle;
00352 }
00353
00354 void Screen::ApplyStyle()
00355 {
00356 SetWindowLong(hWnd,GWL_STYLE,dwStyle);
00357 }
00358
00359 void Screen::ApplyStyleEx()
00360 {
00361 SetWindowLong(hWnd,GWL_EXSTYLE,dwExStyle);
00362 }
00363
00364 void Screen::RegionReset()
00365 {
00366 region.Reset(dxClient,dyClient);
00367 }
00368
00369 void Screen::RegionUse()
00370 {
00371 region.Use(hWnd);
00372 }
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391