|
Hi all, I have finally managed to get a TransparentBlt function going in my program, the trouble is I`m finding it is too slow for what I need it to do (especially on larger images, with multiple layers). I am using a MDI app which supports multi layer bitmaps(hence the need for transparency). The OnDraw function is called every time I re-size the window etc. and so it ends up using blt many many times. So basically I wondered if :
1. Alpha Blend was faster?
2. Alpha Blend is capable of simply ommitting to change the color of a pixel where that pixel is the transparent color?
I have only briefly looked through the alpha blend code, and it seems to merely blend two bitmaps together, thus creating a kind of duo-transparency. This isn`t particularly what I want, I just need to get rid of the main background colour of the foreground bitmaps. Any ideas on perhaps how I could speed up the process would be greatly received.
Thankyou all.
Alan.
"When I left you I was but the learner, now I am the Master" - Darth Vader
|
|
|
|
|
I can only give you a limited advice, but this may be better than nothing . In one of my projects, I have to transparently blt a bitmap. TransparentBlt, which is available on Win98 and 2K looks like good idea. However, its performance on Win98 is absolutely abysmal, my own code which creates a mask and then does two blts to destination was orders of magnitude faster.
OTOH, the W2K implementation constantly beats my home-grown solution, sometimes its 100% faster... but not always. It seems that this speedup depends on the video driver - probably some drivers implement this functionality natively, while others do not and GDI must simulate it, creating a mask each time you call TransparentBlt. I've ended with a customizable option - users can enable TransparentBlt on W2K, but it's disabled by default.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I`m using XP Business Edition RC1 at the moment, so god knows what its gonna be like on this. I`m using an adapted version of Christians code, which uses a good few Blts, including a few SRCANDS (they really are speed killers) raster operations. I have heard of a method using one BitBlt (or StretchBlt) and SRCCOPY, but it doesn`t seem to work. I`ll post the code here, and if anyone can see whats wrong cool (remember this is NOT my code, so if it raises any questions, chances are I won`t know the answer).
if(GetDeviceCaps(hdcDest, CAPS1) &C1_TRANSPARENT)
{
oldMode = SetBkMode(hdcDest, NEWTRANSPARENT);
rgbBk = SetBkColor(hdcDest, rgbTransparent);
BitBlt(hdcDest, x, y, dx, dy, hdcSrc, x0, y0, SRCCOPY);
SetBkColor(hdcDest, rgbBk);
SetBkMode(hdcDest, oldMode);
}
Of course, this code doesn`t compile cause it don`t say what oldMode and rgbBk are variables of any particualar type. Even then NEWTRANSPARENT is undefined (I assumed whoever wrote the code #defined it to be = to 1, as SetBkMode's second argument is either 0 (Opaque) or 1(Transparent) as I understand it). I then assumed rgbTransparent to be the colour I don`t want copied onto the CDC (so I gave it a fixed value of 0 for black). Despite all this, it still don`t blinking work. This code would have been perfect for me, had it worked, because my programs layers need to be drawn (and re-drawn) fairly quickly. The strange thing is that Delphi actually manages to cope with this mechanism superbly, with not much performance loss at all, so I know there is a way get the desired results, but what is it?
Anyway cheers all for reading this far (again), and cheers Tomasz for the quick reply,
Alan.
"When I left you I was but the learner, now I am the Master" - Darth Vader
|
|
|
|
|
The key to adequate perf across all Win32 platforms is simple: you have to pre-calculate the mask. If you have the mask, it takes two blts to draw transparently.
Creating the mask requires a two calls to Create[Compatible]Bitmap, two calls to CreateCompatibleDC and two BitBlts. It's *much* more expensive.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Right, got you. I`ve got something to work with now Tomasz, thanks for that. I`ll let you know how I get on.
Thanks again for the quick response,
Alan.
P.S. One more thing, I presume that once you`ve calculated the mask its stored as a HBITMAP variable, ready to be used over and over again?
"When I left you I was but the learner, now I am the Master" - Darth Vader
|
|
|
|
|
I presume that once you`ve calculated the mask its stored as a HBITMAP variable, ready to be used over and over again?
Exaclty. I'm keeping it selected in its own memory DC to reduce overhead.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Cheers Tomasz, everything is now cool.
Alan.
"When I left you I was but the learner, now I am the Master" - Darth Vader
|
|
|
|
|
As far as the functions I wrote are concerned, Alphablend is probably faster because it doesn't generate a mask on the fly, it accesses the bits directly. As Thomasz has said, if you're doing it over & over you're better off splitting the code so you only generate the mask once, that's probably faster again. The way to make my alpha blend function faster is to make sure the bitmap is a DIBSection to start with, then you can use GetObject to get the pointer to the underlying bits.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
Thanks for the response Christian, I`ve decided to go and do it the Alpha Blend way, for the reasons you said. I already had a DIBSection, and the method became alot faster again. I also didn`t have to worry about masks and stuff either, which was the main problem I encountered with TransparentBlt (as Tomasz rightly pointed out).
Cheers for all the help guys,
very much appreciated.
"When I left you I was but the learner, now I am the Master" - Darth Vader
|
|
|
|
|
- Are there any stuff about how to use VC++ to manipulate registry?
- Can you help?
- Regards,
Maer
|
|
|
|
|
|
- Thanks, Michael pal!
- I have taken a look at the URL you mentioned. It is a nice stuff.
- But I am a newbie of the field. I just want to know the basic use of the registry. I think there are too many articles for me to read. )
- Which article(s) is the most suitable to me? Do you have any suggestions?
- Regards,
Maer
|
|
|
|
|
|
- Thanks, Michael pal!
- The URL is a good stuff. It helps a lot.
- Have a nice weekend,
Maer
|
|
|
|
|
take a look at the following functions :-
RegOpenKeyEx
RegQueryInfoKey
RegQueryValueEx
RegEnumKeyEx
RegCreateKeyEx
RegDeleteKey
RegCloseKey
You better understand these calls before you start using those wrapper classes from CP because if you need to customize those classes, you'll need to know how they work
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
Nish is a BIG fan of Goran Ivanisevic
|
|
|
|
|
- Thanks, Nish pal!
- Your reply clarifies all my doubts. Hi, Nish, I think you know all the fields of VC++, arent't you? I think you are a born VC++ programmer.
- Have a nice weekend,
Maer
|
|
|
|
|
Hi,
Has anyone had this problem before:
If I click in the CListCtrl in report view and ALT+TAB toggles to another program (which completly hides the control) and then toggles back to the app with the CListCtrl, the control disappears.
However it works if I don't click the CListCtrl and performs the some thing as above.
I've included the CListCtrl (report view) on a dialog which in turn is on a tab page.
Any ideas anyone?
/Tommy
|
|
|
|
|
I've included the CListCtrl (report view) on a dialog which in turn is on a tab page.
But it isn't a propertypage/sheet, right? Probably you have a problem with z-order. Try to handle WM_ACTIVATEAPP and bring contents of tab to front.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Yes you're right, no propertypage/sheet.
But I tried to loacate which window is on top with GetTopWindow and from the result the CListCtrl should be on top, but maybe the result is incorrect when I'm in debug mode (see comments below).
See if we can narrow the problem down. It works like this:
I have my CTabStrl in the var m_TabCtrl.
I've created several dialogs each of which is "activated" like this when I click on a tab:
void CSystemInfoDlg::OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult)
{
ActivateTab(m_TabCtrl.GetCurSel());
*pResult = 0;
}
void CSystemInfoDlg::ActivateTab(int nTab)
{
if (pCurDlg)
{
pCurDlg->ShowWindow(SW_HIDE);
}
pCurDlg = pDlgs[nTab];
pCurDlg->ShowWindow(SW_SHOW);
}
When I try to debug it works?!!? I'm clicking on a CListCtrl which is on every pDlgs and after toggling away the app and toggling it back and then doing something to reach a breakpoint and then continue with F5, the CListCtrl shows up again... But that doesn't happen if I don't debug...
Any ideas?
/T
|
|
|
|
|
I've dusted off one very old project I was involved in. There was similar problem - there was a CListCltr directly on CDialog (no list controls) which was disappearing after Alt+Tab. Adding a WM_ACTIVATEAPP handler solved the problem:
void CSomeDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CDialog::OnActivate(nState, pWndOther, bMinimized);
if (nState == WA_ACTIVE)
{
m_lst.BringWindowToTop();
}
}
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hmm, I did like this
- Added ON_WM_ACTIVATEAPP in the message map
- Added the OnActivate method to one of the dialogs
- Added a breakpoint at CDialog::OnActivate(...)
but the breakpoint was never found... Did I do something wrong?
/T
|
|
|
|
|
|
[Tomasz, please send me a mail instead because I have to poll for new messages... don't know why but I'm not getting any replies in my mailbox.]
Yes, I clicked the tab -> the dialog with the CListCtrl showed up -> I clicked the CListCtrl somewhere -> tabbed away -> tabbed back -> the CListCtrl is gone.
Now I wanted to check which window was on the top of the z-order by using GetTopWindow(). And I did this by reacting to a click on the dlg, not the CListCtrl, AFTER I had toggled back the app (that is when the CListCtrl had disappeared). So I set a breakpoint in the OnLButtonDown handler to check the handles for the dialog and the ctrl. If the CListCtrl is beneath the dialog then the handles of ctrl and top should NOT be equal. At least that's what I thought...
void CsomeDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
CWnd* ctrl = &m_List;
CWnd* dlg = this;
CWnd* top = GetTopWindow();
}
The handles were all different... but that maybe depends on something else... what wa important here was that when I pressed F5 to continue running the app, the CListCtrl showed up again...?!?!
|
|
|
|
|
Check top->GetDlgCtrlID(). It may give you an idea which window is on top,
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Yes, it did! It says the dialog is on top. But, from what I know the CListCtrl is a child window of the dialog and therefore the ctrl should be visible as well... or is it not a child window? Do I have to make an explicit call to m_List.Create from the dlg to make it a child? I always thought that I if I drag a ctrl on a dialog, the explicit creation of the ctrl is not needed since the wizard adds a variable for me and updates the DDX stuff...
It's like the ctrl doesn't update its painting...
Well, I'll send you a sample project.
/T
|
|
|
|
|