Ok nu ser min kode sådan ud:
#include <windows.h>
#include <string>
HINSTANCE InstanceHandle;
HWND MainWindow;
HBITMAP Bitmap;
UINT ImageWidth, ImageHeight;
std::string a1 = "v";
std::string a2 = "0";
std::string a3 = ".bmp";
std::string mannpos = a1 + a2 + a3;
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
HBITMAP LoadBMP(const char *FileName, UINT *Width, UINT *Height)
{
HBITMAP BitMap = (HBITMAP )LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
if(!BitMap)
MessageBox(0, "Failed to load image", "BitMap", MB_OK);
else
{
BITMAP BitmapInfo;
GetObject(BitMap, sizeof(BITMAP), &BitmapInfo);
*Width = BitmapInfo.bmWidth;
*Height = BitmapInfo.bmHeight;
}
return BitMap;
}
HWND CreateMainWindow()
{
WNDCLASS wc;
memset(&wc, 0, sizeof(WNDCLASS));
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS ;
wc.lpfnWndProc = (WNDPROC )MainWndProc;
wc.hInstance = InstanceHandle;
wc.hbrBackground = (HBRUSH )(COLOR_BTNFACE + 1);
wc.lpszClassName = "SimpleWinWndClass";
wc.lpszMenuName = 0;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClass(&wc))
return 0;
Bitmap = LoadBMP(mannpos, &ImageWidth, &ImageHeight);
return CreateWindow("SimpleWinWndClass",
"NumberGame",
WS_MINIMIZEBOX | WS_VISIBLE |
WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_MAXIMIZEBOX |
WS_CAPTION | WS_BORDER | WS_SYSMENU | WS_THICKFRAME,
100, 100, 788, 725,
0,
0,
InstanceHandle,
0);
}
void OnPaint(HWND hwnd)
{
PAINTSTRUCT PaintStruct;
HDC dc = BeginPaint(hwnd, &PaintStruct);
HDC MemDC = CreateCompatibleDC(dc);
HBITMAP OldBitmap = (HBITMAP )SelectObject(MemDC, Bitmap);
BitBlt(dc, 0, 0, ImageWidth, ImageHeight, MemDC, 0, 0, SRCCOPY);
SelectObject(MemDC, OldBitmap);
DeleteObject(MemDC);
EndPaint(hwnd, &PaintStruct);
}
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_KEYDOWN:
switch (wParam)
{
case VK_LEFT:
mannpos = a1 + a2 + a3;
break;
case VK_RIGHT:
mannpos = a1 + a2 + a3;
break;
case VK_UP:
if(a2 == 4) {
}
else
{
a2++;
mannpos = a1 + a2 + a3;
break;
case VK_DOWN:
if(a2 == 0) {
}
else
{
a2 = a2 - 1;
mannpos = a1 + a2 + a3;
break;
}
break;
case WM_PAINT:
OnPaint(hwnd);
return TRUE;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,msg,wParam,lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
INT nCmdShow)
{
InstanceHandle = hInstance;
if((MainWindow = CreateMainWindow()) == (HWND )0)
{
MessageBox(0, "Failed to create MainWindow!", "Warning", MB_OK);
return 0;
}
ShowWindow(MainWindow, SW_SHOW);
MSG Msg;
while(GetMessage(&Msg, 0, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
Men jeg får et par fejl og jeg ved heller ikke om den opdatere vinduet hver gang jeg har trykket på en piletast fejlene er:
C:\\BORLAND\\BCC55\\BIN>makeobj game/game
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
game/Game.cpp:
Error E2034 game/Game.cpp 49: Cannot convert 'std::string' to 'const char *' in
function CreateMainWindow()
Error E2342 game/Game.cpp 49: Type mismatch in parameter 'FileName' (wanted 'con
st char *', got 'std::string') in function CreateMainWindow()
Error E2094 game/Game.cpp 99: 'operator==' not implemented in type 'std::string'
for arguments of type 'int' in function __stdcall MainWndProc(HWND__ *,unsigned
int,unsigned int,long)
Error E2096 game/Game.cpp 103: Illegal structure operation in function __stdcall
MainWndProc(HWND__ *,unsigned int,unsigned int,long)
Error E2094 game/Game.cpp 110: 'operator==' not implemented in type 'std::string
' for arguments of type 'int' in function __stdcall MainWndProc(HWND__ *,unsigne
d int,unsigned int,long)
Error E2094 game/Game.cpp 114: 'operator-' not implemented in type 'std::string'
for arguments of type 'int' in function __stdcall MainWndProc(HWND__ *,unsigned
int,unsigned int,long)
Warning W8066 game/Game.cpp 129: Unreachable code in function __stdcall MainWndP
roc(HWND__ *,unsigned int,unsigned int,long)
Error E2141 game/Game.cpp 147: Declaration syntax error in function __stdcall Ma
inWndProc(HWND__ *,unsigned int,unsigned int,long)
Error E2139 game/Game.cpp 163: Declaration missing ; in function __stdcall MainW
ndProc(HWND__ *,unsigned int,unsigned int,long)
Error E2134 game/Game.cpp 163: Compound statement missing } in function __stdcal
l MainWndProc(HWND__ *,unsigned int,unsigned int,long)
Error E2134 game/Game.cpp 163: Compound statement missing } in function __stdcal
l MainWndProc(HWND__ *,unsigned int,unsigned int,long)
Warning W8070 game/Game.cpp 163: Function should return a value in function __st
dcall MainWndProc(HWND__ *,unsigned int,unsigned int,long)
*** 10 errors in Compile ***
Men ellers hvis de fejl ikke var der så burde manden kunne gå op og ned nu!