can anyone convert this MFC code to WIN32 code please help
-
.
Some Day I Will Prove MySelf :: GOLD
modified on Monday, March 21, 2011 2:13 PM
-
.
Some Day I Will Prove MySelf :: GOLD
modified on Monday, March 21, 2011 2:13 PM
The source is included with MFC.....
Steve
-
.
Some Day I Will Prove MySelf :: GOLD
modified on Monday, March 21, 2011 2:13 PM
The majority of MFC class methods have equivalents in Win32; check the documentation on MSDN for any extra parameters needed. The
CDC
andCBitmap
objects would be replaced byHDC
andHBITMAP
handles. It is simply a matter of reading the documentation and modifying the code according to the correct rules.I must get a clever new signature for 2011.
-
The majority of MFC class methods have equivalents in Win32; check the documentation on MSDN for any extra parameters needed. The
CDC
andCBitmap
objects would be replaced byHDC
andHBITMAP
handles. It is simply a matter of reading the documentation and modifying the code according to the correct rules.I must get a clever new signature for 2011.
sir, i had try to convert the above code. but this code doesn't work at all. please check it.
COLORREF m_crBlack;
COLORREF m_crWhite;int Height();
int Width();
void InitBMP();
void DrawTransparent(HDC* pDC, int x, int y, COLORREF crColour);void InitBMP()
{
m_crBlack = 0;
m_crWhite = RGB(255,255,255);
}
int Width()
{
BITMAP bm={0};
//SIZE lp ={0};
//GetBitmapDimensionEx(bm,&lp);
//return lp.cx;
GetObject(&bm,sizeof(BITMAP),&bm);
return bm.bmWidth;
}
int Height()
{
BITMAP bm={0};
//SIZE lp={0};
//GetBitmapDimensionEx(bm,&lp);
//return lp.cy;
GetObject(&bm, sizeof(BITMAP),&bm);
return bm.bmHeight;
}
void DrawTransparent(HDC pDC, int x, int y, COLORREF crColour)
{
COLORREF croldBack = SetBkColor(pDC,m_crWhite);
COLORREF croldText = SetTextColor(pDC,m_crBlack);//create two memory dcs for the image and the mask; HDC dcImage = CreateCompatibleDC(pDC); HDC dcTrans = CreateCompatibleDC(pDC); //Select the image into the appropriate dc HBITMAP pOldBitmapImage = NULL; SelectObject(dcImage,pOldBitmapImage); //SelectObject(dcImage,this); //create the mask bitmap HBITMAP bitmapTrans = NULL; int nWidth = Width(); int nHeight =Height(); bitmapTrans = CreateBitmap(nWidth,nHeight,1,1,NULL); //select the mast bitmap into the appropriate dc HBITMAP pOldBitmapTrans= NULL; SelectObject(dcTrans,bitmapTrans); //Build mask based on transparent color SetBkColor(dcImage,crColour); BitBlt(dcTrans,0,0,nWidth,nHeight,dcImage,0,0,SRCCOPY); //Do the work true mask method BitBlt(pDC,x,y,nWidth,nHeight,dcImage,0,0,SRCINVERT); BitBlt(pDC,x,y,nWidth,nHeight,dcTrans,0,0,SRCAND); BitBlt(pDC,x,y,nWidth,nHeight,dcImage,0,0,SRCINVERT); //Restore Settings SelectObject(dcImage,pOldBitmapImage); SelectObject(dcTrans,pOldBitmapTrans); SetBkColor(pDC,croldBack); SetTextColor(pDC,croldText);
}
Some Day I Will Prove MySelf :: GOLD
-
sir, i had try to convert the above code. but this code doesn't work at all. please check it.
COLORREF m_crBlack;
COLORREF m_crWhite;int Height();
int Width();
void InitBMP();
void DrawTransparent(HDC* pDC, int x, int y, COLORREF crColour);void InitBMP()
{
m_crBlack = 0;
m_crWhite = RGB(255,255,255);
}
int Width()
{
BITMAP bm={0};
//SIZE lp ={0};
//GetBitmapDimensionEx(bm,&lp);
//return lp.cx;
GetObject(&bm,sizeof(BITMAP),&bm);
return bm.bmWidth;
}
int Height()
{
BITMAP bm={0};
//SIZE lp={0};
//GetBitmapDimensionEx(bm,&lp);
//return lp.cy;
GetObject(&bm, sizeof(BITMAP),&bm);
return bm.bmHeight;
}
void DrawTransparent(HDC pDC, int x, int y, COLORREF crColour)
{
COLORREF croldBack = SetBkColor(pDC,m_crWhite);
COLORREF croldText = SetTextColor(pDC,m_crBlack);//create two memory dcs for the image and the mask; HDC dcImage = CreateCompatibleDC(pDC); HDC dcTrans = CreateCompatibleDC(pDC); //Select the image into the appropriate dc HBITMAP pOldBitmapImage = NULL; SelectObject(dcImage,pOldBitmapImage); //SelectObject(dcImage,this); //create the mask bitmap HBITMAP bitmapTrans = NULL; int nWidth = Width(); int nHeight =Height(); bitmapTrans = CreateBitmap(nWidth,nHeight,1,1,NULL); //select the mast bitmap into the appropriate dc HBITMAP pOldBitmapTrans= NULL; SelectObject(dcTrans,bitmapTrans); //Build mask based on transparent color SetBkColor(dcImage,crColour); BitBlt(dcTrans,0,0,nWidth,nHeight,dcImage,0,0,SRCCOPY); //Do the work true mask method BitBlt(pDC,x,y,nWidth,nHeight,dcImage,0,0,SRCINVERT); BitBlt(pDC,x,y,nWidth,nHeight,dcTrans,0,0,SRCAND); BitBlt(pDC,x,y,nWidth,nHeight,dcImage,0,0,SRCINVERT); //Restore Settings SelectObject(dcImage,pOldBitmapImage); SelectObject(dcTrans,pOldBitmapTrans); SetBkColor(pDC,croldBack); SetTextColor(pDC,croldText);
}
Some Day I Will Prove MySelf :: GOLD
-
sir, i had try to convert the above code. but this code doesn't work at all. please check it.
COLORREF m_crBlack;
COLORREF m_crWhite;int Height();
int Width();
void InitBMP();
void DrawTransparent(HDC* pDC, int x, int y, COLORREF crColour);void InitBMP()
{
m_crBlack = 0;
m_crWhite = RGB(255,255,255);
}
int Width()
{
BITMAP bm={0};
//SIZE lp ={0};
//GetBitmapDimensionEx(bm,&lp);
//return lp.cx;
GetObject(&bm,sizeof(BITMAP),&bm);
return bm.bmWidth;
}
int Height()
{
BITMAP bm={0};
//SIZE lp={0};
//GetBitmapDimensionEx(bm,&lp);
//return lp.cy;
GetObject(&bm, sizeof(BITMAP),&bm);
return bm.bmHeight;
}
void DrawTransparent(HDC pDC, int x, int y, COLORREF crColour)
{
COLORREF croldBack = SetBkColor(pDC,m_crWhite);
COLORREF croldText = SetTextColor(pDC,m_crBlack);//create two memory dcs for the image and the mask; HDC dcImage = CreateCompatibleDC(pDC); HDC dcTrans = CreateCompatibleDC(pDC); //Select the image into the appropriate dc HBITMAP pOldBitmapImage = NULL; SelectObject(dcImage,pOldBitmapImage); //SelectObject(dcImage,this); //create the mask bitmap HBITMAP bitmapTrans = NULL; int nWidth = Width(); int nHeight =Height(); bitmapTrans = CreateBitmap(nWidth,nHeight,1,1,NULL); //select the mast bitmap into the appropriate dc HBITMAP pOldBitmapTrans= NULL; SelectObject(dcTrans,bitmapTrans); //Build mask based on transparent color SetBkColor(dcImage,crColour); BitBlt(dcTrans,0,0,nWidth,nHeight,dcImage,0,0,SRCCOPY); //Do the work true mask method BitBlt(pDC,x,y,nWidth,nHeight,dcImage,0,0,SRCINVERT); BitBlt(pDC,x,y,nWidth,nHeight,dcTrans,0,0,SRCAND); BitBlt(pDC,x,y,nWidth,nHeight,dcImage,0,0,SRCINVERT); //Restore Settings SelectObject(dcImage,pOldBitmapImage); SelectObject(dcTrans,pOldBitmapTrans); SetBkColor(pDC,croldBack); SetTextColor(pDC,croldText);
}
Some Day I Will Prove MySelf :: GOLD
In your Height and Width functions, the first argument to GetObject should be a HBITMAP, not a BITMAP*. Judging from your original post, the HBITMAP to use would be pOldBitmapImage. In the second post, you assign NULL to this, which is inconsistent with what you do in your original post; you'd want to get the HBITMAP from dcImage and put that in pOldBitmapImage.
-
.
Some Day I Will Prove MySelf :: GOLD
modified on Monday, March 21, 2011 2:13 PM
-
never tried sir, can you provide a small sample.
Some Day I Will Prove MySelf :: GOLD
-
never tried sir, can you provide a small sample.
Some Day I Will Prove MySelf :: GOLD
-
nice joke.... Google. anyways thanx 4 d reply...
Some Day I Will Prove MySelf :: GOLD
-
nice joke.... Google. anyways thanx 4 d reply...
Some Day I Will Prove MySelf :: GOLD
goldenrose9 wrote:
nice joke.... Google. anyways thanx 4 d reply
The only joke is that you consistently ask for answers you can find yourself, using google. If you expect people to take your questions seriously, then invest a little time to try to find the answer yourself, instead of expecting other people to do your work for you. BTW, use of SMS speak is not acceptable on these forums.
Best wishes, Hans
-
goldenrose9 wrote:
nice joke.... Google. anyways thanx 4 d reply
The only joke is that you consistently ask for answers you can find yourself, using google. If you expect people to take your questions seriously, then invest a little time to try to find the answer yourself, instead of expecting other people to do your work for you. BTW, use of SMS speak is not acceptable on these forums.
Best wishes, Hans
i understand what you want to tell. Its a request, don't mind it, please, i don't want to get lots of anwser. how much i had asked and how complex is it. If u see this question here, i had searched the code and tried to convert it. But i failed so asked here. if you feel that i ask most then i will never ask again. Why i commented on google. because everyone out on net know google very much. this answer is simply useless.
Some Day I Will Prove MySelf :: GOLD
-
i understand what you want to tell. Its a request, don't mind it, please, i don't want to get lots of anwser. how much i had asked and how complex is it. If u see this question here, i had searched the code and tried to convert it. But i failed so asked here. if you feel that i ask most then i will never ask again. Why i commented on google. because everyone out on net know google very much. this answer is simply useless.
Some Day I Will Prove MySelf :: GOLD
Here's how it went:
- Hans suggested you could use the TransparentBlt function, and included a link to the MSDN documentation page to help you get started.
- You responded by asking for a sample, rather than trying to work it out for yourself.
- Hans suggested (quite rightly) that there were lots to be found if you use Google.
- You responded by saying you thought his answer was a joke, and thus not worth consideration.
- Hans explained that people are not going to help you unless you are prepared to at least try and do some of your own work.
- You responded by a childish show of petulance, just because people will not do what you are quite capable of doing for yourself.
I must get a clever new signature for 2011.
-
Here's how it went:
- Hans suggested you could use the TransparentBlt function, and included a link to the MSDN documentation page to help you get started.
- You responded by asking for a sample, rather than trying to work it out for yourself.
- Hans suggested (quite rightly) that there were lots to be found if you use Google.
- You responded by saying you thought his answer was a joke, and thus not worth consideration.
- Hans explained that people are not going to help you unless you are prepared to at least try and do some of your own work.
- You responded by a childish show of petulance, just because people will not do what you are quite capable of doing for yourself.
I must get a clever new signature for 2011.