|
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)
|
|
|
|
|
I have checked again CreateDIBitmap and I finally got the correct bitmap displaying on my button, so your code works just perfect!
Thank you very much for your time offered to me!
Best regards!
Ioan
|
|
|
|
|
|
Ok, so after trying for hours on end to get things working correctly I am posting here.
I am new to programming and trying to learn. Please provide me with clarification of how I have this screwed up. Also, please include how I can fix this. I learn through practicals.
Also, I have changed things so many times trying to call the function correctly with assigning the correct arguments but I am just so confused at this point I am asking for help.
#define _WIN32_WINNT (0x0601)
#include <windows.h>
#include <winbase.h>
#include <winreg.h>
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
DWORD pdwQuotaAllowed, pdwQuotaUsed;
GetSystemRegistryQuota(&pdwQuotaAllowed, &pdwQuotaUsed);
DWORD dwFlags;
RegGetValue(&dwFlags);
cout << pdwQuotaAllowed << endl;
cout << pdwQuotaUsed << endl;
return 0;
}
|
|
|
|
|
As a newbie to programming I would strongly caution you not to do anything to the registry. If you corrupt an entry you could end up with a totally unusable system.
As to the code you posted you need to read the MSDN documentation for details of how to use particular functions, e.g RegGetValue()[^] needs a lot more parameters than you offered. Once again, I would suggest you find something less likely to damage your system to learn on.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
We can set task manager always on top by check options -> always on top
is that possible we can set our application window always on top
Trioum
|
|
|
|
|
You could create the window using WS_EX_TOPMOST , or use SetWindowPos()[^] to make an existing window have the always-on-top style.
|
|
|
|
|
See also somediscussions here[^].
txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
I would like to update my CListCtrl at specific counts. I have tryed the following code and it does not update the control until the main loop is finished. What am I missing?
for(long x = 0; x != 1000;x++)
{
int iCount = 1000;
int a;
for ( long loop =0; loop != 100;loop++)
{
m_list.InsertItem(0,"Loop test");
}
m_list.UpdateData();
// test delay
do
{
a++;
} while(iCount--);
}
Any constructive help on subject is as always appreciated.
Thanks for reading.
Vaclav
|
|
|
|
|
What does UpdateData() do? The MSDN page[^] doesn't mention such a method.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
"CWnd::UpdateData
This method initializes data in a dialog box, or retrieves and validates dialog data."
To be truthful I am not sure if it does anything in my test case.
I was just trying to make it work for me. It works same wihtout it - the list updates on completion of the loop only.
I vaguely recall using it when I have been accessing (different) list control from functions and not in the loop like this time. It did update the list then.
I am currently looking onto LVITEM and see if it can be used.
Thanks for your input.
Vaclav
|
|
|
|