Loading an image in from a resource file

This is a discussion on Loading an image in from a resource file within the C++ Programming forums, part of the General Programming Boards category; I'm using MSVC++ 2003 and am creating a windows forms application. I want to load in an image from a ...

  1. #1
    Registered User starcatcher's Avatar
    Join Date
    Feb 2008
    Location
    Australia
    Posts
    45

    Question Loading an image in from a resource file

    I'm using MSVC++ 2003 and am creating a windows forms application.
    I want to load in an image from a resource file during runtime so that it can be used by a picturebox. It is fine if the image is added to the resources before compile/runtime.

    I have absolutely no idea about resources. What I have tried though (successfully) is to add an image to my app.rc file. It then comes up in my resource view as IDB_BITMAP000 or something like that. How can I then use this in my program code to actually for example set the image of a picturebox to that image???

    I don't think it's relevant, but the image(s) I am trying to load in are all bitmaps.

    OR, is there a better way to do what I am trying to do other than using resources? Perhaps a different resource file type (not .rc but .resX or something like that...)??

    As i said I have no idea and haven't programmed anything yet so I am open to all ideas!!

    A second question:
    How can I make it so that white JUST ON THAT IMAGE is treated as transparent. I tried setting the transparent colour on the picturebox object to white, but it didn't seem to work. Perhaps a stupid error on my part??

    Thanks,

    Philipp
    I program solely as a hobby so this is definitely not homework.
    Best thing that's been said to me:
    I was so pleasantly surprised to see another post in this thread, and yours was brilliant; a fitting end to a subject (matrix manipulations of all kinds) that is quite intriguing.
    Read this thread to find out why...
    Cannibalism

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Resource is a fine way to store images for your application, no doubt.

    Have a look at this:LoadImage()

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,020
    Windows Forms applications is Managed C++, a non-standard extension to C++.
    Suggest you upgrade to at least 2005 to use Windows Form Applications to use the standard C++/CLI. Even so, LoadImage will most likely not work since it's meant for native.
    Alternatively, you can just go for a native project.

    A good advice for you: if you use Windows Forms, mention that you're using C++/CLI or Managed C++, since people will be confused otherwise.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User starcatcher's Avatar
    Join Date
    Feb 2008
    Location
    Australia
    Posts
    45

    Question Ummm....

    Thanks,

    That seems to open up a few more questions for me, because I didn't really understand what you were saying). What is managed C++, C++/CLI etc...

    I have attached my two code files. Could you tell me if my environment is the one you thought I was programming in? I have no idea.

    I've just been trying to program as usual in 'Form1.h'. 'Form1.cpp' was computer generated and I haven't touched that.

    What is the difference between normal C++ and this?

    Philipp

    PS What is a native project and how can I get it?
    Attached Files Attached Files
    I program solely as a hobby so this is definitely not homework.
    Best thing that's been said to me:
    I was so pleasantly surprised to see another post in this thread, and yours was brilliant; a fitting end to a subject (matrix manipulations of all kinds) that is quite intriguing.
    Read this thread to find out why...
    Cannibalism

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,020
    Maybe you've seen it... native C++, or the real C++, just C++. The typical Hello World program is:

    Code:
    int main()
    {
        cout << "Hello World!";
        return 0;
    }
    Now. There is also an alternative to C++ using Microsoft's managed .NET Framework. You've probably heard of that, too. Microsoft made two versions. The first, 1.0 so to speak is called Managed C++. It's not standard, so it's locked in the Windows platform. This version is available in Visual Studio 2002 (.NET) & 2003 (also .NET)
    The second version, C++/CLI as it's called is, or will be, a standard, thus can be used everywhere. Or will be anyway. Plus Managed C++ (v1.0) is deprecated. But 2.0 is available in Visual Studio 2005+.
    So I suggest you upgrade if you want to use C++/CLI (2.0) or just go normal C++. Then you'll probably have to find some books and start with console applications.

    Native projects are just not named Windows Forms Application. It's called Console Application or Win32 Application.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 01:36 PM
  2. Loading Image from file path
    By csonx_p in forum Windows Programming
    Replies: 16
    Last Post: 04-25-2008, 08:38 AM
  3. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 04:39 AM
  4. multiple file loading. so fruturated! help!
    By psychopath in forum Game Programming
    Replies: 5
    Last Post: 05-09-2005, 06:13 PM
  5. Image Loading Troubles
    By frenchfry164 in forum C++ Programming
    Replies: 3
    Last Post: 11-02-2003, 01:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21