unexpected end of file -_-

Started by
12 comments, last by jflanglois 16 years, 11 months ago
You were right to remove $(NoInherit). Could you post all of your code, as it is currently? The code you posted before doesn't compile for a variety of reasons.

Oh, and the problem is probably when you register your window class. Also, I saw a few character pointers. You might want to make friends with std::string or std::wstring, since you are using C++.


jfl.
Advertisement
Yeah, without seeing more of your code,

wndclass.hIcon = LoadIcon(m_hInstance, MAKEINTRESOURCE(GetIcon()));
wndclass.hIconSm = LoadIcon(m_hInstance, MAKEINTRESOURCE(GetSmallIcon()));

should be

wndclass.hIcon = LoadIcon(m_hInstance, MAKEINTRESOURCE(IDI_BLIZZARD));
wndclass.hIconSm = LoadIcon(m_hInstance, MAKEINTRESOURCE(IDI_BLIZZARD_SM));


jfl.
(resource.h)
//iconer		Range: 1000-1999#define IDI_BLIZZARD		1000#define IDI_BLIZZARD_SM		1001


(sexyengine1.h)
#pragma once//include files#include <windows.h>//windows function declariationint WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow);LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);//SexyEngine function declatiationer (Hver af understående er spil-specifikke, så de skal indsættes// af de specifikke spil der bruger SexyEngineBOOL GameInitialize(HINSTANCE hInstance);void GameStart(HWND hWindow);void GameEnd();void GameActivate(HWND hWindow);void GameDeactivate(HWND hWindow);void GamePaint(HDC hDC);void GameCycle();//SexyEngine classclass SexyEngine{ protected:  //medlems variabler  static SexyEngine*	m_pSexyEngine;  HINSTANCE				m_hInstance;  HWND					m_hWindow;  TCHAR					m_szWindowClass[32];  TCHAR					m_szTitle[32];  WORD					m_wIcon, m_wSmallIcon;  int					m_iWidth, m_iHeight;  int					m_iFrameDelay;  BOOL					m_bSleep;   public:  //constructor/destructor  SexyEngine(HINSTANCE hInstance, LPTSTR szWindoClass, LPTSTR szTitle, WORD wIcon, WORD wSmallIcon, int iWidth = 640, int iHeight = 480);  virtual ~SexyEngine();    //generale metoder  static SexyEngine* GetEngine() {return m_pSexyEngine;};  BOOL Initialize(int iCmdShow);  LRESULT HandleEvent(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam);    //adgangs metoder  HINSTANCE GetInstance() {return m_hInstance;};  HWND GetWindow() {return m_hWindow;};  void SetWindow(HWND hWindow) { m_hWindow = hWindow;};  LPTSTR GetTitle() {return m_szTitle;};  WORD GetIcon() {return m_wIcon;};  WORD GetSmallIcon() {return m_wSmallIcon;};  int GetWidth() {return m_iWidth;};  int GetHeight() {return m_iHeight;};  int GetFrameDelay() {return m_iFrameDelay;};  void SetFrameRate (int iFrameRate) { m_iFrameDelay = 1000 / iFrameRate;};  BOOL GetSleep() {return m_bSleep;};  void SetSleep(BOOL bSleep) {m_bSleep = bSleep;};};//end of SexyEngine class


(storm.h)
[source lang = "cpp"]#pragma once//include filer#include <windows.h>#include "Resource.h"#include "SexyEngine1.h"//globale variablerSexyEngine* g_pGame;


(storm.rc)
[source lang = "cpp"]#include "Resource.h"//iconerIDI_BLIZZARD         ICON       "fjeringrofl.ico"IDI_BLIZZARD_SM      ICON       "fjeringrofl_sm.ico"


(sexyengine1.cpp)
[source lang = "cpp"]#include "SexyEngine1.h"//static variabel initialisationSexyEngine* SexyEngine::m_pSexyEngine = NULL;//windows funktionerint WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow){ MSG		msg; static int	iTickTrigger = 0; int		iTickCount;  if (GameInitialize(hInstance)) {  //initialiser(not to self: er begyndt at hade det ord..) SexyEngine  if (!SexyEngine::GetEngine()->Initialize(iCmdShow))   return FALSE;    while (TRUE)  {   if( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))   {    //proces beskeden    if (msg.message == WM_QUIT)     break;    TranslateMessage(&msg);    DispatchMessage(&msg);   }   else   {    //vær sikker på at engien ikke sover    if (!SexyEngine::GetEngine()->GetSleep())    {     iTickCount = GetTickCount();     if (iTickCount > iTickTrigger)     {      iTickTrigger = iTickCount + SexyEngine::GetEngine()->GetFrameDelay();      GameCycle();	 }	}   }  } return (int)msg.wParam; } GameEnd(); return TRUE;}LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam){ return SexyEngine::GetEngine()->HandleEvent(hWindow, msg, wParam, lParam);}//game engine constructor(s) + destructor definationerSexyEngine::SexyEngine(HINSTANCE hInstance, LPTSTR szWindowClass, LPTSTR szTitle, WORD wIcon, WORD wSmallIcon, int iWidth, int iHeight){ //sætter member variablerne for SexyEngine m_pSexyEngine = this; m_hInstance = hInstance; m_hWindow = NULL; if (lstrlen(szWindowClass) > 0)  lstrcpy(m_szWindowClass, szWindowClass); if (lstrlen(szTitle) > 0)  lstrcpy(m_szTitle, szTitle); m_wIcon = wIcon; m_wSmallIcon = wSmallIcon; m_iWidth = iWidth; m_iHeight = iHeight; m_iFrameDelay = 50; //20 fps default m_bSleep = TRUE;}SexyEngine::~SexyEngine(){}//SexyEngine generale MetoderBOOL SexyEngine::Initialize(int iCmdShow){ WNDCLASSEX wndclass;  wndclass.cbSize		=sizeof(wndclass); wndclass.style			=CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc	= WndProc; wndclass.cbClsExtra	= 0; wndclass.cbWndExtra	= 0; wndclass.hInstance		= m_hInstance; wndclass.hIcon			= LoadIcon(m_hInstance, MAKEINTRESOURCE(GetIcon())); wndclass.hIconSm		= LoadIcon(m_hInstance, MAKEINTRESOURCE(GetSmallIcon())); wndclass.hbrBackground	= (HBRUSH)(COLOR_WINDOW + 1); wndclass.lpszMenuName	= NULL; wndclass.lpszClassName	= m_szWindowClass;  //registrer window classen if (!RegisterClassEx(&wndclass))  return FALSE;  //vidnuet bliver lavet i midten int iWindowWidth = m_iWidth + GetSystemMetrics(SM_CXFIXEDFRAME) * 2, iWindowHeight = m_iHeight + GetSystemMetrics(SM_CYFIXEDFRAME) * 2 + GetSystemMetrics(SM_CYCAPTION); if (wndclass.lpszMenuName != NULL)  iWindowHeight += GetSystemMetrics(SM_CYMENU); int iXWindowPos = (GetSystemMetrics(SM_CXSCREEN) - iWindowWidth) / 2, iYWindowPos = (GetSystemMetrics(SM_CYSCREEN) - iWindowHeight) / 2;  //Laver vinduet m_hWindow = CreateWindow(m_szWindowClass, m_szTitle, WS_POPUPWINDOW | WS_CAPTION | WS_MINIMIZE, iXWindowPos, iYWindowPos, iWindowWidth, iWindowHeight, NULL, NULL, m_hInstance, NULL); if (!m_hWindow)  return FALSE;   //vis og updater vinduet ShowWindow(m_hWindow, iCmdShow); UpdateWindow(m_hWindow);return TRUE;}LRESULT SexyEngine::HandleEvent(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam){ //efter at have sendt alle 'beskeder' til SexyEngines HandleEvent() switch (msg) {  case WM_CREATE:   //sætter spille vinduet og starter spillet   $(NoInherit)   SetWindow(hWindow);   GameStart(hWindow);	    return 0;    case WM_SETFOCUS:   //activer spillevinduet og opdater sleep statusen   GameActivate(hWindow);   SetSleep(FALSE);   return 0;    case WM_PAINT:   HDC hDC;   PAINTSTRUCT ps;   hDC = BeginPaint(hWindow, &ps);   //tegn spillet   GamePaint(hDC);      EndPaint(hWindow, &ps);   return 0;    case WM_DESTROY:   //slut spillet og skrid fra applicationen   GameEnd();   PostQuitMessage(0);   return 0; }return DefWindowProc(hWindow, msg, wParam, lParam);}// mads ztyrer!  


(storm.cpp)
[source lang= "cpp"]#include "Storm.h"//game engine funktionerBOOL GameInitialize(HINSTANCE hInstance){ g_pGame = new SexyEngine(hInstance, TEXT("Fjering"), TEXT("FJERING"), IDI_BLIZZARD, IDI_BLIZZARD_SM); if (g_pGame == NULL)  return FALSE;  //sætter frame raten g_pGame->SetFrameRate(15); return TRUE;}void GameStart(HWND hWindow){ //Seeder RANDom nummer generatoren srand(GetTickCount());}void GameEnd(){ //rydder op i game engine delete g_pGame;}void GameActivate(HWND hWindow){ HDC hDC; RECT rect; //tegn hvad der sker på skærmen GetClientRect(hWindow,&rect); hDC = GetDC(hWindow); DrawText(hDC,TEXT("Her kommer der en storm!"), -1, &rect, DT_SINGLELINE| DT_CENTER | DT_VCENTER);ReleaseDC(hWindow,hDC);}void GameDeactivate(HWND hWindow){ HDC hDC; RECT rect; //tegn deaktiverings tekst op skærmen GetClientRect(hWindow, &rect); hDC = GetDC(hWindow); DrawText(hDC,TEXT("Stormen er ovre."), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);ReleaseDC(hWindow, hDC);}void GamePaint(HDC hDC){}void GameCycle(){ HDC hDC; HWND hWindow = g_pGame->GetWindow();   //tegn storm partiklerne på skærmen hDC = GetDC(hWindow);   DrawIcon(hDC, rand() % g_pGame->GetWidth(), g_pGame->GetHeight(), (HICON)(WORD)GetClassLong(hWindow, GCL_HICON));ReleaseDC(hWindow, hDC);}   


there you go. it is supposed to paint a picture every 15 sek at a random possition in the screen. Instead it makes a empty popupwindow with a window as cursor.

edit: if i do as you mentioned above, i get 2 compiler errors, that IDI_BLIZZARD and IDI_BLIZZARD_SM is undeclared(this is also my first time working with splitted files, didnt i declared them in the right file?)
a small question: is there a way that i can make, all those settings you have taught me the "standard" so when i open MSVC++ those are the settings that are used.

[Edited by - MadsGustaf on May 22, 2007 11:35:30 AM]
•°*”˜˜”*°•.˜”*°•..•°*”˜.•°*”˜˜”*°•..•°*”˜˜”*°•.˜”*°•.˜”*°•. Mads .•°*”˜.•°*”˜.•°*”˜˜”*°•.˜”*°•..•°*”˜.•°*”˜.•°*”˜ ˜”*°•.˜”*°•.˜”*°•..•°*”˜I am going to live forever... or die trying!
Sorry for the late reply, I was a little busy.

So:

Quote:there you go. it is supposed to paint a picture every 15 sek at a random possition in the screen. Instead it makes a empty popupwindow with a window as cursor.

That is because you are painting it outside of the window boundaries:
DrawIcon(hDC, rand() % g_pGame->GetWidth(), g_pGame->GetHeight(), (HICON)(WORD)GetClassLong(hWindow, GCL_HICON));

You want to mod rand() there as well.

Quote:edit: if i do as you mentioned above, i get 2 compiler errors, that IDI_BLIZZARD and IDI_BLIZZARD_SM is undeclared(this is also my first time working with splitted files, didnt i declared them in the right file?)

There is no "right file" in C++. You need to #include "Resource.h" in order to refer to them (or you can redefine them, but that would defeat the purpose). However, if your project ran fine as it was, then there is no need to change it. It failed for me, for some reason.

Quote:a small question: is there a way that i can make, all those settings you have taught me the "standard" so when i open MSVC++ those are the settings that are used.

You can. There is a predefined project "Win32 Console Application" that you can use (just select Windows Application and Empty Project in the wizard that follows). Normally, it's possible to define your own project types, but I haven't looked into it.


jfl.

This topic is closed to new replies.

Advertisement