CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Deploying Windows Server 2008 with System Center
  • Remote Desktop Protocol Performance Improvements in Windows Server 2008 R2 and Windows 7
  • The Microsoft Dynamics CRM Security Model
  • SQL Server Modeling Services with Microsoft Visual Studio 2010 Beta 2

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old November 12th, 2009, 06:26 AM
    kevincee kevincee is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 1
    kevincee is an unknown quantity at this point (<10)
    Arrow how to fill a rectangle with a bmp pic of the resource

    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
    Reply With Quote
      #2    
    Old November 12th, 2009, 06:32 AM
    Alex F's Avatar
    Alex F Alex F is offline
    Senior Member
     
    Join Date: Jul 2002
    Posts: 1,663
    Alex F is a splendid one to behold (750+) Alex F is a splendid one to behold (750+) Alex F is a splendid one to behold (750+) Alex F is a splendid one to behold (750+) Alex F is a splendid one to behold (750+) Alex F is a splendid one to behold (750+) Alex F is a splendid one to behold (750+)
    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.
    Reply With Quote
      #3    
    Old November 12th, 2009, 09:58 AM
    hoxsiew hoxsiew is offline
    Senior Member
     
    Join Date: Feb 2005
    Posts: 1,476
    hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+)
    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);
    Just do it all in one step:

    Code:
      Bitmap* pBitmap = Bitmap::FromResource(AfxGetInstanceHandle(),MAKEINTRESOURCE(RT_BITMAP));
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 03:03 PM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.