|
This is what U need
void MyTransparentBlt( HDC hdcDest, int nXDest, int nYDest, int nWidth,
int nHeight, HDC hBmpDC/*, HBITMAP hBitmap*/, int nXSrc, int nYSrc,
COLORREF colorTransparent, HPALETTE hPal)
{
HDC hdcMask = ::CreateCompatibleDC( hdcDest );
HDC hdcTmp = ::CreateCompatibleDC( hdcDest );
HBITMAP bmMask = ::CreateBitmap( nWidth, nHeight, 1, 1, NULL );
HBITMAP hOldMaskBitmap = (HBITMAP)::SelectObject( hdcMask, bmMask );
HBITMAP hTmpBmp = CreateCompatibleBitmap(hdcDest, nWidth, nHeight);
HBITMAP hOldTmpBmp = (HBITMAP)::SelectObject(hdcTmp, hTmpBmp);
::BitBlt(hdcTmp, 0,0,nWidth, nHeight, hBmpDC, nXSrc, nYSrc, SRCCOPY );
::SetBkColor( hdcTmp, colorTransparent );
::SetTextColor( hBmpDC, RGB( 0, 0, 0 ) );
::BitBlt( hdcMask, 0, 0, nWidth, nHeight, hdcTmp, 0, 0, SRCCOPY );
HDC hdcOffScr = ::CreateCompatibleDC(hdcDest);
::SetBkMode(hdcOffScr, TRANSPARENT);
HBITMAP hbmOffScr = ::CreateBitmap(nWidth, nHeight,
(BYTE)GetDeviceCaps(hdcDest, PLANES),
(BYTE)GetDeviceCaps(hdcDest, BITSPIXEL),
NULL);
HBITMAP hbmOldOffScr = (HBITMAP)::SelectObject(hdcOffScr, hbmOffScr);
::BitBlt(hdcOffScr, 0, 0, nWidth, nHeight, hdcDest, nXDest, nYDest, SRCCOPY);
::SetBkColor( hBmpDC, RGB( 0, 0, 0 ) );
::SetTextColor( hBmpDC, RGB( 0xff, 0xff, 0xff ));
COLORREF crOldBackColor = ::GetBkColor( hdcDest );
COLORREF crOldTextColor = ::GetTextColor( hdcDest );
::SetBkColor( hdcOffScr, RGB( 0xff, 0xff, 0xff ) );
::SetTextColor( hdcOffScr, RGB( 0, 0, 0 ) );
::BitBlt( hdcOffScr, 0, 0, nWidth, nHeight, hBmpDC, 0, 0, SRCINVERT );
::BitBlt( hdcOffScr, 0, 0, nWidth, nHeight, hdcMask, 0, 0, SRCAND );
::BitBlt( hdcOffScr, 0, 0, nWidth, nHeight, hBmpDC, 0, 0, SRCINVERT );
::SetBkColor( hdcOffScr, crOldBackColor );
::SetTextColor( hdcOffScr, crOldTextColor );
::SetBkMode(hdcDest, TRANSPARENT);
::BitBlt(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcOffScr, 0, 0, SRCCOPY);
if ( hOldMaskBitmap )
::SelectObject( hdcMask, hOldMaskBitmap );
if ( hbmOldOffScr )
::SelectObject( hdcOffScr, hbmOldOffScr );
if ( hOldTmpBmp )
::SelectObject( hdcTmp, hOldTmpBmp );
::DeleteObject( hTmpBmp );
::DeleteObject( bmMask );
::DeleteObject( hbmOffScr );
::DeleteDC( hdcOffScr );
::DeleteDC( hdcTmp );
::DeleteDC( hdcMask );
}
but with more effort you could do your self(msdn etc), like I did it is a lot more fun !!
good luck,
Dror
|
|
|
|
|
I've not tested the code someone else just offered, but I notice it failed to allow for a differering source and destination size. I don't even have the code here, but the Sept issue of WDJ will have an article from me on doing exactly what you want, and also alphablend under W95. Basically to change the code below you just need to do a stretchblt to change the source bitmap to the dimensions of the destination.
Christian
#include "std_disclaimer.h"
The careful application of terror is also a form of communication.
Eagles may soar, but weasels don't get sucked into jet engines.
|
|
|
|
|
It seems that when I dynamically create my radio button (i.e at run time) the text gets displayed if I choose certain UID number and not the other ones.
m_RadioButtonArray[nDex].Create("paradi",
WS_GROUP | WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON , ctrlRect,this, 2013 );
Note that on this screen I am also dynamically creating other edit controls that their GUI ID ranges from 1999 to 2011 !!!!
Paradise is where I am.
Voltaire
|
|
|
|
|
anyone knows how to convert an int variable from decimal to hex?? I am using VC++ and MFC, but am looking for a simple function to do it.
please reply to me at asengupt@uiuc.edu
Thanks!
ananya
(student)
|
|
|
|
|
If you want to print it use something like printf, or use _ltoa or _ultoa.
|
|
|
|
|
i've created a Dialog app using the MFC wizard. now, i want to add to the dialog a tool-bar and a status-bar. so i added this code to onInitDialog():
UINT indicators [3] =
{
ID_PAN1,
ID_PAN2,
ID_PAN3
};
if (!m_status.Create(this))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
m_status.SetIndicators(indicators, 3);
if (!toolbar.Create(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!toolbar.LoadToolBar(IDR_TOOLBAR1))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
i think its ok, but when i execute the app, i dont see neither the statusbar nor the toolbar
Pliz jelp. thanks
|
|
|
|
|
MFC sample DLGCBAR32 does exactly that.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
|
Why the sample don't help?
The sample that said Tomasz is very good.
Try to explain that you don't understand....
Regards
Carlos Antollini.
|
|
|
|
|
hi
almost every control has a parameter ID in its Create() function...(CButton for example)
what is that parameter and what should i pass to the function?
i've tried to put any number and it worlks, but it looks wrong to me
thanks
|
|
|
|
|
The ID is defined in resource.h and then passed in by name. This is so there is no double up, where two controls have the same ID.
Christian
#include "std_disclaimer.h"
The careful application of terror is also a form of communication.
Eagles may soar, but weasels don't get sucked into jet engines.
|
|
|
|
|
I want to use in serialize and CArchive for save and load from file
But I don't know how can I check if the loading success ?
Who can help me ?
|
|
|
|
|
Try using...
if(ArchiveObj.isLoading())
{
}
else
{
}
Hope it works...
|
|
|
|
|
I need to check if the operation of the loading itself is successes or that failed for example in case that the file terminated suddenly.
|
|
|
|
|
Sorry, In your if/else bodies you need to check the for the end of the file. Try using a counter, and the CFile::GetLength() if CArchive derives from CFile(I don't rememeber) or if not CFile::GetStatis(/*FileName as param*/) which fills the CFileStatis(The Name may be wrong so check MSDN) obj and the CFileStatis obj will have a length memeber(check MSDN for name). You need to use if statements to test the counter to see if counter is smaller than the file length. When you read the Archive add the amount you just read from the Archive to the counter(this is hard to do and I can explain it here maybe later in this thread if you like).
Hope this helps...
Real World Coding:
POP& BuyAPop(Money ADollar){...};
|
|
|
|
|
CArchive will throw an exception if it encounters a probloem while loading or saving the file. This includes if it encounters an unexpected end of file.
(code assumes fp is a CFile object already opened.)
try
{
CArchive ar(&fp, CArchive::load);
// serialize objects here
ar.Close();
}
catch(CArchiveException* pArError)
{
// an error occured
pArError->Delete();
}
catch(CException* pError)
{
// an error occured
pError->Delete();
}
catch(...)
{
// an error occured
}
|
|
|
|
|
|
With <'PRE'> and <'/PRE'> without '
Carlos Antollini.
|
|
|
|
|
By using the <pre> HTML Tags...
<pre>What you want to be Preformatted.</pre> The <pre> allows you to display a fixed font and more than one space(HTML allow only one space to be displayed outside of <pre>...</pre> ). The yellow is applyed by www.codeproject.com in maybe a stylesheet that replaces the background color of all the <pre>...</pre> it find.
Real World Coding:
POP& BuyAPop(Money ADollar){...};
|
|
|
|
|
I have an HICON, and need to be copy the contents of it to a HBITMAP.
How could I do this, please?
Peter
|
|
|
|
|
Call DrawIcon or DrawIconEx for memory device context with HBITMAP selected.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Anyone know how to read bits using a structure?
I used to do it like this using Borland. I need to know how to do it in MFC.
union test
{
int n 1:8;
unsigned char c;
}
This may not be correct syntax its been a while.
Old ansi C stuff.
JLS
Student/Part time programmer
Major Programming.
|
|
|
|
|
This will compile when you remove space between 'n' and '1' and add semicolon after }.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
thanks kind of rusty
JLS
Student/Part time programmer
Major Programming.
|
|
|
|
|
How can I change the colour of the text in a button @ run-time.
I tried to override the onctlcolor method:-
HBRUSH CTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (nCtlColor == CTLCOLOR_BTN)
{
pDC->SetTextColor(RGB(255,0,0));//set red
return (HBRUSH) m_Brush.GetSafeHandle();
};
return hbr;
}
m_Brush is a member brush & in OnInitDialog method, I create it with a solid brush.
m_Brush.CreateSolidBrush(RGB(129,129,129));
Thanks
Gerry.
|
|
|
|
|