Svar til:
2:
#include "resource.h"
#include <windows.h>
#include <iostream>
HINSTANCE hInsta;
int Show;
void NewGame();
void Settings();
void Rules();
void About();
void InitPop();
std::string table[8][8];
//Første = x, anden = y
//Hvis hvid har feltet = 1
//Hvis sort har feltet = 2
//Hvis feltet er tomt = 0
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam);
HWND hwnd;
HWND popup;
WNDCLASSEX wc;
WNDCLASSEX pop;
HBITMAP g_hbmBall = NULL;
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
g_hbmBall = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(BALL));
Show = nShow;
MSG msg;
hInsta = hInst;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU);
wc.lpszClassName = "WndClass";
wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);
RegisterClassEx(&wc);
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,
"WndClass",
"Dam V. 1.0",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 700, 700,
NULL,
NULL,
hInst,
NULL);
ShowWindow(hwnd, Show);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
switch(nMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_FILE_EXIT:
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
case ID_FILE_NEW:
NewGame();
break;
case ID_FILE_SETTINGS:
Settings();
break;
case ID_FILE_ABOUT:
InitPop();
About();
MessageBox(NULL, table[1][1],"Test",MB_OK);
break;
case ID_FILE_RULES:
Rules();
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
break;
default:
return DefWindowProc(hwnd, nMsg, wParam, lParam);
}
}
void NewGame()
{
//række 1 (talt nedefra)
table[0][0] = "2";
table[0][1] = "0";
table[0][2] = "2";
table[0][3] = "0";
table[0][4] = "2";
table[0][5] = "0";
table[0][6] = "2";
table[0][7] = "0";
//række 2
table[1][0] = "0";
table[1][1] = "2";
table[1][2] = "0";
table[1][3] = "2";
table[1][4] = "0";
table[1][5] = "2";
table[1][6] = "0";
table[1][7] = "2";
//række 3
table[2][0] = "2";
table[2][1] = "0";
table[2][2] = "2";
table[2][3] = "0";
table[2][4] = "2";
table[2][5] = "0";
table[2][6] = "2";
table[2][7] = "0";
//række 4
table[3][0] = "0";
table[3][1] = "0";
table[3][2] = "0";
table[3][3] = "0";
table[3][4] = "0";
table[3][5] = "0";
table[3][6] = "0";
table[3][7] = "0";
//række 5
table[4][0] = "0";
table[4][1] = "0";
table[4][2] = "0";
table[4][3] = "0";
table[4][4] = "0";
table[4][5] = "0";
table[4][6] = "0";
table[4][7] = "0";
//række 6
table[5][0] = "0";
table[5][1] = "1";
table[5][2] = "0";
table[5][3] = "1";
table[5][4] = "0";
table[5][5] = "1";
table[5][6] = "0";
table[5][7] = "1";
//række 7
table[6][0] = "1";
table[6][1] = "0";
table[6][2] = "1";
table[6][3] = "0";
table[6][4] = "1";
table[6][5] = "0";
table[6][6] = "1";
table[6][7] = "0";
//række 8
table[7][0] = "0";
table[7][1] = "1";
table[7][2] = "0";
table[7][3] = "1";
table[7][4] = "0";
table[7][5] = "1";
table[7][6] = "0";
table[7][7] = "1";
}
void Settings()
{
}
void About()
{
popup = CreateWindowEx(WS_EX_CLIENTEDGE,"PopClass", "Om", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, hwnd, NULL, hInsta, NULL);
ShowWindow(popup, Show);
UpdateWindow(popup);
}
void Rules()
{
}
void InitPop()
{
pop.cbSize = sizeof(WNDCLASSEX);
pop.style = CS_HREDRAW | CS_VREDRAW;
pop.lpfnWndProc = MainWndProc;
pop.cbClsExtra = 0;
pop.cbWndExtra = 0;
pop.hInstance = hInsta;
pop.hCursor = LoadCursor(NULL, IDC_ARROW);
pop.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
pop.lpszMenuName = NULL;
pop.lpszClassName = "PopClass";
pop.hIcon = NULL;
pop.hIconSm = NULL;
RegisterClassEx(&pop);
}
4: Hvordan?