Thread: Saving bmps#2

  1. #1
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470

    Saving bmps#2

    Hi
    My program gets a screen cap and displays that image on it's main dialog window. Then it lets the user to crop the image by drawing a square on the image. After the user releases the mouse after cropping, a child dialog window is opened to display the cropped image. Now i want to save this cropped image into the hard disk. i checked out the msdn article: Storing an Image and used the 2 functions found there to do this. Below is how i call those 2 function within the WM_LBUTTONUP msg handler of my main windows's dlgproc (the dlg that displays the uncropped screen cap).

    Code:
    case WM_LBUTTONUP:
    		//user releases the mouse ending the crop
    		if(bCrop)
    		{
    			//get ending mouse coords
    			iEndXPos = GET_X_LPARAM(lParam); 
    			iEndYPos = GET_Y_LPARAM(lParam); 
    			
    			HWND hwndTempCap = CreateDialog(hInst,MAKEINTRESOURCE(IDD_TEMPCAP),NULL,DlgProcTempCap); //open the child dlg which should display the croped img
    			ShowWindow(hwndTempCap,SW_MAXIMIZE);
    
    			g_hTempMemDC = GetDC(hwndTempCap); //get the dc for the child dlg
    			BitBlt(g_hTempMemDC,0,0,iEndXPos-iStartXPos,iEndYPos-iStartYPos,
    				g_hMemDC,iStartXPos,iStartYPos,SRCCOPY); //copy the croped bitmap into the child dialogs' hdc
    
    			HBITMAP hbitmap = CreateCompatibleBitmap(g_hTempMemDC,200,200); // create a bmp for the child dlg
    			if(hbitmap==NULL)
    				PostQuitMessage(0);
    			PBITMAPINFO bmpinfo = CreateBitmapInfoStruct(hwnd, hbitmap); // msdn function - initialize members within a BITMAPINFOHEADER structure
    			CreateBMPFile(hwnd,"test.bmp",bmpinfo,hbitmap,g_hTempMemDC); // msdn function - save the croped img to disk
    
    			bCrop=FALSE;
    		}
    		break;
    But after CreateBMPFile executes, what i get is a blank bitmap ("test.bmp") on the hard disk. CreateBitmapInfoStruct() and CreateBMPFile() cannot go wrong because i found them in msdn, so it's me somthing doing wrong. what's i'm doing wrong plase? Please help.
    Thanks.
    Last edited by geek@02; 10-16-2006 at 09:52 PM.
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Several things wrong. Very similar to a problem I had. Use this 'screenshot' function (thx to anonytmouse).

    Code:
    http://cboard.cprogramming.com/showthread.php?t=66259

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New to C++ problem saving files
    By wesm in forum C++ Programming
    Replies: 2
    Last Post: 11-02-2005, 02:00 PM
  2. Replies: 2
    Last Post: 06-16-2005, 10:03 AM
  3. saving a binary tree??
    By fayte in forum C++ Programming
    Replies: 9
    Last Post: 01-27-2005, 01:32 PM
  4. Saving vectors of structures problem
    By redeck in forum C++ Programming
    Replies: 4
    Last Post: 12-09-2004, 04:47 PM
  5. File saving problem in DevC++ pls help ???
    By intruder in forum C Programming
    Replies: 3
    Last Post: 12-17-2002, 01:17 AM