CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Feb 2010
    Posts
    11

    [RESOLVED] Difficulty Compiling Resource files (.rc, .h, and .res) in Visual C++

    Hello, my name is Justin! I'm currently a 3rd year Junior majoring in CSE, and I'm learning a bit about Windows programming on my own outside of class. The book I am currently reading from is "Tricks of the Windows Game Programming Gurus 2nd Edition" by Andre LaMothe. I'm on Chapter 3 right now, and I have run into some difficulty with resource files. I have been searching the internet for 3 hours (it is now 4:39am!) for a problem I have been having, yet am still unable to find a solution! After searching this forum and reading the available FAQs, I decided to post to see if I could have any luck here! I'm not sure if this is the appropriate forum for this thread, so I apologize if it isn't.

    This is what I want to do: I want to make a .rc file, a corresponding .h file, a .ico file, and have my compiler link and successfully create an executable that has my personal .ico file in its place, as well as in it's upper window. From what I understand, the compiler will generate some .res file, and then linking my .h, .cpp, .rc, and .ico file, it will generate an .exe file. My program is quite simple; it simply displays a simple 400 x 400 black window. No menus, nothing else. I have successfully gotten this to work (displaying the window), I just need to be able to get the icon thing to work!

    Originally, I was using Visual C++ Express Edition 2008 for this "project". After some research using google, I discovered that it doesn't support resource editing. I downloaded a tool called ResEdit, but this isn't really what I want to do. Sure, it's great for creating the .rc and respective .h files, but I want to learn to do this on my own! I looked at some other options, but for me they were a bit more complicated and time consuming that I could handle.

    My next step was using Visual C++ 6.0 Standard Edition. This supported resource files, but again it seems more for creating them then simply linking them over all. I'm sure I'm over-complicating this problem, but I sure would love some help!

    For reference, here is some information regarding my files:

    File 1: "resource.rc"

    #include "resource.h"
    id_icon1 ICON star.ico

    File 2: "resource.h"

    #define id_icon1 100

    File 3: "main.cpp"

    //this is simply part of the winclass I am registering

    winclass.cbSize = sizeof(WNDCLASSEX);
    winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
    winclass.lpfnWndProc = WindowProc; //how the messages are handled
    winclass.cbClsExtra = 0;
    winclass.cbWndExtra = 0;
    winclass.hInstance = hinstance;
    winclass.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(id_icon1));
    winclass.hCursor = LoadCursor(hinstance, IDC_ARROW);
    winclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    winclass.lpszMenuName = NULL;
    winclass.lpszClassName = WINDOW_CLASS_NAME;
    winclass.hIconSm = LoadIcon(hinstance, MAKEINTRESOURCE(id_icon1));

    File 4: "star.ico"

    I was quite certain to use an '#include "resource.h" in my main.cpp file. All my files, including star.ico are contained in the same directory, my "Source" folder, for either compiler. I will be quite honest; I have yet to make an executable yet (I haven't gotten that far with these new programs for me), but just simply seeing my "hIconSm" in the window would make me happy! If I can at least figure out how to get this to work, I can easily handle the rest on my own! Thank you for any time that can be offered to assist me!!!

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Difficulty Compiling Resource files (.rc, .h, and .res) in Visual C++

    Once you have begun using Visual C++ 6.0 which has a resorce editor, use that resource editor and avoid manually editing of resource script files as well as using some external tools.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  3. #3
    Join Date
    Feb 2010
    Posts
    11

    Re: Difficulty Compiling Resource files (.rc, .h, and .res) in Visual C++

    Without a doubt, I do indeed plan on using the built in resource editor. Reading ahead in my book, it seems like creating menus will become a pain unless I use the editor. I don't plan on manually editing these files long-term-wise (especially in the case of menus), but for the present I still want to learn how to manipulate these files without the resource editor. I feel like I could learn a lot if I could start without it, and then learn to use it later. Sorry for being so stubborn!

  4. #4
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Difficulty Compiling Resource files (.rc, .h, and .res) in Visual C++

    Once having a resource editor, the maually editing of resource script files (and I'm not only talking about menus) is a kind of masochistic waste of time.
    In very rare cases we really have to do that.
    Instead, we can focus on another better goals like for example learning Windows API, which oho... it a huge domain that never let us bored.

    However, if you really, really want to learn the resource file statements, you can find them in the (MSDN) documentation.
    Well, last but not the least: which is the real problem?
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  5. #5
    Join Date
    Feb 2010
    Posts
    11

    Re: Difficulty Compiling Resource files (.rc, .h, and .res) in Visual C++

    Yes, I agree that overall, it can become a waste. However, I'm not planning on learning the entire Windows API. I just need enough "bare-bones" coding to get me into Direct X. Besides, I'm a control-freak (as some programmers tend to be), I want to make my own files and link/compiler them without all the extra tags Visual C++ puts in.

    I'm not sure what you mean when you ask "what's the real problem?". I'm doing this for fun, though I am embarrassed to say that despite being a Junior, my programming capabilities are quite novice. I have trouble understanding a lot of things, which is why I was hoping to get some help on this forum! I checked through the MSDN, but I was unable to find anything pertaining to what I actually wanted to do. Sure, I found topics on resource files and creating them, but not linking and compiling my own personal ones. Perhaps am I simply looking for the wrong thing?

    Thanks again for your time!

  6. #6
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Difficulty Compiling Resource files (.rc, .h, and .res) in Visual C++

    Quote Originally Posted by jroeser View Post
    I'm not sure what you mean when you ask "what's the real problem?".
    I too don’t understand what the problem you are trying to solve is.
    Of course you do not “need” to use resource editor; it simply is a convenience tool.
    The code you have in your first post should work, provided that you build it properly. BTW, how do you do that? Do you use your Visual Studio? What error(s) are you getting? Did you add that resource file to your project?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  7. #7
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Difficulty Compiling Resource files (.rc, .h, and .res) in Visual C++

    Quote Originally Posted by jroeser View Post
    I'm not sure what you mean when you ask "what's the real problem?". I'm doing this for fun...
    I looked through the whole thread... You know what? What occured to me first was exactly the same: what's the real problem? There are lots of lines about resources, and some misty things about desperate switching among compilers. Finally it seems you just able to compile, but unable to link your executable. So, what was the point of mentioning about resource editing?

    As long as you intend to become an engineer, first thing you need to learn is the protocol for solving problems:
    • dissect your problem for simpler parts,
    • ask simple questions separately,
    • try the solutions separately,
    • and only after having a firm grip on all of them, integrate all the parts together.


    You've missed the first step, that's why you were unable to ask simple questions, that was the reason of having no specific answers you would be able to try out.

    You see? You just follow the protocol and you're saved.
    Last edited by Igor Vartanov; February 5th, 2010 at 06:33 AM.
    Best regards,
    Igor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured