GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: Add Line Numbers


The main program too by jnighthawk
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <string>
#include <vector>
#include <winsock.h>
#include <fstream>
#include "cBuffer.h"

#define ClassName "DJSTest"
#define WindowName "DJ's Test"

#define RedTile            0;
#define BlackTile        1;
#define RedChecker        2;
#define BlackChecker    3;

LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam);

HWND hWnd;
WNDCLASSEX WndClassEx;
MSG Msg;

cBuffer Buffer;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevINstance, LPSTR lpCmdLine, int nShowCmd)
{
    WndClassEx.cbSize = sizeof(WndClassEx);
    WndClassEx.style = CS_HREDRAW | CS_VREDRAW;
    WndClassEx.lpfnWndProc = WndProc;
    WndClassEx.cbClsExtra = 0;
    WndClassEx.cbWndExtra = 0;
    WndClassEx.hInstance = hInstance;
    WndClassEx.hCursor = LoadCursor(NULL, IDC_ARROW);
    WndClassEx.hIcon = LoadIcon(NULL, IDI_WINLOGO);
    WndClassEx.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    WndClassEx.lpszMenuName = NULL;
    WndClassEx.lpszClassName = ClassName;
    RegisterClassEx(&WndClassEx);
    hWnd = CreateWindow(ClassName, WindowName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                        NULL, NULL, hInstance, NULL);
    SetWindowPos(hWnd, HWND_TOP, 0, 0, 720, 450, SWP_SHOWWINDOW);
    while(1) {
        if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) {
            if(Msg.message == WM_QUIT)
                break;
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
        Sleep(10);
    }
    UnregisterClass(ClassName, hInstance);
    return 0;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
    switch(iMsg) {
        case WM_CREATE:
            Buffer.CreateDoubleBuffering(hWnd);
            if(!Buffer.LoadBitmap("images\\RedTile.bmp")) {
                MessageBox(hWnd, "Failed to load RedTile.bmp.", "Fatal Error", MB_OK);
                return 0;
            }
            if(!Buffer.LoadBitmap("images\\BlackTile.bmp")) {
                MessageBox(hWnd, "Failed to load BlackTile.bmp.", "Fatal Error", MB_OK);
                return 0;
            }
            if(!Buffer.LoadBitmap("images\\RedChecker.bmp")) {
                MessageBox(hWnd, "Failed to load RedChecker.bmp.", "Fatal Error", MB_OK);
                return 0;
            }
            if(!Buffer.LoadBitmap("images\\BlackChecker.bmp")) {
                MessageBox(hWnd, "Failed to load BlackChecker.bmp.", "Fatal Error", MB_OK);
                return 0;
            }
            break;

        case WM_LBUTTONDOWN:
            int iXLoc;
            iXLoc = LOWORD(lParam);
            int iYLoc;
            iYLoc = HIWORD(lParam);
            Buffer.DisplayBitmap(1, iXLoc, iYLoc);
            Buffer.SwapBackBuffer(false);
            break;
        case WM_DESTROY:
            SelectObject(Buffer.hdcBack, Buffer.hOldBitmap);
            PostQuitMessage(0);
            break;
    };
    return DefWindowProc(hWnd, iMsg, wParam, lParam);
}