| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I want to fill a rectangle with a bmp pic of the resource.
below is my code: hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(pResId), RT_BITMAP); CString src = MAKEINTRESOURCE(pResId); int strLen = 0; strLen =src.GetLength(); WCHAR* ch = new WCHAR[strLen]; wcscpy(ch, CT2CW(src)); // Bitmap* pBitmap = new Bitmap(100,100); Bitmap* pBitmap = Bitmap::FromResource(hInstResource, ch); if(!FindResource(NULL, src, RT_BITMAP)) { AfxMessageBox("Fail load pic!", MB_OK, 0); } graphics.DrawImage(pBitmap, 75,35); TextureBrush* pTextureBrush = new TextureBrush(pBitmap, WrapModeTileFlipY); graphics.FillRectangle(pTextureBrush, 50,300,200,80); Color m_penColor(233,100,54); Pen pen1(m_penColor, 1); graphics.DrawRectangle(&pen1, 50,300,200,80); but there is two problems. first is "Bitmap::FromResource(..)" can not load the pic second is the MAKEINTRESOURCE(pResId) can not get the pic name does the gdi+ need more configuration? or any other reasons |
|
#2
|
||||
|
||||
|
Re: how to fill a rectangle with a bmp pic of the resource
Use LoadImage function with IMAGE_BITMAP, LR_CREATEDIBSECTION parameters. It returns HBITMAP. Then use Bitmap::FromHBITMAP Method to create GDI+ Bitmap.
|
|
#3
|
|||
|
|||
|
Re: how to fill a rectangle with a bmp pic of the resource
Please use code tags; it's hard to follow what you are doing.
Why all the stuff above Code:
Bitmap* pBitmap = Bitmap::FromResource(hInstResource, ch); Code:
Bitmap* pBitmap = Bitmap::FromResource(AfxGetInstanceHandle(),MAKEINTRESOURCE(RT_BITMAP)); |
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|