1 #ifndef __cxxtest__Win32Gui_h__ 2 #define __cxxtest__Win32Gui_h__ 79 WaitForSingleObject(
_gui, INFINITE );
108 _startMinimized = _keep =
false;
111 for (
int i = 1;
i < argc; ++
i )
113 if ( !lstrcmpA( argv[
i],
"-minimized" ) )
114 _startMinimized =
true;
115 else if ( !lstrcmpA( argv[i],
"-keep" ) )
117 else if ( !lstrcmpA( argv[i],
"-title" ) && (i + 1 < argc) )
138 WaitForSingleObject( _canStartTests, INFINITE );
165 _windowClass.style = CS_HREDRAW | CS_VREDRAW;
167 _windowClass.cbClsExtra = 0;
168 _windowClass.cbWndExtra =
sizeof(
LONG);
169 _windowClass.hInstance = (HINSTANCE)
NULL;
170 _windowClass.hIcon = (HICON)
NULL;
171 _windowClass.hCursor = (HCURSOR)
NULL;
172 _windowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
173 _windowClass.lpszMenuName =
NULL;
174 _windowClass.lpszClassName = TEXT(
"CxxTest Window Class");
175 _windowClass.hIconSm = (HICON)
NULL;
177 RegisterClassEx( &_windowClass );
182 _mainWindow =
createWindow( _windowClass.lpszClassName, WS_OVERLAPPEDWINDOW );
187 HMODULE dll = LoadLibraryA(
"comctl32.dll" );
191 typedef void (WINAPI *FUNC)( void );
192 FUNC func = (FUNC)GetProcAddress( dll,
"InitCommonControls" );
201 _progressBar =
createWindow( PROGRESS_CLASS, WS_CHILD | WS_VISIBLE | PBS_SMOOTH, _mainWindow );
203 #ifdef PBM_SETRANGE32 205 #else // No PBM_SETRANGE32, use PBM_SETRANGE 207 #endif // PBM_SETRANGE32 211 UpdateWindow( _progressBar );
216 _statusBar =
createWindow( STATUSCLASSNAME, WS_CHILD | WS_VISIBLE, _mainWindow );
220 void setRatios(
unsigned suiteNameRatio,
unsigned suiteTimeRatio,
221 unsigned testNameRatio,
unsigned testTimeRatio,
222 unsigned testsDoneRatio,
unsigned worldTimeRatio )
235 return CreateWindow( className, NULL, style, 0, 0, 0, 0, parent,
236 (HMENU)NULL, (HINSTANCE)NULL, (LPVOID)
this );
241 SendMessage( _progressBar, message, wParam, lParam );
249 LONG screenWidth = screen.right - screen.left;
250 LONG screenHeight = screen.bottom - screen.top;
252 LONG xCenter = (screen.right + screen.left) / 2;
253 LONG yCenter = (screen.bottom + screen.top) / 2;
255 LONG windowWidth = (screenWidth * 4) / 5;
256 LONG windowHeight = screenHeight / 10;
257 LONG minimumHeight = 2 * (GetSystemMetrics( SM_CYCAPTION ) + GetSystemMetrics( SM_CYFRAME ));
258 if ( windowHeight < minimumHeight )
259 windowHeight = minimumHeight;
261 SetWindowPos( _mainWindow, HWND_TOP,
262 xCenter - (windowWidth / 2), yCenter - (windowHeight / 2),
263 windowWidth, windowHeight, 0 );
274 return (SystemParametersInfo( SPI_GETWORKAREA,
sizeof(RECT), &area, 0 ) != 0);
279 area.left = area.top = 0;
280 area.right = GetSystemMetrics( SM_CXSCREEN );
281 area.bottom = GetSystemMetrics( SM_CYSCREEN );
287 UpdateWindow( _mainWindow );
292 ShowWindow( _mainWindow, mode );
299 reset( _worldStart );
300 reset( _suiteStart );
307 tick = GetTickCount();
312 SetEvent( _canStartTests );
318 while ( BOOL haveMessage = GetMessage( &message,
NULL, 0, 0 ) )
319 if ( haveMessage != -1 )
320 DispatchMessage( &message );
325 if ( message == WM_CREATE )
326 setUp( window, (LPCREATESTRUCT)lParam );
329 return that->
handle( window, message, wParam, lParam );
334 SetWindowLong( window, GWL_USERDATA, (
LONG)create->lpCreateParams );
350 default:
return DefWindowProc( window, message, wParam, lParam );
358 GetClientRect( _mainWindow, &r );
359 LONG width = r.right - r.left;
360 LONG height = r.bottom - r.top;
362 GetClientRect( _statusBar, &r );
363 LONG statusHeight = r.bottom - r.top;
364 LONG resizeGripWidth = statusHeight;
365 LONG progressHeight = height - statusHeight;
367 SetWindowPos( _progressBar, HWND_TOP, 0, 0, width, progressHeight, 0 );
368 SetWindowPos( _statusBar, HWND_TOP, 0, progressHeight, width, statusHeight, 0 );
382 SendMessage( _statusBar, message, wParam, (LPARAM)lParam );
391 #ifdef PBM_SETBARCOLOR 392 void setColor( BYTE red, BYTE green, BYTE blue )
396 #else // !PBM_SETBARCOLOR 400 #endif // PBM_SETBARCOLOR 404 SendMessage( _mainWindow, WM_SETICON, ICON_BIG, (LPARAM)
loadStandardIcon( icon ) );
409 return LoadIcon( (HINSTANCE)
NULL, icon );
414 setCaption( suiteName,
"::", testName,
"()" );
417 void setCaption(
const char *
a =
"",
const char *
b =
"",
const char *c =
"",
const char *d =
"" )
419 unsigned length = lstrlenA( _title ) +
sizeof(
" - " ) +
420 lstrlenA(
a ) + lstrlenA(
b ) + lstrlenA( c ) + lstrlenA( d );
422 lstrcpyA( name, _title );
423 lstrcatA( name,
" - " );
428 SetWindowTextA( _mainWindow, name );
445 _testsDone, _strTotalTests,
446 (_testsDone * 100) / _numTotalTests );
459 unsigned total = (GetTickCount() - start) / 1000;
460 unsigned hours = total / 3600;
461 unsigned minutes = (total / 60) % 60;
462 unsigned seconds = total % 60;
465 wsprintfA(
_timeString,
"%u:%02u:%02u", hours, minutes, seconds );
467 wsprintfA(
_timeString,
"%02u:%02u", minutes, seconds );
476 if ( !_startMinimized )
478 return (_mainWindow == GetForegroundWindow());
504 const char *tests = (_numTotalTests == 1) ?
"test" :
"tests";
521 return (
char *)HeapAlloc( GetProcessHeap(), 0, length );
526 HeapFree( GetProcessHeap(), 0, data );
531 #endif // __cxxtest__Win32Gui_h__ void getTotalTests(const WorldDescription &wd)
char _statusTestsDone[sizeof("1000000000 of (100%)")+WorldDescription::MAX_STRLEN_TOTAL_TESTS]
void setIcon(LPCTSTR icon)
void setStatusTime(unsigned part, DWORD start)
LRESULT handle(HWND window, UINT message, WPARAM wParam, LPARAM lParam)
void message(int i, int *reduc, int *olddeg, kStrategy strat, int red_result)
HWND createWindow(LPCTSTR className, DWORD style, HWND parent=(HWND) NULL)
char _timeString[sizeof("00:00:00")]
void parseCommandLine(int argc, char **argv)
void registerWindowClass()
void setCaption(const char *a="", const char *b="", const char *c="", const char *d="")
HICON loadStandardIcon(LPCTSTR icon)
void getWholeScreenArea(RECT &area)
void setStatusParts(LONG width)
unsigned failedTests() const
void deallocate(char *data)
void setSummaryStatusBar()
char * allocate(unsigned length)
void showTestName(const char *testName)
void enterWorld(const WorldDescription &wd)
static DWORD WINAPI guiThread(LPVOID parameter)
void guiEnterSuite(const char *suiteName)
static LRESULT CALLBACK windowProcedure(HWND window, UINT message, WPARAM wParam, LPARAM lParam)
char name(const Variable &v)
char _strTotalTests[WorldDescription::MAX_STRLEN_TOTAL_TESTS]
int _statusWidths[STATUS_TOTAL_PARTS]
void guiEnterTest(const char *suiteName, const char *testName)
void setTestCaption(const char *suiteName, const char *testName)
void showMainWindow(int mode)
void setColor(BYTE, BYTE, BYTE)
void enterGui(int &argc, char **argv)
virtual unsigned numTotalTests(void) const =0
void initCommonControls()
unsigned _statusOffsets[STATUS_TOTAL_PARTS]
void getScreenArea(RECT &area)
void showSuiteName(const char *suiteName)
static void setUp(HWND window, LPCREATESTRUCT create)
void statusBarMessage(UINT message, WPARAM wParam=0, const void *lParam=0)
char * strTotalTests(char *) const
void setStatusPart(unsigned part, const char *text)
bool getScreenAreaWithoutTaskbar(RECT &area)
void progressBarMessage(UINT message, WPARAM wParam=0, LPARAM lParam=0)
void setRatios(unsigned suiteNameRatio, unsigned suiteTimeRatio, unsigned testNameRatio, unsigned testTimeRatio, unsigned testsDoneRatio, unsigned worldTimeRatio)