not making any sence
i have a book and im trying to use an example slide show program and plug in my own bitmaps but it wont let me i have double checked and the properties on the bit maps that come with the example are exactly the same as the properties of my own bit maps but it wont load and its ticking me off i dont get it whats my problem?
You gave us no information whatsoever about the book or program you are mentioning. We won't be able to guess these, you need to tell us first. What you did here is just run into the forums and ask something along the lines of "I have a book, won't tell you which book it is, but can you explain what the fifth word on the first page means?"
If it's OpenGL or DirectX, bitmaps need to have a width and height of 2^nin order to load.
2 x 2, 4 x 4, 8 x 8, 16 x 16, 32 x 32 , 64 x 64, 128 x 128, 256 x 256....
2 x 2, 4 x 4, 8 x 8, 16 x 16, 32 x 32 , 64 x 64, 128 x 128, 256 x 256....
oo im sorry ok um im using c++ on dev-cpp 4.9.9.0 using the slideshow example program from teach yourself game programming in 24 hours i guess ill post all my code
rather cumbersome though
bitmap data
width 640
hight 480
resulution (both ways) 96dpi
bit depth 8
frames 1
(wrote using paint)
//-----------------------------------------------------------------// Slideshow Application// C++ Source - Slideshow.cpp//-----------------------------------------------------------------//-----------------------------------------------------------------// Include Files//-----------------------------------------------------------------#include "Slideshow.h"//-----------------------------------------------------------------// Game Engine Functions//-----------------------------------------------------------------BOOL GameInitialize(HINSTANCE hInstance){ // Create the game engine _pGame = new GameEngine(hInstance, TEXT("Slideshow"), TEXT("Slideshow"), IDI_SLIDESHOW, IDI_SLIDESHOW_SM); if (_pGame == NULL) return FALSE; // Set the frame rate _pGame->SetFrameRate(100); // Store the instance handle _hInstance = hInstance; return TRUE;}void GameStart(HWND hWindow){ // Create and load the slide bitmaps HDC hDC = GetDC(hWindow); _pSlides[0] = new Bitmap(hDC, TEXT("guy1.bmp")); _pSlides[1] = new Bitmap(hDC, TEXT("guy2.bmp")); _pSlides[2] = new Bitmap(hDC, TEXT("guy3.bmp")); _pSlides[3] = new Bitmap(hDC, TEXT("guy4.bmp")); _pSlides[4] = new Bitmap(hDC,TEXT("guy5.bmp")); _pSlides[5] = new Bitmap(hDC, TEXT("guy6.bmp")); _pSlides[6] = new Bitmap(hDC, TEXT("guy7.bmp")); _pSlides[7] = new Bitmap(hDC, TEXT("guy8.bmp")); _pSlides[8] = new Bitmap(hDC,TEXT("guy9.bmp")); _pSlides[9] = new Bitmap(hDC, TEXT("guy10.bmp")); _pSlides[10] = new Bitmap(hDC, TEXT("guy11.bmp")); _pSlides[11] = new Bitmap(hDC, TEXT("guy12.bmp")); _pSlides[12] = new Bitmap(hDC, TEXT("guy13.bmp")); _pSlides[13] = new Bitmap(hDC, TEXT("guy14.bmp")); _pSlides[14] = new Bitmap(hDC, TEXT("guy15.bmp")); _pSlides[15] = new Bitmap(hDC, TEXT("guy16.bmp")); _pSlides[16] = new Bitmap(hDC,TEXT("guy17.bmp")); // Set the first slide _iCurSlide = 0;}void GameEnd(){ // Cleanup the slide bitmaps for (int i = 0; i < _iNUMSLIDES; i++) delete _pSlides; // Cleanup the game engine delete _pGame;}void GameActivate(HWND hWindow){}void GameDeactivate(HWND hWindow){}void GamePaint(HDC hDC){ // Draw the current slide bitmap _pSlides[_iCurSlide]->Draw(hDC, 0, 0);}void GameCycle(){ static int iDelay = 0; // Establish a 3-second delay before moving to the next slide if (++iDelay > 3) { // Restore the delay counter iDelay = 0; // Move to the next slide if (++_iCurSlide == _iNUMSLIDES) _iCurSlide = 0; // Force a repaint to draw the next slide InvalidateRect(_pGame->GetWindow(), NULL, FALSE); }}
//-----------------------------------------------------------------// Bitmap Object// C++ Source - Bitmap.cpp//-----------------------------------------------------------------//-----------------------------------------------------------------// Include Files//-----------------------------------------------------------------#include "Bitmap.h"//-----------------------------------------------------------------// Bitmap Constructor(s)/Destructor//-----------------------------------------------------------------Bitmap::Bitmap() : m_hBitmap(NULL), m_iWidth(0), m_iHeight(0){}// Create a bitmap from a fileBitmap::Bitmap(HDC hDC, LPTSTR szFileName) : m_hBitmap(NULL), m_iWidth(0), m_iHeight(0){ Create(hDC, szFileName);}// Create a bitmap from a resourceBitmap::Bitmap(HDC hDC, UINT uiResID, HINSTANCE hInstance) : m_hBitmap(NULL), m_iWidth(0), m_iHeight(0){ Create(hDC, uiResID, hInstance);}// Create a blank bitmap from scratchBitmap::Bitmap(HDC hDC, int iWidth, int iHeight, COLORREF crColor) : m_hBitmap(NULL), m_iWidth(0), m_iHeight(0){ Create(hDC, iWidth, iHeight, crColor);}Bitmap::~Bitmap(){ Free();}//-----------------------------------------------------------------// Bitmap Helper Methods//-----------------------------------------------------------------void Bitmap::Free(){ // Delete the bitmap graphics object if (m_hBitmap != NULL) { DeleteObject(m_hBitmap); m_hBitmap = NULL; }}//-----------------------------------------------------------------// Bitmap General Methods//-----------------------------------------------------------------BOOL Bitmap::Create(HDC hDC, LPTSTR szFileName){ // Free any previous bitmap info Free(); // Open the bitmap file HANDLE hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) return FALSE; // Read the bitmap file header BITMAPFILEHEADER bmfHeader; DWORD dwBytesRead; BOOL bOK = ReadFile(hFile, &bmfHeader, sizeof(BITMAPFILEHEADER), &dwBytesRead, NULL); if ((!bOK) || (dwBytesRead != sizeof(BITMAPFILEHEADER)) || (bmfHeader.bfType != 0x4D42)) { CloseHandle(hFile); return FALSE; } BITMAPINFO* pBitmapInfo = (BITMAPINFO*)(new BITMAPINFO_256); if (pBitmapInfo != NULL) { // Read the bitmap info header bOK = ReadFile(hFile, pBitmapInfo, sizeof(BITMAPINFOHEADER), &dwBytesRead, NULL); if ((!bOK) || (dwBytesRead != sizeof(BITMAPINFOHEADER))) { CloseHandle(hFile); Free(); return FALSE; } // Store the width and height of the bitmap m_iWidth = (int)pBitmapInfo->bmiHeader.biWidth; m_iHeight = (int)pBitmapInfo->bmiHeader.biHeight; // Skip (forward or backward) to the color info, if necessary if (pBitmapInfo->bmiHeader.biSize != sizeof(BITMAPINFOHEADER)) SetFilePointer(hFile, pBitmapInfo->bmiHeader.biSize - sizeof (BITMAPINFOHEADER), NULL, FILE_CURRENT); // Read the color info bOK = ReadFile(hFile, pBitmapInfo->bmiColors, pBitmapInfo->bmiHeader.biClrUsed * sizeof(RGBQUAD), &dwBytesRead, NULL); // Get a handle to the bitmap and copy the image bits PBYTE pBitmapBits; m_hBitmap = CreateDIBSection(hDC, pBitmapInfo, DIB_RGB_COLORS, (PVOID*)&pBitmapBits, NULL, 0); if ((m_hBitmap != NULL) && (pBitmapBits != NULL)) { SetFilePointer(hFile, bmfHeader.bfOffBits, NULL, FILE_BEGIN); bOK = ReadFile(hFile, pBitmapBits, pBitmapInfo->bmiHeader.biSizeImage, &dwBytesRead, NULL); if (bOK) return TRUE; } } // Something went wrong, so cleanup everything Free(); return FALSE;}BOOL Bitmap::Create(HDC hDC, UINT uiResID, HINSTANCE hInstance){ // Free any previous DIB info Free(); // Find the bitmap resource HRSRC hResInfo = FindResource(hInstance, MAKEINTRESOURCE(uiResID), RT_BITMAP); if (hResInfo == NULL) return FALSE; // Load the bitmap resource HGLOBAL hMemBitmap = LoadResource(hInstance, hResInfo); if (hMemBitmap == NULL) return FALSE; // Lock the resource and access the entire bitmap image PBYTE pBitmapImage = (BYTE*)LockResource(hMemBitmap); if (pBitmapImage == NULL) { FreeResource(hMemBitmap); return FALSE; } // Store the width and height of the bitmap BITMAPINFO* pBitmapInfo = (BITMAPINFO*)pBitmapImage; m_iWidth = (int)pBitmapInfo->bmiHeader.biWidth; m_iHeight = (int)pBitmapInfo->bmiHeader.biHeight; // Get a handle to the bitmap and copy the image bits PBYTE pBitmapBits; m_hBitmap = CreateDIBSection(hDC, pBitmapInfo, DIB_RGB_COLORS, (PVOID*)&pBitmapBits, NULL, 0); if ((m_hBitmap != NULL) && (pBitmapBits != NULL)) { const PBYTE pTempBits = pBitmapImage + pBitmapInfo->bmiHeader.biSize + pBitmapInfo->bmiHeader.biClrUsed * sizeof(RGBQUAD); CopyMemory(pBitmapBits, pTempBits, pBitmapInfo->bmiHeader.biSizeImage); // Unlock and free the bitmap graphics object UnlockResource(hMemBitmap); FreeResource(hMemBitmap); return TRUE; } // Something went wrong, so cleanup everything UnlockResource(hMemBitmap); FreeResource(hMemBitmap); Free(); return FALSE;}BOOL Bitmap::Create(HDC hDC, int iWidth, int iHeight, COLORREF crColor){ // Create a blank bitmap m_hBitmap = CreateCompatibleBitmap(hDC, iWidth, iHeight); if (m_hBitmap == NULL) return FALSE; // Set the width and height m_iWidth = iWidth; m_iHeight = iHeight; // Create a memory device context to draw on the bitmap HDC hMemDC = CreateCompatibleDC(hDC); // Create a solid brush to fill the bitmap HBRUSH hBrush = CreateSolidBrush(crColor); // Select the bitmap into the device context HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, m_hBitmap); // Fill the bitmap with a solid color RECT rcBitmap = { 0, 0, m_iWidth, m_iHeight }; FillRect(hMemDC, &rcBitmap, hBrush); // Cleanup SelectObject(hMemDC, hOldBitmap); DeleteDC(hMemDC); DeleteObject(hBrush); return TRUE;}void Bitmap::Draw(HDC hDC, int x, int y){ if (m_hBitmap != NULL) { // Create a memory device context for the bitmap HDC hMemDC = CreateCompatibleDC(hDC); // Select the bitmap into the device context HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, m_hBitmap); // Draw the bitmap to the destination device context BitBlt(hDC, x, y, GetWidth(), GetHeight(), hMemDC, 0, 0, SRCCOPY); // Restore and delete the memory device context SelectObject(hMemDC, hOldBitmap); DeleteDC(hMemDC); }}
//-----------------------------------------------------------------// Bitmap Object// C++ Header - Bitmap.h//-----------------------------------------------------------------#pragma once//-----------------------------------------------------------------// Include Files//-----------------------------------------------------------------#include <windows.h>//-----------------------------------------------------------------// Custom Data Types//-----------------------------------------------------------------struct BITMAPINFO_256{ BITMAPINFOHEADER bmiHeader; RGBQUAD bmiColors[256];};//-----------------------------------------------------------------// Bitmap Class//-----------------------------------------------------------------class Bitmap{protected: // Member Variables HBITMAP m_hBitmap; int m_iWidth, m_iHeight; // Helper Methods void Free();public: // Constructor(s)/Destructor Bitmap(); Bitmap(HDC hDC, LPTSTR szFileName); Bitmap(HDC hDC, UINT uiResID, HINSTANCE hInstance); Bitmap(HDC hDC, int iWidth, int iHeight, COLORREF crColor = RGB(0, 0, 0)); virtual ~Bitmap(); // General Methods BOOL Create(HDC hDC, LPTSTR szFileName); BOOL Create(HDC hDC, UINT uiResID, HINSTANCE hInstance); BOOL Create(HDC hDC, int iWidth, int iHeight, COLORREF crColor); void Draw(HDC hDC, int x, int y); int GetWidth() { return m_iWidth; }; int GetHeight() { return m_iHeight; };};
//-----------------------------------------------------------------// Game Engine Object// C++ Source - GameEngine.cpp//-----------------------------------------------------------------//-----------------------------------------------------------------// Include Files//-----------------------------------------------------------------#include "GameEngine.h"//-----------------------------------------------------------------// Static Variable Initialization//-----------------------------------------------------------------GameEngine *GameEngine::m_pGameEngine = NULL;//-----------------------------------------------------------------// Windows Functions//-----------------------------------------------------------------int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){ MSG msg; static int iTickTrigger = 0; int iTickCount; if (GameInitialize(hInstance)) { // Initialize the game engine if (!GameEngine::GetEngine()->Initialize(iCmdShow)) return FALSE; // Enter the main message loop while (TRUE) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { // Process the message if (msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } else { // Make sure the game engine isn't sleeping if (!GameEngine::GetEngine()->GetSleep()) { // Check the tick count to see if a game cycle has elapsed iTickCount = GetTickCount(); if (iTickCount > iTickTrigger) { iTickTrigger = iTickCount + GameEngine::GetEngine()->GetFrameDelay(); GameCycle(); } } } } return (int)msg.wParam; } // End the game GameEnd(); return TRUE;}LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam){ // Route all Windows messages to the game engine return GameEngine::GetEngine()->HandleEvent(hWindow, msg, wParam, lParam);}//-----------------------------------------------------------------// GameEngine Constructor(s)/Destructor//-----------------------------------------------------------------GameEngine::GameEngine(HINSTANCE hInstance, LPTSTR szWindowClass, LPTSTR szTitle, WORD wIcon, WORD wSmallIcon, int iWidth, int iHeight){ // Set the member variables for the game engine m_pGameEngine = 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;}GameEngine::~GameEngine(){}//-----------------------------------------------------------------// Game Engine General Methods//-----------------------------------------------------------------BOOL GameEngine::Initialize(int iCmdShow){ WNDCLASSEX wndclass; // Create the window class for the main window 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.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = m_szWindowClass; // Register the window class if (!RegisterClassEx(&wndclass)) return FALSE; // Calculate the window size and position based upon the game size 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; // Create the window m_hWindow = CreateWindow(m_szWindowClass, m_szTitle, WS_POPUPWINDOW | WS_CAPTION | WS_MINIMIZEBOX, iXWindowPos, iYWindowPos, iWindowWidth, iWindowHeight, NULL, NULL, m_hInstance, NULL); if (!m_hWindow) return FALSE; // Show and update the window ShowWindow(m_hWindow, iCmdShow); UpdateWindow(m_hWindow); return TRUE;}LRESULT GameEngine::HandleEvent(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam){ // Route Windows messages to game engine member functions switch (msg) { case WM_CREATE: // Set the game window and start the game SetWindow(hWindow); GameStart(hWindow); return 0; case WM_ACTIVATE: // Activate/deactivate the game and update the Sleep status if (wParam != WA_INACTIVE) { GameActivate(hWindow); SetSleep(FALSE); } else { GameDeactivate(hWindow); SetSleep(TRUE); } return 0; case WM_PAINT: HDC hDC; PAINTSTRUCT ps; hDC = BeginPaint(hWindow, &ps); // Paint the game GamePaint(hDC); EndPaint(hWindow, &ps); return 0; case WM_DESTROY: // End the game and exit the application GameEnd(); PostQuitMessage(0); return 0; } return DefWindowProc(hWindow, msg, wParam, lParam);}void GameEngine::ErrorQuit(LPTSTR szErrorMsg){ MessageBox(GetWindow(), szErrorMsg, TEXT("Critical Error"), MB_OK | MB_ICONERROR); PostQuitMessage(0);}
//-----------------------------------------------------------------// Game Engine Object// C++ Header - GameEngine.h//-----------------------------------------------------------------#pragma once//-----------------------------------------------------------------// Include Files//-----------------------------------------------------------------#include <windows.h>//-----------------------------------------------------------------// Windows Function Declarations//-----------------------------------------------------------------int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow);LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);//-----------------------------------------------------------------// Game Engine Function Declarations//-----------------------------------------------------------------BOOL GameInitialize(HINSTANCE hInstance);void GameStart(HWND hWindow);void GameEnd();void GameActivate(HWND hWindow);void GameDeactivate(HWND hWindow);void GamePaint(HDC hDC);void GameCycle();//-----------------------------------------------------------------// GameEngine Class//-----------------------------------------------------------------class GameEngine{protected: // Member Variables static GameEngine* m_pGameEngine; 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(s)/Destructor GameEngine(HINSTANCE hInstance, LPTSTR szWindowClass, LPTSTR szTitle, WORD wIcon, WORD wSmallIcon, int iWidth = 640, int iHeight = 480); virtual ~GameEngine(); // General Methods static GameEngine* GetEngine() { return m_pGameEngine; }; BOOL Initialize(int iCmdShow); LRESULT HandleEvent(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam); void ErrorQuit(LPTSTR szErrorMsg); // Accessor Methods 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; };};
//-----------------------------------------------------------------// Slideshow Resource Identifiers// C++ Header - Resource.h//-----------------------------------------------------------------//-----------------------------------------------------------------// Icons Range : 1000 - 1999//-----------------------------------------------------------------#define IDI_SLIDESHOW 1000#define IDI_SLIDESHOW_SM 1001//-----------------------------------------------------------------// Bitmaps Range : 2000 - 2999//-----------------------------------------------------------------#define IDB_GUY1 1#define IDB_GUY2 2#define IDB_GUY3 3#define IDB_GUY4 4#define IDB_GUY5 5#define IDB_GUY6 6#define IDB_GUY7 7#define IDB_GUY8 8#define IDB_GUY9 9#define IDB_GUY10 10#define IDB_GUY11 11#define IDB_GUY12 12#define IDB_GUY13 13#define IDB_GUY14 14#define IDB_GUY15 15#define IDB_GUY16 16#define IDB_GUY17 17
//-----------------------------------------------------------------// Slideshow Application// C++ Header - Slideshow.h//-----------------------------------------------------------------#pragma once//-----------------------------------------------------------------// Include Files//-----------------------------------------------------------------#include <windows.h>#include "Resource.h"#include "GameEngine.h"#include "Bitmap.h"//-----------------------------------------------------------------// Global Variables//-----------------------------------------------------------------HINSTANCE _hInstance;GameEngine* _pGame;const int _iNUMSLIDES = 17;Bitmap* _pSlides[_iNUMSLIDES];int _iCurSlide;
//-----------------------------------------------------------------// Slideshow Resources// RC Source - Slideshow.rc//-----------------------------------------------------------------//-----------------------------------------------------------------// Include Files//-----------------------------------------------------------------#include "Resource.h"//-----------------------------------------------------------------// Icons//-----------------------------------------------------------------IDI_SLIDESHOW ICON "Slideshow.ico"IDI_SLIDESHOW_SM ICON "Slideshow_sm.ico"//-----------------------------------------------------------------// Bitmaps//----------------------------------------------------------------- IDB_GUY1 BITMAP "guy1.bmp" IDB_GUY2 BITMAP "guy2.bmp" IDB_GUY3 BITMAP "guy3.bmp" IDB_GUY4 BITMAP "guy4.bmp" IDB_GUY5 BITMAP "guy5.bmp" IDB_GUY6 BITMAP "guy6.bmp" IDB_GUY7 BITMAP "guy7.bmp" IDB_GUY8 BITMAP "guy8.bmp" IDB_GUY9 BITMAP "guy9.bmp" IDB_GUY10 BITMAP "guy10.bmp" IDB_GUY11 BITMAP "guy11.bmp" IDB_GUY12 BITMAP "guy12.bmp" IDB_GUY13 BITMAP "guy13.bmp" IDB_GUY14 BITMAP "guy14.bmp" IDB_GUY15 BITMAP "guy15.bmp" IDB_GUY16 BITMAP "guy16.bmp" IDB_GUY17 BITMAP "guy17.bmp"
rather cumbersome though
bitmap data
width 640
hight 480
resulution (both ways) 96dpi
bit depth 8
frames 1
(wrote using paint)
Quote:Original post by ToohrVyk
"I have a book, won't tell you which book it is, but can you explain what the fifth word on the first page means?"
Here you go: What it means.
I looked at your code, and I cannot see the exact reason why it do not work as expected, but I suspect this has something to do with your bitmap creation.
1) since your BMPs are resources, you should use
To construct them. I'm pretty sure that the files are not where Bitmap::Bitmap(HDC hDC, LPTSTR szFileName) expect them (BTW, this should be LPCTSTR, and not LPTSTR, unless you want to allow the constructor to modify the string you give).
2) It should be better to do
This will allow you to catch up runtime errors (constructors do not return anything)
3) nothing to do with your problem but there is a GDI resource leak in GameStart() : you must call ReleaseDC() at the end of the function. DCs are rare, so you must take care of them.
@Washu : woh... How did you know it was this word ?
Yours,
1) since your BMPs are resources, you should use
Bitmap::Bitmap(HDC hDC, UINT uiResID, HINSTANCE hInstance);
To construct them. I'm pretty sure that the files are not where Bitmap::Bitmap(HDC hDC, LPTSTR szFileName) expect them (BTW, this should be LPCTSTR, and not LPTSTR, unless you want to allow the constructor to modify the string you give).
2) It should be better to do
Bitmap *pBitmap = new Bitmap();BOOL b = pBitmap->Create(...);
This will allow you to catch up runtime errors (constructors do not return anything)
3) nothing to do with your problem but there is a GDI resource leak in GameStart() : you must call ReleaseDC() at the end of the function. DCs are rare, so you must take care of them.
@Washu : woh... How did you know it was this word ?
Yours,
Quote:Original post by Emmanuel Deloget
I looked at your code, and I cannot see the exact reason why it do not work as expected, but I suspect this has something to do with your bitmap creation.
1) since your BMPs are resources, you should useBitmap::Bitmap(HDC hDC, UINT uiResID, HINSTANCE hInstance);
To construct them. I'm pretty sure that the files are not where Bitmap::Bitmap(HDC hDC, LPTSTR szFileName) expect them (BTW, this should be LPCTSTR, and not LPTSTR, unless you want to allow the constructor to modify the string you give).
Warts...gross.
Quote:
2) It should be better to doBitmap *pBitmap = new Bitmap();BOOL b = pBitmap->Create(...);
This will allow you to catch up runtime errors (constructors do not return anything)
He could throw an exception here, of course, there are reasons to and reasons not to, all dependant upon the situation (is the bitmap file not being found an exceptional condition? in most situations, where it is a resource, probably.)
std::auto_ptr<Bitmap> bitmap;try { bitmap.reset(new Bitmap(arr, rawr, whooo));} catch(std::exception& e) { ...}
Quote:
3) nothing to do with your problem but there is a GDI resource leak in GameStart() : you must call ReleaseDC() at the end of the function. DCs are rare, so you must take care of them.
Aye, tis very rare indeed.
Quote:
@Washu : woh... How did you know it was this word ?
Yours,
Omniscience does have its benefits.
ok well when i load it from resources it works out fine (i still dont get what the prob is) oh well thanks guys
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement