Hi:
Now I'm practising with bitmaps and drawing. Things are going well (very
well) except for this problem:
I call a function which creates a pattern brush, which bitmap is
constructed on the fly based on the current selected color, it receives
the HBITMAP and the HWND, the scrollbars position through a couple of
int variables and the selected color.
In the main source I choose the color with ChooseColor function like
this (comments added in the mail):
case ID_COLOR:
{
CHOOSECOLOR chc;
ZeroMemory(&chc, sizeof(CHOOSECOLOR));
chc.lStructSize = sizeof(CHOOSECOLOR);
chc.hwndOwner = hwnd;
chc.rgbResult = rgbCol;//Current selected color, its a static
variable
chc.lpCustColors = rgbCust;
chc.Flags = CC_RGBINIT | CC_FULLOPEN;
if (ChooseColor(&chc)){
rgbCol = chc.rgbResult;//if success I change the current color
and I change the current pen.
logPen.lopnColor = rgbCol;
}
}
break;
Then when I want to scroll the image and when calling that function,
used when lbuttondwon either during mousemove or mouse still, but no
other functions with same arguments than this. I got the errors 1400
INVALID_WINDOW_HANDLE and 5 ERROR_ACCESS_DENIED.
It's like the HWND to the window gets invalidated, since when this
happens then the mouse does nothing in the window and it has to be
closed with the task manager.
Some times it only reports the error 5 the first time I try to use the
brush function but then it works well again.
I did some changes, adding more GetLastError calls:
If I call the brush then I get the error 5 the first time and the brush
is drawn, after hdc = GetDC(hwnd), and from that moment everything work
again, if I try to scroll first the I get the error 1400 (I forgot say
at the end of WM_XSCROLL I call a function for draw the image which
receives the hwnd, hbm, scroll positions and which scroll changed.) and
the window has to be closed through the task manager.
I don't see any difference with the win32api reference in the color
selection code, and I don't kno how it could affect the window handle.
Am I missing something?
The other question is how can I get the bits of the bitmap in a buffer??
I use GetDIBits but:
If I alloc memory for the buffer GetDIBits returns with
NOT_ENOUGH_MEMORY error, if I increase the memory allocated I only
achieve having this error with GlobalAlloc, if I don't alloc and say,
'perhaps it allocates itself the memory', it seems like it hasn't
allocated memory and has not filled the buffer and when I try to access
to the members I get an access violation (pvBits[n], pvBits is not a
LPVOID, it is LPBYTE).
I want it for knowing the n-th pixel is of this color.
Where can I find examples of using Get/Set DIBits and CreateDIBSection?,
what I find is using MFC, or source code with not enough explanations.
So I can't see what I am doing wrong.
Thanks
|