Thread: question on BitBlt drawing routines / functions

  1. #1
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    question on BitBlt drawing routines / functions

    I have this function:
    Code:
    void Title()
    {
    	int width;
    	int height;
    
    	HDC hDC = GetDC(hWnd);
    	RECT rcClient;
    	GetClientRect(hWnd, &rcClient);
    
    	HDC hDCBuffer = CreateCompatibleDC(hDC);
    	HBITMAP hbmOldBuffer = (HBITMAP)SelectObject(hDCBuffer, c);
    
    	//InvalidateRect(hWnd, &rcClient, TRUE);
    	BitBlt(hDC, 0, 0, rcClient.right, rcClient.bottom, hDCBuffer, 0, 0, SRCPAINT);
    	//InvalidateRect(hWnd, &rcClient, TRUE);
    	PlaySound("intro.wav", NULL, SND_FILENAME);
    }
    I call Title() before the main windows loop, like this:
    Code:
    //.......
    ShowWindow(hWnd, nCmdShow);
        UpdateWindow(hWnd);
    
    	Title();
    	PlaySound("intro.wav", NULL, SND_FILENAME);
    	PlaySound("music1.wav", NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
    
    	//Working example
    	//PlaySound("a.wav", NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
    
        // Step 3: The Message Loop
        for(;;)
        {
    		if(newgame == true)
    		{
    			players = GetPlayers(*phWnd);
    			SetPlayers();
    			newgame = false;
    			finished = false;
    			SetQuestions();
    		}
    
    		GetMessage(&Msg, NULL, 0, 0);
    		if(Msg.message == WM_QUIT || Msg.message == WM_DESTROY)
    			break;
    
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
    
    		if(finished == false)
    		    MainLoop(*phWnd, players);
    		else if(endone == false)
    			End();
        }
        return Msg.wParam;
    }
    should this display anything onto the screen? for some reason, it doesn't. What did I do wrong?

  2. #2
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    Again, I figured this one on my own.....but this brings on another question:

    The problem with my code was this line:

    Code:
    c = LoadBitmap(NULL, MAKEINTRESOURCE(IDB_C));
    For the bitmap to be loaded correctly, the line has to be:
    Code:
    c = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_C));
    Isn't that the same as NULL? The same is with loading icons.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    No

    HINSTANCE = GetModuleHandle(NULL);

    HINSTANCE != NULL ( or your app is not running)

    also

    HDC hDC = GetDC(hWnd);
    //this reqires a ReleaseDC() call to return the GDI resources you have allocated.

    HBITMAP hbmOldBuffer = (HBITMAP)SelectObject(hDCBuffer, c);

    //Great you catch the HBITMAP already in the DC but where do you return it?
    So the DC is EXACTLY the same when the function exits as when the function started?

    c = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_C));

    //this requires a DeleteObject() call after you have finished with the image. LoadBitmap() is old. LoadImage() is better, particularly if you need to print them (as you can easily create DIB's)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    yeah i have it all fixed up

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Functions Question
    By audinue in forum C Programming
    Replies: 2
    Last Post: 01-09-2009, 09:39 AM
  2. newb question about interpreting and writing functions
    By crazychile in forum C Programming
    Replies: 1
    Last Post: 10-23-2008, 07:51 PM
  3. Question about Downloading/Uploading Functions
    By TeCNoYoTTa in forum C++ Programming
    Replies: 0
    Last Post: 05-26-2008, 01:36 PM
  4. functions question.
    By Boozel in forum C Programming
    Replies: 1
    Last Post: 02-23-2008, 12:38 AM
  5. Question about Recursive Functions
    By jack999 in forum C++ Programming
    Replies: 5
    Last Post: 05-15-2006, 05:14 PM