i can't do this, too hard.
Hi everyone,
I am reaaaaaaalllllllyyyyyy sorry for postin'' this up but i really need help!
All i want is a Bitmap displayed in a full screen window. I have been tryin to get this to work for weeks!
here is my code :S it aint in any order because i just want it to work before i sort it out :S
:
#include <windows.h>
#include "stdafx.h"
#include "ddraw.h"
#define INITGUID
#define MAX_LOADSTRING 100
LPDIRECTDRAW lpDD = NULL;
LPDIRECTDRAWSURFACE lpDDSPrimary = NULL;
LPDIRECTDRAWSURFACE lpDDSBack = NULL;
LPDIRECTDRAWSURFACE lpDDSBitmap = NULL;
LPDIRECTDRAWCLIPPER lpClipper = NULL;
HRESULT hRet;
HINSTANCE hInst; // current instance
TCHAR szTitle[] = "Hughs App 2"; // The title bar text
TCHAR szWindowClass[] = "MY WINDOWS CLASS"; // The title bar text
// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
// Initialize global strings
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, NULL, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wcex.lpszMenuName = 0;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = 0;
return RegisterClassEx(&wcex);
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
DDSURFACEDESC ddsd;
HBITMAP hBitmap = NULL;
hInst = hInstance; // Store instance handle in our global variable
if (FAILED(hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
250, 150, 500, 500, NULL, NULL, hInstance, NULL)))
return FALSE;
if (!hWnd)
{
return FALSE;
}
if (FAILED(ShowWindow(hWnd, nCmdShow)))
return FALSE;
if (FAILED(UpdateWindow(hWnd)))
return FALSE;
HRESULT ddrval;
ddrval = DirectDrawCreate( NULL, &lpDD, NULL );
if( ddrval != DD_OK )
{
return(false);
}
ddrval = lpDD->SetCooperativeLevel( hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN );
if( ddrval != DD_OK )
{
lpDD->Release();
return(false);
}
ddrval = lpDD->SetDisplayMode( 1024, 768, 32);
if( ddrval != DD_OK )
{
lpDD->Release();
return(false);
}
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL);
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd.dwWidth = 819;
ddsd.dwHeight = 614;
lpDD->CreateSurface(&ddsd, &lpDDSBitmap, NULL);
LoadImage(NULL, "stanley4.bmp", IMAGE_BITMAP, 0,0, LR_LOADFROMFILE);
DeleteObject(hBitmap);
HDC hdcImage;
HDC hdc;
BITMAP bm;
int width = 819;
int height = 614;
lpDDSBitmap->Restore();
hdcImage = CreateCompatibleDC(NULL);
SelectObject(hdcImage, hBitmap);
GetObject(hBitmap, sizeof(bm),&bm);
width = width == 0 ? bm.bmWidth : width;
height = height == 0 ? bm.bmHeight : height;
lpDDSBitmap->GetDC(&hdc);
BitBlt(hdc, 0, 0, width, height, hdcImage, 0,0,SRCCOPY);
lpDDSBitmap->ReleaseDC(hdc);
DeleteDC(hdcImage);
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
ok, it compiles fine and when i run it, i get a fullscreen window covering the start toolbar so i guess it works to a point but i have no bitmap! could sombody point out wot i am doing wrong?
c yas l8er
thedude.
November 14, 2002 01:18 PM
well, first of all, you spelled ''forward'' wrong. you put ''foward'' in one of your comments. i hope this doesn''t help!!
<hr><p>
I know it''s not a train, but it''ll do.<p>
<hr>
<hr><p>
I know it''s not a train, but it''ll do.<p>
<hr>
quote:
ddrval = lpDD->SetDisplayMode( 1024, 768, 32);
if( ddrval != DD_OK )
{
lpDD->Release();
return(false);
}
doesn''t SetDisplayMode() take 5 parameters?
...i think i know whats going on.
the call to the GDI that displays you bitmap is probably wiping the surface data for lpDDSBitmap. when you call Restore(), it doesn''t restore the data, only the surface memory. so you would have to call the GDI for the bitmap stuff , restore(), and then put the bitmap onto the surface (which usues the GDI), restore()...you see where this is going.
I''d also check the GDI stuff in the WM_PAINT handling section.
In my program that soesn''t quite work (much like yours) i use ValidateRect().
it''s too bad i have the same problem right now. i''d tell you how to fix it, but i don''t know.
oh, and you should probably also add error handling for the lpDD->Create Surface calls too.
Programmers of the world, UNTIE!
cheers MatS423 i''ll try that out - it is a great relief to find somebody in the same boat as me! thanx.
thedude.
thedude.
hm..i can''t see the back buffer? where is it? where is the code where you blit the bitmap to the back buffer and flip it?
My compiler generates one error message: "does not compile."
My compiler generates one error message: "does not compile."
quote: LoadImage(NULL, "stanley4.bmp", IMAGE_BITMAP, 0,0, LR_LOADFROMFILE);
You load the bitmap and do not store the handle. And you have to give a bitmap size or set the LR_DEFAULTSIZE flag I think.
And don't delete the bitmap right after you loaded it!! I'd delete it when cleaning up with DirectDraw, so you have it already loaded if you have to restore a surface.
Oh, and use the {source}{/source} ([] instead of {}) tags for long code!
[edited by - LordLethis on November 14, 2002 3:42:45 PM]
or, you could try this.....
I threw in Abort(). I wrote that to deliver error messages so you don''t have to attempt to use the debugger to find out what happened.
int BitmapToSurface(LPDIRECTDRAWSURFACE7 lpDDSBitmap, char BitmapName[],int BitmapSizeX,int BitmapSizeY){ //Sets the color key to black DDCOLORKEY ColorKey; ColorKey.dwColorSpaceHighValue = _RGB32BIT(0,0,0,0); ColorKey.dwColorSpaceLowValue = _RGB32BIT(0,0,0,0); //Color key is now set...attach it to the surface if(FAILED(lpDDSBitmap->SetColorKey(DDCKEY_SRCBLT,&ColorKey))) { Abort("Could not set color key"); return 1; } DDBLTFX DDBltFx; DDBltFx.dwSize = sizeof(DDBltFx); DDBltFx.dwFillColor = _RGB32BIT(0,255,255,255); if(FAILED(lpDDSBitmap->Blt(NULL,NULL,NULL, DDBLT_WAIT | DDBLT_COLORFILL, &DDBltFx))) { Abort("Error Wiping the Bitmap"); return 1; } HBITMAP hbBitmap; if(!(hbBitmap = (HBITMAP) LoadImage(NULL,BitmapName,IMAGE_BITMAP, BitmapSizeX,BitmapSizeY,LR_LOADFROMFILE))) { Abort("hbBitmap error"); return 1; } HDC hdc; lpDDSBitmap->GetDC(&hdc); HDC hBitmapDC = CreateCompatibleDC(hdc); SelectObject(hBitmapDC,hbBitmap); if(!(BitBlt(hdc,0,0,BitmapSizeX,BitmapSizeY, hBitmapDC,0,0,SRCCOPY))) { Abort("BitBlt error"); return 1; } ReleaseDC(g_hWnd,hBitmapDC); lpDDSBitmap->ReleaseDC(hdc); return 0;}void Abort(char ErrorMessage[]){ MessageBox(g_hWnd,ErrorMessage,"Error",MB_OK | MB_ICONEXCLAMATION);}
I threw in Abort(). I wrote that to deliver error messages so you don''t have to attempt to use the debugger to find out what happened.
Programmers of the world, UNTIE!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement