Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Bitmap::FromResource(HINSTANCE, WCHAR) , problem

Bitmap::FromResource(HINSTANCE, WCHAR) , problem

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsquestionc++winformshelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kk_Kevin
    wrote on last edited by
    #1

    I use the code "Bitmap::FromResource(HINSTANCE, WCHAR)" to load the bmp pic form res and then to fill a rectangle.but can not get a bitmap. My project is mfc project. so my first question is how to get hte handle of the HINSTANTCE and the second is the wchar parameter, I use "MAKEINTRESOURCE(pResId)" to get he pic name, but get a blank. and why? whether the gdi+ need more configuration or any other reason. below is my the whole 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 = Bitmap::FromResource(hInstResource, ch);

    if(!FindResource(hInstResource, 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);

    K 1 Reply Last reply
    0
    • K kk_Kevin

      I use the code "Bitmap::FromResource(HINSTANCE, WCHAR)" to load the bmp pic form res and then to fill a rectangle.but can not get a bitmap. My project is mfc project. so my first question is how to get hte handle of the HINSTANTCE and the second is the wchar parameter, I use "MAKEINTRESOURCE(pResId)" to get he pic name, but get a blank. and why? whether the gdi+ need more configuration or any other reason. below is my the whole 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 = Bitmap::FromResource(hInstResource, ch);

      if(!FindResource(hInstResource, 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);

      K Offline
      K Offline
      kk_Kevin
      wrote on last edited by
      #2

      I have already resolved it first: hinstance = AfxGetInstanceHandle(); second: FromResource(hInstResource, (LPCWSTR)MAKEINTRESOURCE(pResId));

      H 1 Reply Last reply
      0
      • K kk_Kevin

        I have already resolved it first: hinstance = AfxGetInstanceHandle(); second: FromResource(hInstResource, (LPCWSTR)MAKEINTRESOURCE(pResId));

        H Offline
        H Offline
        Hadi Dayvary
        wrote on last edited by
        #3

        how did you do that? please help

        www.logicsims.ir

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups