GLWindow

bool GLWindow::registerWindowClass()

Another Win32 you should look up if you don’t understand. The important part is that we set the windowProc to our static window proc.

bool
GLWindow::registerWindowClass()
{
// Register A Window Class
WNDCLASSEX windowClass; // Window Class
ZeroMemory(&windowClass, sizeof(WNDCLASSEX)); // Make Sure Memory Is Cleared
windowClass.cbSize = sizeof(WNDCLASSEX); // Size Of The windowClass Structure
windowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraws The Window For Any Movement / Resizing
windowClass.lpfnWndProc = (WNDPROC)(GLWindow::staticWindowProc); // WindowProc Handles Messages
windowClass.hInstance = hInstance; // Set The Instance
windowClass.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE); // Class Background Brush Color
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
windowClass.lpszClassName = className; // Sets The Applications Classname
if(RegisterClassEx(&windowClass) == 0) // Did Registering The Class Fail?
{
// NOTE: Failure, Should Never Happen
MessageBox(HWND_DESKTOP, "RegisterClassEx Failed!", "Error", MB_OK | MB_ICONEXCLAMATION);
return false;
}
return true;
}

void GLWindow::redirectIOToConsole()

redirectIOToConsole allows us to use printf and cout. It will spawn a window and is very helpful for anyone who, like me, does poor man’s debugging. This was found by a colleage of mine, so I don’t know the original source.

void
GLWindow::redirectIOToConsole()
{
int hConHandle;
long lStdHandle;

CONSOLE_SCREEN_BUFFER_INFO coninfo;
FILE *fp;

// allocate a console for this app
AllocConsole();

// set the screen buffer to be big enough to let us scroll text
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
coninfo.dwSize.Y = MAX_CONSOLE_LINES;
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);

// redirect unbuffered STDOUT to the console
lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
fp = _fdopen(hConHandle, "w");
*stdout = *fp;
setvbuf(stdout, NULL, _IONBF, 0);

// redirect unbuffered STDIN to the console
lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE);
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
fp = _fdopen(hConHandle, "r");
*stdin = *fp;
setvbuf(stdin, NULL, _IONBF, 0);

// redirect unbuffered STDERR to the console
lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE);
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
fp = _fdopen(hConHandle, "w");
*stderr = *fp;
setvbuf(stderr, NULL, _IONBF, 0);
}

Pages: 1 2 3 4 5 6 7 8

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>