• Advertisement

Archived

This topic is now archived and is closed to further replies.

No BMP

This topic is 6547 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

When I compiled the following, no bitmap came up, why?(I deliberately put my includes in quotes) #define WIN32_LEAN_AND_MEAN #include "windows.h" #include "windowsx.h" #include "stdio.h" #include "conio.h" #include "memory.h" #include "ddraw.h" HWND windowh = NULL; HINSTANCE instance= NULL; int GameInit(); int GameMain(); int GameEnd(); LPDIRECTDRAW lpdd = NULL; LPDIRECTDRAWSURFACE pbuff= NULL; LPDIRECTDRAWSURFACE bbuff= NULL; DDSCAPS ddcap; DDSURFACEDESC ddsd; DDBLTFX bltfx; HBITMAP hbm; HDC imagedc =NULL; HDC surfacedc =NULL; LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { PAINTSTRUCT ps; HDC hdc; switch(msg) { case WM_CREATE: { return(0); } break; case WM_PAINT: { hdc = BeginPaint(hwnd,&ps); EndPaint(hwnd,&ps); return(0); } break; case WM_DESTROY: { PostQuitMessage(0); return(0); } break; default:break; } return (DefWindowProc(hwnd, msg, wparam, lparam)); } int WINAPI WinMain( HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { WNDCLASSEX winclass; HWND hwnd; MSG msg; winclass.cbSize = sizeof(WNDCLASSEX); winclass.style = CS_DBLCLKS / CS_OWNDC / CS_HREDRAW / CS_VREDRAW; winclass.lpfnWndProc = WindowProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hinstance; winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); winclass.lpszMenuName = NULL; winclass.lpszClassName = "WINDOW_CLASS_NAME"; winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); instance = hinstance; if (!RegisterClassEx(&winclass)) return(0); if (!(hwnd = CreateWindowEx(NULL, "WINDOW_CLASS_NAME", "BlitEx", WS_POPUP / WS_VISIBLE, 0,0, 480,640, NULL, NULL, hinstance, NULL))) windowh = hwnd; GameInit(); while(TRUE) { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if (msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } GameMain(); } GameEnd(); return(msg.wParam); } int GameInit() { if(FAILED(DirectDrawCreate(NULL, &lpdd, NULL))) { return(0); } if(FAILED(lpdd->SetCooperativeLevel(windowh, DDSCL_EXCLUSIVE/ DDSCL_FULLSCREEN/ DDSCL_ALLOWREBOOT))) { return(0); } if(FAILED(lpdd->SetDisplayMode(640, 480, 16))) { return(0); } memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize =sizeof(ddsd); ddsd.dwFlags =DDSD_CAPS; ddsd.ddsCaps.dwCaps =DDSCAPS_PRIMARYSURFACE/DDSCAPS_FLIP; if(FAILED(lpdd->CreateSurface(&ddsd, &pbuff, NULL))) { return(0); } return(1); } int GameMain() { hbm =(HBITMAP)LoadImage(NULL, "Image.dib", IMAGE_BITMAP, ddsd.dwWidth, ddsd.dwHeight, LR_LOADFROMFILE/LR_CREATEDIBSECTION); imagedc = CreateCompatibleDC(NULL); SelectObject(imagedc, hbm); if(FAILED(pbuff->GetDC(&surfacedc))) { return(0); } if(BitBlt(surfacedc,0,0,ddsd.dwHeight, ddsd.dwWidth, imagedc, 0, 0, SRCCOPY) == FALSE) { return(0); } return(1); } int GameEnd() { if(imagedc) { pbuff->ReleaseDC(surfacedc); } if(imagedc) { DeleteObject(imagedc); } if(hbm) { DeleteObject(hbm); } if(pbuff) { pbuff->Release(); } if(lpdd) { lpdd->Release(); } return(1); } Games are the path to another dimension.

Share this post


Link to post
Share on other sites
Advertisement
It''s generally not a good idea to load a bitmap EVERY CYCLE THROUGH YOUR MAIN LOOP. I think that''s your problem. Perhaps you could do something to move it to your Init? Anyway, happy coding and enjoy.

Pythius

Share this post


Link to post
Share on other sites

  • Advertisement