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. Loading an ICON from a file

Loading an ICON from a file

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 4 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.
  • E Offline
    E Offline
    eli15021979
    wrote on last edited by
    #1

    Hi, My project does not contain any resources file , and I need to load an ICON from a specified location. I used the following :

    m_hIcon = AfxGetApp()->LoadIcon(_T"C:\test\res\OPTIONS_ICON.ico"));

    but m_hIcon is allways NULL. Anyone? With best regards, Eli :doh:

    C N H 3 Replies Last reply
    0
    • E eli15021979

      Hi, My project does not contain any resources file , and I need to load an ICON from a specified location. I used the following :

      m_hIcon = AfxGetApp()->LoadIcon(_T"C:\test\res\OPTIONS_ICON.ico"));

      but m_hIcon is allways NULL. Anyone? With best regards, Eli :doh:

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      You need to escape backslashes inside strings, change

      eli15021979 wrote:

      m_hIcon = AfxGetApp()->LoadIcon(_T"C:\test\res\OPTIONS_ICON.ico"));

      into:

      m_hIcon = AfxGetApp()->LoadIcon(_T"C:\\test\\res\\OPTIONS_ICON.ico"));

      :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

      E 1 Reply Last reply
      0
      • C CPallini

        You need to escape backslashes inside strings, change

        eli15021979 wrote:

        m_hIcon = AfxGetApp()->LoadIcon(_T"C:\test\res\OPTIONS_ICON.ico"));

        into:

        m_hIcon = AfxGetApp()->LoadIcon(_T"C:\\test\\res\\OPTIONS_ICON.ico"));

        :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

        E Offline
        E Offline
        eli15021979
        wrote on last edited by
        #3

        Thanks for your quick answer... I tried this also , but m_hIcon still NULL. Note that I'm able to load an ICON using a resources file by AfxGetApp()->LoadIcon(IDI_NEW_LOGGER_ICON); Thanks again, Eli

        1 Reply Last reply
        0
        • E eli15021979

          Hi, My project does not contain any resources file , and I need to load an ICON from a specified location. I used the following :

          m_hIcon = AfxGetApp()->LoadIcon(_T"C:\test\res\OPTIONS_ICON.ico"));

          but m_hIcon is allways NULL. Anyone? With best regards, Eli :doh:

          N Offline
          N Offline
          Naveen
          wrote on last edited by
          #4

          eli15021979 wrote:

          AfxGetApp()->LoadIcon(_T"C:\test\res\OPTIONS_ICON.ico"));

          will not work. U should use the LoadImage() function to load the icon from a file.

          nave [OpenedFileFinder]

          1 Reply Last reply
          0
          • E eli15021979

            Hi, My project does not contain any resources file , and I need to load an ICON from a specified location. I used the following :

            m_hIcon = AfxGetApp()->LoadIcon(_T"C:\test\res\OPTIONS_ICON.ico"));

            but m_hIcon is allways NULL. Anyone? With best regards, Eli :doh:

            H Offline
            H Offline
            Hamid Taebi
            wrote on last edited by
            #5

            Did you try with LoadImage?

            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