Sign in to follow this  

question! New to resources (win32)

This topic is 3857 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

(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 declariation

int 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 SexyEngine

BOOL GameInitialize(HINSTANCE hInstance);
void GameStart(HWND hWindow);
void GameEnd();
void GameActivate(HWND hWindow);
void GameDeactivate(HWND hWindow);
void GamePaint(HDC hDC);
void GameCycle();

//SexyEngine class

class 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 variabler
SexyEngine* g_pGame;




(storm.rc)
[source lang = "cpp"]
#include "Resource.h"

//iconer

IDI_BLIZZARD         ICON       "fjeringrofl.ico"
IDI_BLIZZARD_SM      ICON       "fjeringrofl_sm.ico"





(sexyengine1.cpp)
[source lang = "cpp"]
#include "SexyEngine1.h"

//static variabel initialisation
SexyEngine* SexyEngine::m_pSexyEngine = NULL;

//windows funktioner

int 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 definationer

SexyEngine::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 Metoder

BOOL 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(IDI_BLIZZARD));
 wndclass.hIconSm		= LoadIcon(m_hInstance, MAKEINTRESOURCE(IDI_BLIZZARD_SM));
 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 funktioner
BOOL 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);
} 
  




MSVC++ compiler complains, that i have not defined the BLIZZARD resources (in BOOL SexyEngine::Initialize() ). Can anyone help me get through to a sollution? im new to splitted files/resources/win32 programming, so if anyone can clear up why the compiler cant find them? as far as im concerned i defined them as i should.. Thanks! - Mads

Share this post


Link to post
Share on other sites

This topic is 3857 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this