Click here to Skip to main content
15,882,553 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Need Help in writing a Windows device driver Pin
Eddy Vluggen14-Nov-16 3:49
professionalEddy Vluggen14-Nov-16 3:49 
QuestionGaneric Class Define Pin
bestbear10-Nov-16 18:27
bestbear10-Nov-16 18:27 
AnswerRe: Ganeric Class Define Pin
leon de boer10-Nov-16 19:04
leon de boer10-Nov-16 19:04 
GeneralRe: Ganeric Class Define Pin
bestbear10-Nov-16 19:10
bestbear10-Nov-16 19:10 
GeneralRe: Ganeric Class Define Pin
leon de boer10-Nov-16 19:31
leon de boer10-Nov-16 19:31 
AnswerRe: Ganeric Class Define Pin
Stefan_Lang1-Dec-16 3:55
Stefan_Lang1-Dec-16 3:55 
QuestionSave the image from window buffer Pin
Onic77710-Nov-16 4:26
Onic77710-Nov-16 4:26 
AnswerRe: Save the image from window buffer Pin
leon de boer10-Nov-16 16:10
leon de boer10-Nov-16 16:10 
That is all you need .. you can then get the window size
RECT r;
GetWindowRect(hWnd, &r);
int Wth = r.right - r.left;
int Ht = r.bottom - r.top;

You also have the wonderful function CreateDIBSection which just needs a DC
CreateDIBSection function (Windows)[^]

You will need to allocate memory to hold the bits. That size is slightly tricky it depends on what color depth you are going to ask for in bits. Typically you want RGB24 or RGB32 and the size also needs to be aligned to a 4 byte boundary. Anyhow long story short its a funny maths calc and we need to setup a bitmap header info for the call ... Lets do 24 bit colour.
BITMAPINFOHEADER BMIH;
BMIH.biSize = sizeof(BITMAPINFOHEADER);
BMIH.biBitCount = 24;
BMIH.biPlanes = 1;
BMIH.biCompression = BI_RGB;
BMIH.biWidth = Wth;
BMIH.biHeight = Ht;
BMIH.biSizeImage = ((((BMIH.biWidth * BMIH.biBitCount)+ 31) & ~31) >> 3) * BMIH.biHeight;

See that funny calc at end well BMIH.biSizeImage now has the memory size you need to allocate. So allocate it and then call CreateDIBSection
char* myBits = malloc(BMIH.biSizeImage);
CreateDIBSection(hDC, (CONST BITMAPINFO*)&BMIH, DIB_RGB_COLORS, (void**)&myBits, NULL, 0);

myBits now has all your image data from the DC now all you need to do is save it!!!!
For a BMP file that is trivial
FILE *pFile = fopen(  /* some Name  */,  "wb");
BITMAPFILEHEADER bmfh;
int nBitsOffset = sizeof(BITMAPFILEHEADER) + BMIH.biSize; 
LONG lImageSize = BMIH.biSizeImage;
LONG lFileSize = nBitsOffset + lImageSize;
bmfh.bfType = 'B'+('M'<<8);
bmfh.bfOffBits = nBitsOffset;
bmfh.bfSize = lFileSize;
bmfh.bfReserved1 = bmfh.bfReserved2 = 0;
// Write bitmap file header
UINT nWrittenFileHeaderSize = fwrite(&bmfh, 1, sizeof(BITMAPFILEHEADER), pFile);
// Write bitmap info header
UINT nWrittenInfoHeaderSize = fwrite(&BMIH, 1, sizeof(BITMAPINFOHEADER), pFile);
// Write our data we got back 
UINT nWrittenDIBDataSize = fwrite(myBits, 1, lImageSize, pFile);
// Close the file
fclose(pFile); 


Now don't forget to free myBits when you are done that is alot of memory to bleed if you forget Smile | :)
In vino veritas


modified 11-Nov-16 0:33am.

QuestionERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
ForNow10-Nov-16 2:41
ForNow10-Nov-16 2:41 
AnswerRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
Chris Losinger10-Nov-16 3:07
professionalChris Losinger10-Nov-16 3:07 
GeneralRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
ForNow10-Nov-16 3:29
ForNow10-Nov-16 3:29 
AnswerRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
Randor 10-Nov-16 4:32
professional Randor 10-Nov-16 4:32 
GeneralRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
ForNow10-Nov-16 4:40
ForNow10-Nov-16 4:40 
GeneralRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
Richard MacCutchan10-Nov-16 4:50
mveRichard MacCutchan10-Nov-16 4:50 
GeneralRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
ForNow10-Nov-16 5:02
ForNow10-Nov-16 5:02 
GeneralRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
leon de boer10-Nov-16 8:25
leon de boer10-Nov-16 8:25 
GeneralRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
ForNow10-Nov-16 8:50
ForNow10-Nov-16 8:50 
GeneralRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
Randor 10-Nov-16 5:06
professional Randor 10-Nov-16 5:06 
AnswerRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
Albert Holguin10-Nov-16 7:32
professionalAlbert Holguin10-Nov-16 7:32 
GeneralRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
ForNow10-Nov-16 7:50
ForNow10-Nov-16 7:50 
GeneralRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
Albert Holguin10-Nov-16 7:58
professionalAlbert Holguin10-Nov-16 7:58 
GeneralRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
leon de boer10-Nov-16 8:38
leon de boer10-Nov-16 8:38 
GeneralRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
ForNow10-Nov-16 8:53
ForNow10-Nov-16 8:53 
QuestionDebug Assertion Failed error by WaitForMultipleObjectsEx in 64 bit application Pin
Member 123356959-Nov-16 20:27
Member 123356959-Nov-16 20:27 
AnswerRe: Debug Assertion Failed error by WaitForMultipleObjectsEx in 64 bit application Pin
Richard MacCutchan9-Nov-16 22:54
mveRichard MacCutchan9-Nov-16 22:54 

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.