Thread: need help with some DX stuff

  1. #1

    Question need help with some DX stuff

    Okay, as always, I am slowly trudging along learning DX bit by bit, while using my book Real Time Strategy Game Programming with MS DirectX.

    I have come to a small problem while trying to load targa files into my app. Everything has worked fine before this. For some reason as I try to load the targa file and display it, it freezes the whole program, and for some reason also does not let me Alt+Tab or Ctrl+Alt+Del out of the program, so I have to reboot my computer every time.

    Here is all code that is relevant to the problem:

    #include "screen.h"
    #include "dirdraw.h"
    #include "winshell.h"
    DWORD WINAPI RedrawScreen (LPVOID lpvParm);
    DWORD WINAPI UpdateProc (LPVOID lpvParm);
    DWORD WINAPI HandleEvents (LPVOID lpvParm);
    void InitLoops ( );
    void CleanupLoops ( );
    BOOL ActiveApp;// is the program active?
    static HWND WindowHandle;
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
            LPSTR lpCmdLine, int nCmdShow)
        MSG         msg;
        HWND        hwnd;
    	//DRAWING_MANAGERptr Draw;	
    	bool FullScreenFlag = /*false;*/true;
    	int SCREEN_WIDTH = 640, SCREEN_HEIGHT = 480;
        hPrevInstance = hPrevInstance;// avoid C++ warning
        // here we instantiate the direct draw object
    	hwnd = DDraw->CreateMainWindow(SCREEN_WIDTH, SCREEN_HEIGHT, 
    				"Generic Name", MessageLoop, hInstance, 
    	//					MessageLoop, hInstance, FullScreenFlag);
    	//hwnd = (HWND)Draw->GetWindowHandle();
    	//if (!hwnd) {delete Draw; return FALSE;}	
    	if(!hwnd) { delete DDraw; return FALSE; }
            int t = PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE);
            if (t)
                if (!GetMessage (& msg, NULL, 0, 0))
                return msg.wParam;
                TranslateMessage (&msg);
                DispatchMessage (&msg);
            else if (ActiveApp)// this is important here
    			//RedrawScreen ((LPVOID) Draw);
    			RedrawScreen((LPVOID) DDraw);
            else if (!ActiveApp)
    	//delete Draw; 
    	delete DDraw;
    	return 1;
    void* GetWindowHandle(void)
        return (void*)WindowHandle;
    void  ErrorMessage (char* str)
    	MessageBox (WindowHandle, str, "Error", MB_OK);
    	DestroyWindow (WindowHandle);
    // loops.cpp
    #include "dirdraw.h"
    #include "alphabet.h"
    #include "graphic.h"
    int frame = 0;
    int time =0, timelast=0;
    int count = 0;
    GRAPHIC *Graphic = NULL;
    void Draw ( DIRECT_DRAW_MANAGER *DDraw );
    void InitLoops ( )
    	int NoExternalScratchPad = 1;
    	int compress = 1;
    	Graphic = new GRAPHIC (NoExternalScratchPad);
    	STRINGC str = "Test.tga";
    	Graphic->Load(str, compress);	
    void CleanupLoops ( )
    			delete Graphic;
    DWORD WINAPI RedrawScreen (LPVOID Parm)
    	if (DDraw == NULL) return 1;
    	time = timeGetTime();// get the current millisec
    	if (time-timelast>=1000)
    		frame = count;
    		timelast=time;// update time
    	char buff[40];
    	itoa(frame, buff, 10);
    	DDraw->PaintText(20, 20, buff);	
    	return 0;
    void Draw ( DIRECT_DRAW_MANAGER *DDraw )
    	SCREEN_STRUCT *screen = DDraw->GetScreen();
    	char buff[100];
    	long time1 = timeGetTime();
    	Graphic->DrawAt(screen, rand()%630+5, rand()%470+5);
    	long time2 = timeGetTime();
    	long result = time2-time1;
    	itoa(result, buff, 10);
    	alpha.PrintText(60, 60, screen, buff);
    //one function from graphic.cpp
    bool  GRAPHIC:: Load (STRINGC& str, bool CompressFlag)// load by filename and convert to 16 bit compressed
    	flags.Flag.COMPRESSED = (U16)CompressFlag;// make sure we have this flag
    	if (!flags.Flag.NO_SCRATCH_PAD && ScratchPad == NULL) return false;
    	if (Image != NULL) {delete Image; Image = NULL;}
    	SetPath (str);
    	if (FileType == LLE) return LoadLLE();
        if (FileType == TGA) return LoadTGA();
        if (FileType != BMP) return false;
    	// bmp by default
        //*************** assumes a BMP for now ***********************
    	FILE_MASTER		 file (str, FILE_MASTER:: READ);
    	if (file.Status() != FILE_MASTER::NONE) return false;
    	if (file.Read (&Header, sizeof (BITMAPFILEHEADER))) {return false;}
    	if (file.Read (&Info, sizeof (BITMAPINFOHEADER))) {return false; }
        Height = (U16) Info.biHeight, Width = (U16) Info.biWidth;
    	if (Info.biBitCount == 16) return false;// we do not support 16 bit bitmaps
    	if (flags.Flag.NO_SCRATCH_PAD && ScratchPad) delete ScratchPad;
    	if (flags.Flag.NO_SCRATCH_PAD) ScratchPad = new U16 [2*Height*Width];
        if (Info.biBitCount == 24) if (Load24Bit(&file)==false) return false;
    	if (Info.biBitCount == 8) if (Load8Bit(&file, Info.biClrUsed)==false) return false;
    	if (Info.biBitCount == 4) if (Load4Bit(&file, Info.biClrUsed)==false) return false;
    	if (Info.biBitCount != 1)
    		if (CompressFlag == true) 
    			Image = LLECompression16Bit (ScratchPad, Width, Height, &NumPixels);
    			Image = CopyScratchPadIntoImage ();
    			NumPixels = Width*Height;
        flags.Flag.LOADED = true;
    	if (flags.Flag.NO_SCRATCH_PAD && ScratchPad) 
    		delete ScratchPad;
    		ScratchPad = NULL;
    	return true;

    I tried uploading all of the code in a .zip file, but it was about 50kb too if you want to see all of the code email me and i will send you a zip file of the project...the zip is about 160 kb large. I am using VC++.

    Thanx for any help. (Sunlight would be very helpful right about now...when is that guy gonna come back...)

  2. #2
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Plano, Texas, United States


    dangt....the stupid site logged me out as I was typing the message, so now it says it was posted by an unregistered person...well, it was posted by me, just so u know.
    My Website

    "Circular logic is good because it is."

  3. #3
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    I would ask what all those classes do, but I get the distinct feeling I don't want to know...

    My best guess is something is going wrong, and you are getting a debugger break. However, you can't see it, because you're in DirectDraw mode. Good one, no?

    At this point, you want to try pressing Enter (to close the message box), then Shift+F5 (to stop the program). If you're really lucky, it died while in your source code, and your cursor should be positioned at the offending line. If you're unlucky, it didn't, and you're back to the old 'printf' style of debugging: put OutputDebugString calls throughout your code, so you can trace it in the Output window.

    If you need further help, e-mail me the code and I will respond here.
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DX or OpenGL?
    By michaelp in forum Game Programming
    Replies: 31
    Last Post: 01-10-2008, 06:26 PM
  2. Checking for DX in setup and deployment in MSVS 05 .NET
    By VirtualAce in forum A Brief History of
    Replies: 0
    Last Post: 10-15-2006, 03:32 PM
  3. Assembly Tutorials
    By JoshR in forum A Brief History of
    Replies: 13
    Last Post: 06-11-2005, 09:56 AM
  4. dx sdk pls
    By gooddevil in forum Game Programming
    Replies: 3
    Last Post: 05-14-2004, 12:57 PM
  5. Your stuff
    By smog890 in forum C Programming
    Replies: 6
    Last Post: 06-13-2002, 11:50 PM