Code:
#include <windows.h>
#include "card.h"
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
int deck[MAXCOL][MAXPOS];
HINSTANCE card_dll;
MSG msg;
HWND hwnd;
WNDCLASSEX wc;
pfcdtInit cdtInit;
pfcdtInit cdtDraw;
pfcdtAnimate cdtDrawEx;
pfcdtTerm cdtTerm;
/*load cards.dll*/
if((card_dll = LoadLibrary("cards.dll")) == 0){
MessageBox(NULL, "Unable to load cards.dll", "Error", MB_OK | MB_ICONERROR);
return -1;
}
/*fill in the function pointers with valid addresses*/
cdtInit = GetProcAddress(card_dll, "cdtInit");
cdtDraw = GetProcAddress(card_dll, "cdtDraw");
cdtDrawEx = GetProcAddress(card_dll, "cdtAnimate");
cdtTerm = (pfcdtTerm)GetProcAddress(card_dll, "cdtTerm");
shuffle(deck, 1337);
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_DBLCLKS;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon (hInstance, IDI_APPLICATION);
wc.hCursor = LoadCursor(hInstance, IDC_ARROW);
wc.hbrBackground = CreateSolidBrush(RGB(0,255,0));
wc.lpszMenuName = NULL;
wc.lpszClassName = "Freecell";
wc.hIconSm = NULL;
if(RegisterClassEx(&wc) == 0){
MessageBox(NULL, "Failed to register window", "Error", MB_OK | MB_ICONERROR);
return -1;
}
/*if all goes well we have a window on-screen after this*/
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, "Freecell", "........Cell", WS_VISIBLE | WS_SYSMENU | WS_CAPTION, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL);
if(hwnd == NULL){
MessageBox(NULL, "Unable to create window", "Error", MB_OK | MB_ICONERROR);
return -1;
}
ShowWindow(hwnd, SW_SHOW);
/*message loop*/
while(GetMessage(&msg, hwnd, 0, 0) > 0){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
/*clean up time*/
cdtTerm();
FreeLibrary(card_dll);
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
HDC hdc;
PAINTSTRUCT ps;
switch(uMsg){
/* case WM_CREATE:
hdc = BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
break;
*/
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
break;
}
return 0;
}