Click here to Skip to main content
15,902,002 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Can we stop an .exe from anthoer .exe Pin
pandit8428-Mar-11 3:50
pandit8428-Mar-11 3:50 
QuestionRe: Can we stop an .exe from anthoer .exe Pin
Rajesh R Subramanian28-Mar-11 3:58
professionalRajesh R Subramanian28-Mar-11 3:58 
AnswerRe: Can we stop an .exe from anthoer .exe Pin
pandit8428-Mar-11 4:20
pandit8428-Mar-11 4:20 
GeneralRe: Can we stop an .exe from anthoer .exe Pin
Stefan_Lang28-Mar-11 5:39
Stefan_Lang28-Mar-11 5:39 
GeneralRe: Can we stop an .exe from anthoer .exe Pin
CPallini28-Mar-11 6:02
mveCPallini28-Mar-11 6:02 
AnswerRe: Can we stop and .exe from anthoer .exe Pin
Rolf Kristensen28-Mar-11 7:07
Rolf Kristensen28-Mar-11 7:07 
GeneralRe: Can we stop and .exe from anthoer .exe Pin
pandit8428-Mar-11 7:19
pandit8428-Mar-11 7:19 
QuestionHow to screenshot as a single color bitmap file? Pin
wangningyu27-Mar-11 17:17
wangningyu27-Mar-11 17:17 
Hello everybody !

I wan't to save the bitmap to convert to a single color bitmap (8 pixel / Byte).

I use this way to save to 16 color bitmap. how to convert it to single bitmap ,or how to save it from the device context first ?

/************************************************************************
Function : Screenshot
Parameter: hwnd			the window handle.
	   lpRect		the window rect.
return   : HBITMAP
other    : NULL
************************************************************************/
HBITMAP GetWindowBitmap(HWND hwnd, LPRECT lpRect)
{

     if( !lpRect )
          return NULL;

     HDC	hDC;
     HDC	hMemDC;
     HBITMAP	hBitmap = NULL;
     HBITMAP	hOldBitmap;
    
     if( hwnd == NULL )
         hDC = ::GetDC(HWND_DESKTOP);
     else
         hDC = ::GetWindowDC(hwnd);

     if( hDC == NULL )
         return NULL;

	 hMemDC  = CreateCompatibleDC(hDC);
     hBitmap = CreateCompatibleBitmap(hDC, lpRect->right - lpRect->left, 
	 lpRect->bottom - lpRect->top);

     if( hBitmap == NULL)
         return NULL;

     hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
     BitBlt(hMemDC, 0, 0, lpRect->right - lpRect->left, 
	 lpRect->bottom - lpRect->top, hDC, lpRect->left, lpRect->top, SRCCOPY);
    
     SelectObject(hMemDC, hOldBitmap);
     DeleteDC(hMemDC);
     ::ReleaseDC(hwnd, hDC);

     return hBitmap;
}

/************************************************************************
Function : Write to file
Parameter: strFilePath  the whole file path.
	   hBitmap	the bitmap memory
return   : if success return TRUE, otherwise return FALSE.
************************************************************************/
BOOL SaveBitmapToFile(CString strFilePath,HBITMAP hBitmap)
{
	HDC			hdc  = NULL;
	FILE*			fp   = NULL;
	LPVOID			pBuf = NULL;
	BITMAPINFO		bmpInfo;
	BITMAPFILEHEADER	bmpFileHeader;
	
	do{
		
		hdc = ::GetDC(NULL);
		ZeroMemory(&bmpInfo,sizeof(BITMAPINFO));
		bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);				
		GetDIBits(hdc,hBitmap,0,0,NULL,&bmpInfo,DIB_RGB_COLORS);
		//bmpInfo.bmiHeader.biBitCount = 0x08;		// 8bit,when I use it ,bmp is invalid.
		bmpInfo.bmiHeader.biBitCount = 0x10;		// 16

		if(bmpInfo.bmiHeader.biSizeImage <= 0)
			bmpInfo.bmiHeader.biSizeImage = bmpInfo.bmiHeader.biWidth*abs(bmpInfo.bmiHeader.biHeight)*(bmpInfo.bmiHeader.biBitCount+7)/8;
		
		if((pBuf = malloc(bmpInfo.bmiHeader.biSizeImage)) == NULL)
		{
			::MessageBox(NULL,_T("Unable to Allocate Bitmap Memory"),_T("Error"),MB_OK|MB_ICONERROR);
			return FALSE;
		}
		
		bmpInfo.bmiHeader.biCompression = BI_RGB;
		GetDIBits(hdc,hBitmap,0,bmpInfo.bmiHeader.biHeight,pBuf,&bmpInfo,DIB_RGB_COLORS);	
		
		TRACE(_T("%s\r\n"),strFilePath);
		if((fp=fopen(strFilePath.GetBuffer(strFilePath.GetLength()),"wb"))==NULL)
		{
			::MessageBox(NULL,_T("Unable to Create Bitmap File"),_T("Error"),MB_OK|MB_ICONERROR);
			return FALSE;
		}
		
		bmpFileHeader.bfReserved1	= 0;
		bmpFileHeader.bfReserved2	= 0;
		bmpFileHeader.bfSize		= sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+bmpInfo.bmiHeader.biSizeImage;
		bmpFileHeader.bfType		= 'MB';
		bmpFileHeader.bfOffBits		= sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
		
		fwrite(&bmpFileHeader,sizeof(BITMAPFILEHEADER),1,fp);
		fwrite(&bmpInfo.bmiHeader,sizeof(BITMAPINFOHEADER),1,fp);
		fwrite(pBuf,bmpInfo.bmiHeader.biSizeImage,1,fp);
		
	}while(false);
	
	if(hdc)
           ::ReleaseDC(NULL,hdc);
	
	if(pBuf)
           free(pBuf);
	
	if(fp)
           fclose(fp);
    
	return TRUE;
}<pre>



Thanks for your reply !

Best regards~~~

AnswerRe: How to screenshot as a single color bitmap file? Pin
Ozer Karaagac28-Mar-11 14:11
professionalOzer Karaagac28-Mar-11 14:11 
GeneralRe: How to screenshot as a single color bitmap file? Pin
wangningyu28-Mar-11 14:18
wangningyu28-Mar-11 14:18 
GeneralRe: How to screenshot as a single color bitmap file? Pin
wangningyu28-Mar-11 17:38
wangningyu28-Mar-11 17:38 
GeneralRe: How to screenshot as a single color bitmap file? Pin
Ozer Karaagac28-Mar-11 18:19
professionalOzer Karaagac28-Mar-11 18:19 
QuestionHow to create a windowless control after implementing all the necessary interfaces? Pin
followait26-Mar-11 22:04
followait26-Mar-11 22:04 
QuestionLetter drawing Pin
transoft25-Mar-11 6:40
transoft25-Mar-11 6:40 
AnswerRe: Letter drawing Pin
Richard MacCutchan25-Mar-11 7:21
mveRichard MacCutchan25-Mar-11 7:21 
AnswerRe: Letter drawing Pin
Code-o-mat25-Mar-11 10:02
Code-o-mat25-Mar-11 10:02 
AnswerRe: Letter drawing Pin
Niklas L26-Mar-11 8:53
Niklas L26-Mar-11 8:53 
QuestionKey Press Event Pin
rjkg25-Mar-11 2:44
rjkg25-Mar-11 2:44 
AnswerRe: Key Press Event Pin
Joan M26-Mar-11 3:46
professionalJoan M26-Mar-11 3:46 
Questionproblem when using (detours lib) SetDll.exe to Add a dll to an exe file. Pin
gogosai24-Mar-11 22:13
gogosai24-Mar-11 22:13 
AnswerRe: problem when using (detours lib) SetDll.exe to Add a dll to an exe file. Pin
Nitheesh George24-Mar-11 22:18
Nitheesh George24-Mar-11 22:18 
AnswerRe: problem when using (detours lib) SetDll.exe to Add a dll to an exe file. Pin
Nitheesh George24-Mar-11 22:33
Nitheesh George24-Mar-11 22:33 
GeneralRe: problem when using (detours lib) SetDll.exe to Add a dll to an exe file. Pin
gogosai24-Mar-11 23:10
gogosai24-Mar-11 23:10 
GeneralRe: problem when using (detours lib) SetDll.exe to Add a dll to an exe file. Pin
Albert Holguin25-Mar-11 13:34
professionalAlbert Holguin25-Mar-11 13:34 
GeneralRe: problem when using (detours lib) SetDll.exe to Add a dll to an exe file. Pin
Nitheesh George27-Mar-11 18:27
Nitheesh George27-Mar-11 18:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.