|
Wow, I did not know it !
Thank you very much, Roger !
As possible "workaround"
could be also the usage of a limitation function:
bool CYourDialog::IsWorking() {
return m_bWorking;
}
virtual void BeHappy() = 0;
|
|
|
|
|
Eugen Podsypalnikov wrote: Wow, I did not know it !
Thank you very much, Roger !
You're most welcome.
Eugen Podsypalnikov wrote: As possible "workaround"
could be also the usage of a limitation function:
bool CYourDialog::IsWorking() {
return m_bWorking;
}
Naah, I wouldn't count on that. This also depends on your optimization settings...
There's a compiler switch that tells the compiler to expand "any suitable" function as inline , which would generate the same code as if you would have referenced the variable directly even though you haven't declared the function explicitly as inline . Then you would be back to square one, with the possibility that the variable could be optimized into a register.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Yes, saved...
Thank you - for the both explanations, Roger !
virtual void BeHappy() = 0;
|
|
|
|
|
Eugen Podsypalnikov wrote: DWORD WINAPI CYourDialog::ThreadProc(CYourDialog* pcDlg)
Shouldn't this be:
UINT CYourDialog::ThreadProc( LPVOID pcDlg )
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Yes, of course
You could use my declaration too
and pass it by the casting (AFX_THREADPROC) ,
so you can use its parameter pcDlg without casting...
virtual void BeHappy() = 0;
|
|
|
|
|
Thanks for reply,
But i already written that it is working for static and global function.
What i want is that it is work for member function.
I am waiting for reply
thanks
|
|
|
|
|
kartikthakre wrote: What i want is that it is work for member function.
You can't do it directly. What you'll have to do is:
void CMyDlg::ThreadProc( void )
{
...
}
UINT ThreadProc( LPVOID lpParam )
{
CMyDlg *pDlg = (CMyDlg *) lpParam;
pDlg->ThreadProc();
return 0;
}
static UINT CMyDlg::ThreadProc( LPVOID lpParam )
{
CMyDlg *pDlg = (CMyDlg *) lpParam;
pDlg->ThreadProc();
return 0;
}
AfxBeginThread(ThreadProc, this);
AfxBeginThread(::ThreadProc, this);
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
but what is the region, so that member function pointer is not pass to AfxBeginThread.
|
|
|
|
|
Hello all!
I have a BITMAPINFOHEADER variable and I try to get HBitmap from it.
I have study MSDN documentation and found that BITMAPINFOHEADER variable must be converted to BITMAPINFO and after use CreateDIBSection(...) function like the summary below:
BITMAPINFO*pInfo;
void *pBuffer;
HBITMAP hBitmap;
if ((hBitmap = CreateDIBSection(NULL, pInfo, DIB_RGB_COLORS, &pBuffer, 0, 0)) != NULL)
{
...
}
My problem is that I do not understand very clear how to convert BITMAPINFOHEADER to BITMAPINFO.
According to the same MSDN I know that BITMAPINFO is a structure that contain the initial BITMAPINFOHEADER, my problem is that I do not underatand how to indicate extra RGBQUAD bmiColors[1] as the declaration below:
typedef struct tagBITMAPINFO {
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO;
Any idea?
|
|
|
|
|
Ionut Codrut wrote: My problem is that I do not understand very clear how to convert BITMAPINFOHEADER to BITMAPINFO.
just cast it.
BITMAPINFO *pBMI = (BITMAPINFO *)pBitmapInfoHeader;
|
|
|
|
|
Thank you Chris for your response!
I try to cast directly as you suggest, but all I've got is just a blank image (so I think the approach is an error)
Acordingly to MSDN http://msdn.microsoft.com/en-us/library/dd318229%28VS.85%29.aspx[^] If you cast the BITMAPINFOHEADER to a BITMAPINFO, the bmiHeader member refers to the BITMAPINFOHEADER and the bmiColors member refers to the first entry in the color table, or the first color mask.
Be aware that if the bitmap uses a color table or color masks, then the size of the entire format structure (the BITMAPINFOHEADER plus the color information) is not equal to sizeof(BITMAPINFOHEADER) or sizeof(BITMAPINFO). You must calculate the actual size for each instance....
So I think we are Close, but no cigar..
Best regards!
Ioan
|
|
|
|
|
casting is correct.
but yes, it's also true that you need to find the start of the pixel data in the DIB, and that depends on the number of colors in the palette, any padding, any bitfields masks, etc..
LPBITMAPINFOHEADER lpbi = (LPBITMAPINFOHEADER)pDIB;
HBITMAP hbm;
int nColors = lpbi->biClrUsed ? lpbi->biClrUsed :
1 << lpbi->biBitCount;
BITMAPINFO &bmInfo = *(LPBITMAPINFO)pDIB ;
LPVOID lpDIBBits;
if( bmInfo.bmiHeader.biBitCount > 8 )
{
lpDIBBits = (LPVOID)((UINT32 *)(bmInfo.bmiColors +
bmInfo.bmiHeader.biClrUsed) +
((bmInfo.bmiHeader.biCompression == BI_BITFIELDS) ? 3 : 0));
}
else
{
lpDIBBits = (LPVOID)(bmInfo.bmiColors + nColors);
}
void *ppvBits = NULL;
hbm = CreateDIBSection(hDC,
(LPBITMAPINFO)lpbi,
DIB_RGB_COLORS,
&ppvBits,
NULL,
0);
if (ppvBits!=NULL)
{
memcpy((BYTE *)ppvBits, (BYTE *)lpDIBBits, bmInfo.bmiHeader.biSizeImage);
}
|
|
|
|
|
Hello Chris!
Thank you very much for your extremely fast response!!!
//This is my starting point:
HBITMAP hbm;
BITMAPINFOHEADER *pHeader;
pHeader = (BITMAPINFOHEADER *)(myImage.bmp.begin() );
// doesn' matter myImage.bmp.begin() is coming from
I need to extract fron this pHeader a HBITMAP to put intr-o a dialog as below:
//This is my end point
m_TestBitButtonCtrl.SetBitmap(hbm);
I do not understand the followings:
1. where pDIB comes from
2. if ia necessary the last function (with copy DIB pixels) for what I need
Ioan
|
|
|
|
|
pDIB is your input image. it's a pointer to a DIB, which is a device-independent bitmap: a BITMAPINFOHEADER followed by a palette, followed by the pixel data.
you need the memcpy because CreateDIBSection only allocates the memory for the DIBSection. you need to put your own pixel data into the allocated memory.
and note that a DIBSection is not a standard HBITMAP. you can use a DIBSection as if it was an HBITMAP, and it will work exactly the same as a standard HBITMAP for most uses, but it's not exactly the same thing. see the MSDN for the differences. if you need a standard HBITMAP, you can use CreateDIBitmap instead of CreateDIBSection:
hbm = CreateDIBitmap(hDC,
(LPBITMAPINFOHEADER)lpbi,
(LONG)CBM_INIT,
lpDIBBits,
(LPBITMAPINFO)lpbi,
DIB_RGB_COLORS );
|
|
|
|
|
Chris, I'm a newbie to this deep API functions, all the information I've got from an external API is just this BITMAPINFOHEADER* pHeader, nothing more and I need only HBITMAP to extract from them, do not care by which method, my interest is to set a button picture with this bitmap, and that's all!
So let me understand correctly: to obtain the correct HBITMAP do I need extra info, the BITMAPINFOHEADER provideed is not sufficent?
best wishes!
Ioan
|
|
|
|
|
Ionut Codrut wrote: all the information I've got from an external API is just this BITMAPINFOHEADER* pHeader, nothing more
that's all you need.
what happens if you use the code i posted ?
|
|
|
|
|
I have used your code as below:
BITMAPINFOHEADER *pHeader;
pHeader = (BITMAPINFOHEADER *)(odImage.bmp.begin() );
if(!pHeader)
return TRUE;
HBITMAP hbm;
// how many colors in this DIB?
int nColors = pHeader->biClrUsed ? pHeader->biClrUsed : 1 << pHeader->biBitCount;
BITMAPINFO &bmInfo = *(LPBITMAPINFO)pHeader ;// make cast from BITMAPINFOHEADER!
LPVOID lpDIBBits;
if( bmInfo.bmiHeader.biBitCount > 8 )
{
lpDIBBits = (LPVOID)((UINT32 *)(bmInfo.bmiColors +
bmInfo.bmiHeader.biClrUsed) + ((bmInfo.bmiHeader.biCompression == BI_BITFIELDS) ? 3 : 0));
}
else
{
lpDIBBits = (LPVOID)(bmInfo.bmiColors + nColors);
}
void *ppvBits = NULL;
hbm = CreateDIBSection(NULL,
(LPBITMAPINFO)pHeader,
DIB_RGB_COLORS,
&ppvBits,
NULL,
0);
m_TestBitButtonCtrl.SetBitmap(hbm);
I'm still got a black bitmap, HBITMAP is not NULL (checked with debug!).
Strange!
What I'm wrong?
Ioan
|
|
|
|
|
what are the values in the BITMAPINFOHEADER struct ?
|
|
|
|
|
|
those all look fine.
what happens if you use the CreateDIBitmap function instead of CreateDIBSection ?
|
|
|
|
|
Chris, the results seem to be the same, a black bitmap. Anyway in both cases it seems that there is something wrong with HBITMAP itself. I have attach a picture for that.
http://www.cnc-router.ro/temp/Screen1.JPG[^]
|
|
|
|
|
what do you get if you draw the original DIB (try StretchDIBits)
|
|
|
|
|
I'm struggle to implement it!
Keep you informed ASAP
|
|
|
|
|
I try this code:
int iRet = StretchDIBits(NULL,
// destination rectangle
0, 0, bmInfo.bmiHeader.biWidth, bmInfo.bmiHeader.biHeight,
// source rectangle
0, 0, bmInfo.bmiHeader.biWidth, -bmInfo.bmiHeader.biHeight,
ppvBits,
&bmInfo,
DIB_RGB_COLORS,
SRCCOPY);
But the function generates me an errror..
|
|
|
|
|
that first parameter has to be a valid DC (NULL is not a valid DC)
|
|
|
|