|
I want to display a bitmap that has an alpha chanel for the background.
How can I make the alpha chanel transparent?
I tried using AlphaBlend() but it doesn't work.
Any suggestions?
danginkgo
|
|
|
|
|
|
I can't figure it out...
What shall I use to dispaly the bmp?
danginkgo
|
|
|
|
|
Hi,
Here is an article explaining alpha blending:
Alpha Blending using GDI+[^]
Regards,
Suman
--
"Programming is an art that fights back!"
|
|
|
|
|
I am using GDI.
Is alpha blending posible only with GDI+ ?
I want to blend only the background.
Thank You for the answers.
danginkgo
|
|
|
|
|
|
danginkgo wrote: I tried using AlphaBlend() but it doesn't work.
How did you do this? What values did you use in the BLENDFUNCTION struct?
Is the bitmap 32bpp? What does "doesn't work" mean.
|
|
|
|
|
This is my BLENDFUNCTION struct:
<br />
BLENDFUNCTION blendF; <br />
blendF.BlendOp = AC_SRC_OVER; <br />
blendF.BlendFlags = 0; <br />
blendF.SourceConstantAlpha = 255; <br />
blendF.AlphaFormat = AC_SRC_ALPHA; <br />
The bitmap is 32 bpp with an alpha chanel.
When I display the image using AlphaBlend() function the image looks the same as when I displayed it using BitBlt().
I want the background (wich has an alpha chanel) to be transparent.
Is it posible using this function?
danginkgo
|
|
|
|
|
danginkgo wrote: When I display the image using AlphaBlend() function the image looks the same as when I displayed it using BitBlt().
Then all the alpha channel values must be 255.
danginkgo wrote: Is it posible using this function?
Yes. Try something like this, creating and rendering your own 32bpp ARGB bitmap:
LONG lImageWidth = 640;
LONG lImageHeight = 480;
WORD wBitsPerPixel = 32;
LONG lStride = lImageWidth * 4;
BYTE* pBitmapBits;
BITMAPINFO bmi;
memset(&bmi, 0, sizeof(BITMAPINFO));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = lImageWidth;
bmi.bmiHeader.biHeight = lImageHeight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = wBitsPerPixel;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = lStride * lImageHeight;
HDC hdcMem = ::CreateCompatibleDC(0);
HBITMAP hBitmap = ::CreateDIBSection(hdcMem, &bmi, DIB_RGB_COLORS, (void**)&pBitmapBits, NULL, 0);
if (hBitmap)
{
memset(pBitmapBits, 0, bmi.bmiHeader.biSizeImage);
RGBQUAD *pCurPixel = (RGBQUAD *)pBitmapBits;
int PixelCount = lImageWidth * lImageHeight;
while (PixelCount > 0)
{
(*pCurPixel).rgbRed = 0x00;
(*pCurPixel).rgbGreen = 0x00;
(*pCurPixel).rgbBlue = 0xA0;
(*pCurPixel).rgbReserved = 0x80;
pCurPixel++;
PixelCount--;
}
HGDIOBJ hOldBitmap = ::SelectObject(hdcMem, hBitmap);
HDC hClientDC = ::GetDC(*this);
HPEN hPen = ::CreatePen(PS_SOLID, 10, RGB(255,0,128));
HGDIOBJ hOldPen = ::SelectObject(hClientDC, hPen);
::MoveToEx(hClientDC, 0, 0, NULL);
::LineTo(hClientDC, 650, 490);
::SelectObject(hClientDC, hOldPen);
::DeleteObject(hPen);
BLENDFUNCTION bf;
bf.BlendOp = AC_SRC_OVER;
bf.BlendFlags = 0;
bf.SourceConstantAlpha = 0xFF;
bf.AlphaFormat = AC_SRC_ALPHA;
::AlphaBlend(hClientDC, 0, 0, lImageWidth, lImageHeight,
hdcMem, 0, 0, lImageWidth, lImageHeight, bf);
::ReleaseDC(*this, hClientDC);
::SelectObject(hdcMem, hOldBitmap);
::DeleteObject(hBitmap);
}
::DeleteDC(hdcMem);
|
|
|
|
|
Hi,
Is there a way I could add a browser window - like control, on my dialog?
Thank you,
AJ
|
|
|
|
|
In VC6 IDE, you have option to add ActiveX controls via your resource editor.
Take menu Projects->Add to project->Components and Controls will bring a dialog.
Double click on Registered ActiveX Controls and select Microsoft Web Browser from the list of controls displayed.
This will ask you permission to add support of IE into your application. Select button OK will copy the required header files into your project folder.
Now take the resource editor, where you can see a new control appeared for inserting IE as a control.
Drag and drop it into your dialog and enjoy.
|
|
|
|
|
Thanks a lot!!
Is there a way we could do this in Win32?
|
|
|
|
|
you have use CreateWindow api for doing same in Win32!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/xml>
|
|
|
|
|
Thank you!!
I found another link...
http://support.microsoft.com/kb/q192560/
|
|
|
|
|
|
Pls advice me How to Increase the hight of the status bar in MDI applcation (working on MFC)
Thanks
|
|
|
|
|
I had to do this early on in my MFC career and I did it by enlarging the font associated with the status bar. (I had to display some icons in the panes and they were getting clipped.)
I am sure there is a better and more elegant way, though... Maybe overriding the drawing/measuring of the status bar?
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
1. Derive a class say CMyStatusBar from CStatusBar
2. Override method OnCreate.
3. Add the following code after calling create
CStatusBarCtrl& BarCtrl = GetStatusBarCtrl();
BarCtrl.SetMinHeight( 40 ); // The new width of status bar
Open CMainFrm.h
Include the header file MyStatusBar.h
Replace CStatusBar m_wndStatusBar; with CMyStatusBar m_wndStatusBar;
This should work
|
|
|
|
|
can anybody tell me how to set static IP address using c++ code using win32 API.I am doing it in following way:
InitializeWMI();
const BSTR ClassName = SysAllocString(L"Win32_NetworkAdapterConfiguration");
const BSTR AdapterName = SysAllocString(ADAPTER_INDEX);
const BSTR MethodName = SysAllocString(L"EnableStatic");
IWbemClassObject* pClassObj = NULL;
IWbemClassObject* pInClass = NULL;
IWbemClassObject* pInInstClass = NULL;
IWbemServices *pSvc = NULL ;
LONG index[1]={0};
HRESULT hr = pSvc->GetObject(ClassName,0,NULL,&pClassObj,NULL);///at this point its showing unhandled exception
can anybody help???
|
|
|
|
|
an89 wrote: InitializeWMI();
const BSTR ClassName = SysAllocString(L"Win32_NetworkAdapterConfiguration");
const BSTR AdapterName = SysAllocString(ADAPTER_INDEX);
const BSTR MethodName = SysAllocString(L"EnableStatic");
IWbemClassObject* pClassObj = NULL;
IWbemClassObject* pInClass = NULL;
IWbemClassObject* pInInstClass = NULL;
IWbemServices *pSvc = NULL ;
LONG index[1]={0};
HRESULT hr = pSvc->GetObject (ClassName,0,NULL,&pClassObj,NULL);///at this point its showing unhandled exception
Well, for starters it looks like pSvc is still NULL so that would cause the exception...
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
The problem is in synchronize mode (SND_SYNC) PlaySound Function will block any GUI update calling before the function it self.
Since in MSDN it state that PlaySound with SND_SYNC parameter will not return until the sound is finished playing.
So I expect that any GUI-call calling before PlaySound should take an effect before playing the sound.
eg
this->m_editName.SetWindowText(_T("My name"));
this->m_buttonShow.EnableWindow(FALSE);
PlaySound(_T("c:\test.wav"),NULL,SND_SYNC);
this suppose to update the two control before start playing sound (in synchronize mode) ,
instead the control update after the sound had been played.
putting Sleep() after line two doesn't help either.
since I need my program to play the sound in synchronize mode (blocking any call until the sound is finish playing)
so SND_ASYNC cannot be use.
|
|
|
|
|
Every window updation is happening via MESSAGES. In your code, the PlaySound is blocking the windows MESSAGES as well. To overcome this problem you can insert the following code just before the PlaySound function.
MSG msg;
CWinApp* pApp = AfxGetApp();
while(PeekMessage(&msg,0,0,0,0))
pApp->PumpMessage();
|
|
|
|
|
Rather than doing a peek / message pump, which is very vulnerable to errors, you can simply do UpdateWindow.
Ie:
m_editName.SetWindowText (_T("My name"));
m_buttonShow.EnableWindow (FALSE);
m_editName.UpdateWindow ();
m_buttonShow.UpdateWindow ();
Hope that helps,
Iain.
Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.
|
|
|
|
|
everyone , Thank for your answers.
|
|
|
|
|
I want to move a captionless dialog by clicking on the Move sub-item of menu bar which is poped up after clicking the dialog's icon on the title bar.
Can anybody help?
Ummar
<div class="ForumMod">modified on Monday, July 7, 2008 7:52 AM</div>
|
|
|
|