Der er stadig fejl:
C:\\BORLAND\\BCC55\\BIN>makeobj game/game
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
game/Game.cpp:
Error E2268 game/Game.cpp 106: Call to undefined function 'ToString' in function
__stdcall MainWndProc(HWND__ *,unsigned int,unsigned int,long)
Warning W8071 game/Game.cpp 106: Conversion may lose significant digits in funct
ion __stdcall MainWndProc(HWND__ *,unsigned int,unsigned int,long)
Warning W8071 game/Game.cpp 118: Conversion may lose significant digits in funct
ion __stdcall MainWndProc(HWND__ *,unsigned int,unsigned int,long)
Warning W8066 game/Game.cpp 134: Unreachable code in function __stdcall MainWndP
roc(HWND__ *,unsigned int,unsigned int,long)
*** 1 errors in Compile ***
#include <windows.h>
#include <string>
#include <iostream.h>
#include <stdlib.h>
#include <sstream.h>
HINSTANCE InstanceHandle;
HWND MainWindow;
HBITMAP Bitmap;
UINT ImageWidth, ImageHeight;
int a0 = 0;
std::string a1 = "v";
std::string a2;
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.c_str(), &ImageWidth, &ImageHeight); // BKB
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(a0 == 4) { // BKB
}
else
{
a0++;
a2 = ToString(a0);
mannpos = a1 + a2 + a3;
break;
case VK_DOWN:
if(a0 == 0) { // BKB
}
else
{
a0 = a0 - 1;
a2 = ToString(a0);
mannpos = a1 + a2 + a3;
break;
}
} // BKB
break;
case WM_PAINT:
OnPaint(hwnd);
return TRUE;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,msg,wParam,lParam);
} // BKB
}
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;
}