Click here to Skip to main content
15,894,180 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: _controlfp() - function Pin
CPallini27-Aug-09 23:06
mveCPallini27-Aug-09 23:06 
AnswerRe: _controlfp() - function Pin
durban227-Aug-09 23:39
durban227-Aug-09 23:39 
GeneralRe: _controlfp() - function Pin
CPallini27-Aug-09 23:54
mveCPallini27-Aug-09 23:54 
QuestionHow to retrieve the all drives in a computer and their size using VC++ Code Pin
Shiv Murti Pal27-Aug-09 22:54
Shiv Murti Pal27-Aug-09 22:54 
AnswerRe: How to retrieve the all drives in a computer and their size using VC++ Code Pin
ThatsAlok28-Aug-09 0:37
ThatsAlok28-Aug-09 0:37 
AnswerRe: How to retrieve the all drives in a computer and their size using VC++ Code Pin
David Crow28-Aug-09 3:25
David Crow28-Aug-09 3:25 
AnswerRe: How to retrieve the all drives in a computer and their size using VC++ Code Pin
Hamid_RT28-Aug-09 4:59
Hamid_RT28-Aug-09 4:59 
QuestionDC to Bitmap Pin
LuisFilipeSa27-Aug-09 22:13
LuisFilipeSa27-Aug-09 22:13 
Hi everyone!

I am trying to convert a HDC to Bitmap so that I can have a final picture of all bitmap components. Basically in my code what I do is that I have a bitmap at the background then I add other small bitmaps on top of the main bitmap, thus my final goal is to have a "screenshot" such that it is sort of a bitmap containing all other added bitmaps.
However, for some reason the final bitmap comes out in black. Please I need help and suggestions.


The piece of code is the following(in bold is the part of the code to get the final bitmap, which is almost at the end of the code):




void CSpeedoMeter::OnPaint()
{

CPaintDC dc(this);

//HDC thisDC = CreateDC("Desktop", NULL, NULL, NULL);

HDC thisDC = dc.GetSafeHdc();

HDC hdcMem;

//
// Create a compatible DC.
//
hdcMem = CreateCompatibleDC(NULL);


int seconds2 = 300;


int seconds = 3600;

//clock_t endwait = 0;


//if(saveState == true)
{

//getting the number of CumVend from database

//tempDay = ConnectDBFast();
//tempDay = 42000;

//tempWeek = tempDay + ConnectDBWeek(hdcMem);

//tempMonth = tempDay + ConnectDBMonth();
//tempMonth = 7878996;

//tempYear = tempDay + ConnectDBYear();
//tempYear = 7334554;



saveState = false;

//endwait = 0;

endwait = clock() + seconds * CLOCKS_PER_SEC;

//SetCursor(LoadCursor(NULL,IDC_WAIT));

}




if(saveStateFast == true)
{
//getting the number of CumVend from database
//tempDay = ConnectDBFast();

saveStateFast = false;

endwait2 = clock() + seconds2 * CLOCKS_PER_SEC;

}






//
// Get the size of the client rectangle.
//
RECT rc;
GetClientRect(&rc);



//ndh = rc.right - rc.left;
//ndv = rc.bottom - rc.top;
ndh = rc.right - rc.left - 845;
ndv = rc.bottom - rc.top - 140;
C.x = ndh/2;
C.y = ndv/2;
if(ndh > ndv)
needlelength = (int)(ndv/2.5f);
else
needlelength = (int)(ndh/2.5f);
//needlepos.x = ndh/2;
//needlepos.y = ndv/2 + needlelength;

needlepos.x = ndh/2;
needlepos.y = ndv/2 + needlelength - 190;





HBITMAP hBitmap = (HBITMAP)::LoadImage(AfxGetInstanceHandle(), "C:\\Speedometer\\res\\speedometer6.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);

GetObject(hBitmap, sizeof(bitmap), &bitmap);
SelectObject(hdcMem, hBitmap);





SetNeedleColor(RGB(255, 126, 45));


// draw needle
DrawNeedle((int)tempDay, &dc, needlecolor, hdcMem);


// draw font
HFONT hfont, holdfont;
hfont = CreateFontIndirect(&lf);
holdfont = (HFONT) SelectObject(hdcMem, hfont);



//******************************* CODE TO DRAW NUMBERS FOR DAILY SELLS **********************************
RECT fntRc;
fntRc.left = 815;
fntRc.right = 1000;
fntRc.top = 830;
fntRc.bottom = 1080;


//tempDay = 0;

char numm1[20];
string strTotalDay = "";
strTotalDay = itoa(tempDay, numm1, 10);

//int ll = strTotalMonth.length();
string back1 = strTotalDay;

for(int b=0; b < strTotalDay.length(); b++)
{
back1[b] = strTotalDay[strTotalDay.length()-1-b];

}

strTotalDay = back1;

for(int b=0; b < strTotalDay.length(); b++)
{

if(b != 0)
{
//RECT fntRc1;
fntRc.left -= 55;
fntRc.right -= 55;
}

drawNumbers(hdcMem, &dc, fntRc, strTotalDay[b]);

}
////////////////////////////////////////////////////////////////////////////////////////////////


//******************************* CODE TO DRAW NUMBERS FOR WEEKLY SELLS **********************************


RECT fntRc4;
fntRc4.left = 1683;
fntRc4.right = 1868;
fntRc4.top = 150;
fntRc4.bottom = 400;

//tempWeek = 17;

char numm[20];
string strTotalWeek = "";
strTotalWeek = itoa(tempWeek, numm, 10);

//int ll = strTotalMonth.length();
string back4 = strTotalWeek;

for(int b=0; b < strTotalWeek.length(); b++)
{
back4[b] = strTotalWeek[strTotalWeek.length()-1-b];

}

strTotalWeek = back4;


for(int b=0; b < strTotalWeek.length(); b++)
{

if(b != 0)
{
//RECT fntRc1;
fntRc4.left -= 55;
fntRc4.right -= 55;
}

drawNumbers(hdcMem, &dc, fntRc4, strTotalWeek[b]);

}


////////////////////////////////////////////////////////////////////////////////////////////////


//******************************* CODE TO DRAW NUMBERS FOR MONTHLY SELLS **********************************
RECT fntRc1;
fntRc1.left = 1683;
fntRc1.right = 1868;
fntRc1.top = 380;
fntRc1.bottom = 630;

//tempMonth = 11111111;

string strTotalMonth = "";
stringstream ss;
ss << tempMonth;
strTotalMonth = ss.str();

//TextOutA(hdcMem,5,5, strTotalMonth.c_str(),20);

string back = strTotalMonth;

for(int b=0; b < strTotalMonth.length(); b++)
{
back[b] = strTotalMonth[strTotalMonth.length()-1-b];

}

strTotalMonth = back;



for(int b=0; b < strTotalMonth.length(); b++)
{

if(b != 0)
{
//RECT fntRc1;
fntRc1.left -= 55;
fntRc1.right -= 55;
}

drawNumbers(hdcMem, &dc, fntRc1, strTotalMonth[b]);

}
/////////////////////////////////////////////////////////////////////////////////////////////////////



//******************************* CODE TO DRAW NUMBERS FOR YEARLY SELLS **********************************
RECT fntRc3;
fntRc3.left = 1683;
fntRc3.right = 1868;
fntRc3.top = 610;
fntRc3.bottom = 860;


//tempYear = 15556;

char numm2[20];
string strTotalYear = "";
strTotalYear = itoa(tempYear, numm2, 10);

string back2 = strTotalYear;

for(int b=0; b < strTotalYear.length(); b++)
{
back2[b] = strTotalYear[strTotalYear.length()-1-b];

}

strTotalYear = back2;


for(int b=0; b < strTotalYear.length(); b++)
{

if(b != 0)
{
//RECT fntRc1;
fntRc3.left -= 55;
fntRc3.right -= 55;
}

drawNumbers(hdcMem, &dc, fntRc3, strTotalYear[b]);

}
///////////////////////////////////////////////////////////////////////////////////////////////////////////





//HWND window;
const char* filename = "res\\speedomoterSCREEN.bmp";

// get screen rectangle
//GetWindowRect(&rc);

// bitmap dimensions
int bitmap_dx = rc.right - rc.left;
int bitmap_dy = rc.bottom - rc.top;

// create file
ofstream file(filename, ios::binary);
if(!file) return;

// save bitmap file headers
BITMAPFILEHEADER fileHeader;
BITMAPINFOHEADER infoHeader;

fileHeader.bfType = 0x4d42;
fileHeader.bfSize = 0;
fileHeader.bfReserved1 = 0;
fileHeader.bfReserved2 = 0;
fileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);

infoHeader.biSize = sizeof(infoHeader);
infoHeader.biWidth = bitmap_dx;
infoHeader.biHeight = bitmap_dy;
infoHeader.biPlanes = 1;
infoHeader.biBitCount = 24;
infoHeader.biCompression = BI_RGB;
infoHeader.biSizeImage = 0;
infoHeader.biXPelsPerMeter = 0;
infoHeader.biYPelsPerMeter = 0;
infoHeader.biClrUsed = 0;
infoHeader.biClrImportant = 0;

file.write((char*)&fileHeader, sizeof(fileHeader));
file.write((char*)&infoHeader, sizeof(infoHeader));

// dibsection information
BITMAPINFO info;
info.bmiHeader = infoHeader;

// ------------------
// THE IMPORTANT CODE
// ------------------
// create a dibsection and blit the window contents to the bitmap
//HDC winDC = GetWindowDC(window);
HDC memDC = CreateCompatibleDC(NULL);
BYTE *memory = 0;
HBITMAP bitmap = CreateDIBSection(hdcMem, &info, DIB_RGB_COLORS, (void**)&memory, 0, 0);
SelectObject(memDC, bitmap);







BitBlt(thisDC, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, hdcMem, 0, 0,SRCCOPY);




DeleteDC(memDC);
//ReleaseDC(window, winDC);

const char *memory1 = (char*)memory;

// save dibsection data
int bytes = (((24*bitmap_dx + 31) & (~31))/8)*bitmap_dy;
file.write(memory1, bytes);


DeleteObject(bitmap);





//DeleteObject(font1);
DeleteObject(hfont);
DeleteObject(holdfont);
DeleteObject(hBitmap);

DeleteDC(hdcMem);
DeleteDC(thisDC);



if(clock() >= endwait)
{
saveState = true;
}



if(clock() >= endwait2)
{
saveStateFast = true;
}



Invalidate();


}
AnswerRe: DC to Bitmap Pin
CPallini27-Aug-09 22:38
mveCPallini27-Aug-09 22:38 
GeneralRe: DC to Bitmap Pin
LuisFilipeSa27-Aug-09 23:42
LuisFilipeSa27-Aug-09 23:42 
GeneralRe: DC to Bitmap Pin
CPallini27-Aug-09 23:56
mveCPallini27-Aug-09 23:56 
GeneralRe: DC to Bitmap Pin
LuisFilipeSa30-Aug-09 23:33
LuisFilipeSa30-Aug-09 23:33 
QuestionOleDb Application Pin
andrew_dk27-Aug-09 21:50
andrew_dk27-Aug-09 21:50 
QuestionTracking tooltip double-click problem when using XP manifest (ComCtl32.dl) [modified] Pin
Moak27-Aug-09 13:48
Moak27-Aug-09 13:48 
AnswerRe: Tracking tooltip double-click problem when using XP manifest (ComCtl32.dl) Pin
Moak1-Sep-09 4:25
Moak1-Sep-09 4:25 
QuestionUsing GetThreadContext to get the Program Counter of a thread Pin
Code-o-mat27-Aug-09 11:15
Code-o-mat27-Aug-09 11:15 
GeneralRe: Using GetThreadContext to get the Program Counter of a thread Pin
harold aptroot27-Aug-09 11:48
harold aptroot27-Aug-09 11:48 
GeneralRe: Using GetThreadContext to get the Program Counter of a thread Pin
Code-o-mat27-Aug-09 12:07
Code-o-mat27-Aug-09 12:07 
GeneralRe: Using GetThreadContext to get the Program Counter of a thread Pin
harold aptroot27-Aug-09 12:11
harold aptroot27-Aug-09 12:11 
GeneralRe: Using GetThreadContext to get the Program Counter of a thread Pin
Code-o-mat27-Aug-09 20:19
Code-o-mat27-Aug-09 20:19 
Questionraw input only to an application Pin
Manikandan27-Aug-09 7:47
Manikandan27-Aug-09 7:47 
QuestionIllegal Indirection Error - CertFindChainInStore Pin
mypicturefaded27-Aug-09 6:24
mypicturefaded27-Aug-09 6:24 
AnswerRe: Illegal Indirection Error - CertFindChainInStore Pin
Rajesh R Subramanian27-Aug-09 6:42
professionalRajesh R Subramanian27-Aug-09 6:42 
GeneralRe: Illegal Indirection Error - CertFindChainInStore Pin
mypicturefaded27-Aug-09 6:50
mypicturefaded27-Aug-09 6:50 
GeneralRe: Illegal Indirection Error - CertFindChainInStore Pin
Rajesh R Subramanian27-Aug-09 9:52
professionalRajesh R Subramanian27-Aug-09 9:52 

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.