C language > Windows questions
BitBlt
HellOfMice:
I would like to make sprites using BitBlt. I join a program to see the problem I have.
I have read this : https://social.msdn.microsoft.com/Forums/vstudio/en-US/3ff67e63-3ea3-4235-8763-94f7ef3c7b9c/windows-api-understanding-srcinvert-in-the-bitblt-function?forum=windowsgeneraldevelopmentissues
But No Good result!
I would like some help.
My program is at: https://www.mediafire.com/file/aj0eykop4e3r2ab/Navette.7z/file
Thank you for your help.
HellOfMice:
Now it is OK
Here is the result
I remove the files from Mediafire
How I did?
--- Code: ---HBITMAP CreateBitmapMask(HWND __hWnd,HBITMAP __hBmpObject,HBITMAP __hBmpMask,LPBITMAP __lpBitmap)
{
HDC _hDC, _hDCObject, _hDCMask, _hDCNewMask ;
HBITMAP _hBmpObjectOld, _hBmpMaskOld, _hBmpNewMask, _hBmpNewMaskOld ;
_hBmpNewMask = NULL ;
GetObject(__hBmpObject,sizeof(BITMAP),__lpBitmap) ;
_hDC = GetDC(__hWnd) ;
if(_hDC)
{
_hDCObject = CreateCompatibleDC(_hDC) ;
if(_hDCObject)
{
_hDCMask = CreateCompatibleDC(_hDC) ;
if(_hDCMask)
{
_hDCNewMask = CreateCompatibleDC(_hDC) ;
if(_hDCNewMask)
{
_hBmpNewMask = CreateCompatibleBitmap(_hDC,__lpBitmap->bmWidth,__lpBitmap->bmHeight) ;
if(_hBmpNewMask)
{
_hBmpNewMaskOld = SelectObject(_hDCNewMask,_hBmpNewMask) ;
if(_hBmpNewMaskOld)
{
_hBmpMaskOld = SelectObject(_hDCMask,__hBmpMask) ;
if(_hBmpMaskOld)
{
_hBmpObjectOld = SelectObject(_hDCObject,__hBmpObject) ;
if(_hBmpObjectOld)
{
SetTextColor(_hDCObject,0x00FF00) ;
BitBlt(_hDCNewMask,0,0,__lpBitmap->bmWidth,__lpBitmap->bmHeight,_hDCMask,0,0,SRCCOPY) ;
BitBlt(_hDCNewMask,0,0,__lpBitmap->bmWidth,__lpBitmap->bmHeight,_hDCObject,0,0,SRCINVERT) ;
SelectObject(_hDCObject,_hBmpObjectOld) ;
}
SelectObject(_hDCMask,_hBmpMaskOld) ;
}
SelectObject(_hDCNewMask,_hBmpNewMaskOld) ;
}
}
DeleteDC(_hDCNewMask) ;
}
DeleteDC(_hDCMask) ;
}
DeleteDC(_hDCObject) ;
}
ReleaseDC(__hWnd,_hDC) ;
}
return (_hBmpNewMask) ;
}
--- End code ---
First I create the mask.
The mask is green and black
I want to keep the black part.
--- Code: ---static void Navette_OnPaint(HWND __hWnd)
{
PAINTSTRUCT _Ps ;
RECT _Rc ;
BITMAP _Bitmap ;
HDC _hDC, _hDCMem, _hDCMask, _hDCBackground ;
HBITMAP _hBitmap, _hBitmapOld, _hBmpBgOld, _hBmpMask, _hBmpMaskOld ;
DWORD _dwNewWidth, _dwNewHeight ;
_hDC = BeginPaint(__hWnd,&_Ps) ;
if(_hDC)
{
_hDCMem = CreateCompatibleDC(_hDC) ;
if(_hDCMem)
{
_hDCBackground = CreateCompatibleDC(_hDC) ;
if(_hDCBackground)
{
_hBmpBgOld = SelectObject(_hDCBackground,lpBackground->hImgBitmap) ;
if(_hBmpBgOld)
{
_hBmpMask = CreateBitmapMask(__hWnd,lpNavette->hImgBitmap,lpNavette_Mask->hImgBitmap,&_Bitmap) ;
if(_hBmpMask)
{
_hDCMask = CreateCompatibleDC(_hDC) ;
if(_hDCMask)
{
_hBmpMaskOld = SelectObject(_hDCMask,_hBmpMask) ;
if(_hBmpMaskOld)
{
GetClientRect(__hWnd,&_Rc) ;
_hBitmap = CreateCompatibleBitmap(_hDC,_Rc.right,_Rc.bottom) ;
if(_hBitmap)
{
_hBitmapOld = SelectObject(_hDCMem,_hBitmap) ;
if(_hBitmapOld)
{
ImageResize(lpBackground->BitmapInfo.bmiHeader.bV5Width,lpBackground->BitmapInfo.bmiHeader.bV5Height,_Rc.right,_Rc.bottom,&_dwNewWidth,&_dwNewHeight) ;
SetStretchBltMode(_hDC,COLORONCOLOR) ;
SetStretchBltMode(_hDCMem,COLORONCOLOR) ;
BitBlt(_hDCBackground,100,100,_Bitmap.bmWidth,_Bitmap.bmHeight,_hDCMask,0,0,SRCPAINT) ;
StretchBlt(_hDCMem,0,0,_dwNewWidth,_dwNewHeight,_hDCBackground,0,0,lpBackground->BitmapInfo.bmiHeader.bV5Width,lpBackground->BitmapInfo.bmiHeader.bV5Height,SRCCOPY) ;
BitBlt(_hDC,(_Rc.right - _dwNewWidth) / 2,(_Rc.bottom - _dwNewHeight) / 2,_dwNewWidth,_dwNewHeight,_hDCMem,0,0,SRCCOPY) ;
SelectObject(_hDCMem,_hBitmapOld) ;
}
DeleteObject(_hBitmap) ;
}
SelectObject(_hDCMask,_hBmpMaskOld) ;
}
DeleteDC(_hDCMask) ;
}
DeleteObject(_hBmpMask) ;
}
SelectObject(_hDCBackground,_hBmpBgOld) ;
}
DeleteDC(_hDCBackground) ;
}
DeleteDC(_hDCMem) ;
}
EndPaint(__hWnd,&_Ps) ;
}
return ;
}
--- End code ---
The problem is that americans painted some part of the shuttle in black.
If they used RED I would have not any problem.
HellOfMice:
All the sources for the Navette program are at : https://www.mediafire.com/file/ef38r19ythcesog/Navette.7z/file
Now the shuttle is moving.
Is someone asked me the goal of this program, it is for making the shuttle to advance...
John Z:
Hi Hello...
"If they used RED I would have not any problem." :)
Got it I'll try for warp speed. Congratulations on figuring it out too.
Will be interesting to see the code in action.
John Z
P.S. Why does the program name keep changing ;D ;D ;D
P.P.S. Have suggested in the past Pelles Forum raise the upload size limit a bit, 1Meg is fairly small these days.
Update: Very cool. Not a barn burner but like to see it moving across the sky !
Update2: Be sure to run it full screen... in a tiny window the shuttle does not traverse the entire picture, in full screen it does :)
HellOfMice:
It is moving but very slowly I look at why and search something to do.
The name of the program change because I want to keep the previous like it is and set the improvments on the other.
It's like a backup. It is a first idea now I see what I can do more
I have an idea for the shuttle color: White with a red point!
1 Mb must be enough for writing a pgm on a casio...
Perhaps the admin does use the forum...
Navigation
[0] Message Index
[#] Next page
Go to full version