CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 28 of 28
  1. #16
    Join Date
    Feb 2005
    Posts
    331

    Re: Conditional in resource file

    How do I specify the condition? In VS 2005 after I right click the resource in resource view, then select "Insert Copy", what should I put in the "condition" field? (CHOICE == CHOICE_ONE) doesn't seem to work, it complains that the condition contains illegal characters.
    Last edited by galapogos; April 15th, 2010 at 05:08 AM.

  2. #17
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Conditional in resource file

    Your VS 2005 shows you very clear what "Condition" means:
    Attached Images Attached Images  
    Victor Nijegorodov

  3. #18
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Conditional in resource file

    You cannot have a #ifdef conditional inside a stringtable definition, but you can have one around a table.

    Code:
    #if (CHOICE == CHOICE_ONE)
    STRINGTABLE 
    BEGIN
        IDR_MAINFRAME           "Main Window Title 1"
    END
    
    #elif (CHOICE == CHOICE_TWO)
    STRINGTABLE 
    BEGIN
        IDR_MAINFRAME           "Main Window Title 2"
    END
    
    #elif (CHOICE == CHOICE_THREE)
    STRINGTABLE 
    BEGIN
        IDR_MAINFRAME           "Main Window Title 3"
    END
    #endif

  4. #19
    Join Date
    Feb 2005
    Posts
    331

    Re: Conditional in resource file

    Where do I put the preprocessor symbol? If I put it in the .rc or resource.h files, it gets removed once I modify the resource. I've put it in a separate file choice.h, but I'm not sure where to #include it so that the resources see it. I've tried to #include it in the .rc2 file, but that doesn't seem to work.

    The only ways I found so far are to:
    1. #define the preprocessor symbols in resource.h, but then it gets overwritten when I modify something...
    2. Add the symbol in "Project Properties->Resources->General->Preprocesor definitions", but then I have to change this everytime, and it doesn't sync with my choice.h file.

    Also, is there any way I can change the executable name based on the preprocessor symbol?
    Last edited by galapogos; April 16th, 2010 at 02:23 AM.

  5. #20
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Conditional in resource file

    Open the resource treeview
    rightclick on any part and select the "Resource includes..." item

    you'll see a dialog with 2 large edit boxes.
    In the top one you'll see see afxres.h being included
    add the header file(s) you want
    any defines in those headers will now be available for use as resource identifiers.

  6. #21
    Join Date
    Feb 2005
    Posts
    331

    Re: Conditional in resource file

    Thanks. That seems to work.

  7. #22
    Join Date
    Feb 2005
    Posts
    331

    Re: Conditional in resource file

    Another thing...how do I change IDR_MAINFRAME and AFX_IDS_APP_TITLE based on the conditionals? Which resource should I copy and set a condition to?

  8. #23
    Join Date
    Jan 2004
    Posts
    206

    Re: Conditional in resource file

    Hi I have a similar problem. Can someone elaborate on where exactly should we set the preprocessor symbols for the condition?

    I have set the preprocessor symbol in the preprocessor definitions inside the project properties box, but nothing is changed.

  9. #24
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Conditional in resource file

    Quote Originally Posted by Wombat View Post
    Hi I have a similar problem. Can someone elaborate on where exactly should we set the preprocessor symbols for the condition?
    No one can tell where *exactly* you should set it.
    It depends on your needs and your design.

    Quote Originally Posted by Wombat View Post
    I have set the preprocessor symbol in the preprocessor definitions inside the project properties box, but nothing is changed.
    I usually do it exactly this way (and when I create extension dlls with localized resources I do it only this way) and I never had any problem.

    So you seem to do something wrong.
    Victor Nijegorodov

  10. #25
    Join Date
    Jan 2004
    Posts
    206

    Re: Conditional in resource file

    Thanks VictorN for the prompt reply.

    Let me elaborate my problem. I have a project which is initially in english version, and I need to convert it into spanish language.

    So, this is basically what I did:
    1. At the resource view, right-click on a dialog box resource, select "Insert Copy".
    2. I set the Condition of the new resource as "SPANISH_MODE".
    3. The Condition of the original resource is left empty.
    4. At the project property pages, I appended "SPANISH_MODE" to the preprocessor definitions.
    5. I compiled with no error, but when I run the application, it still load the original dialog box.

    Is there anything that I have done wrongly above? Appreciate any help. Thanks.

  11. #26
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Conditional in resource file

    Quote Originally Posted by Wombat View Post
    Thanks VictorN for the prompt reply.

    Let me elaborate my problem. I have a project which is initially in english version, and I need to convert it into spanish language.
    Well, the best way to do it, IMHO, is creating the localized resource dlls. Microsoft recommends this way since VC++5.0:
    How To Create Localized Resource DLLs for MFC Application
    Victor Nijegorodov

  12. #27
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Conditional in resource file

    That's because unless you did something, the original resource will also be in there. And it'll load the original one by default.

    Either you have no default at all.

    or if you do need it, you need to make sure each resource has it's own unique language id, and explicitely load the resource in the language you want. (MFC doesn't have support for this, so you'll need to call the API functions directly, more annoyingly, this is a terrible hassle for dialogs, formviews etc since the actual resource load is burried inside the MFC internals. Making sure ALL resources of the same ID have a conditional and only ONE version of the conditional is applicable is lots easier.

  13. #28
    Join Date
    Jan 2004
    Posts
    206

    Re: Conditional in resource file

    Thanks guys. I realized I need to specify unique condition for the original resource too. Now it works. Hours of coding have given me headache and overlook this obvious problem.

    Thank you very much, you guys are great!

Page 2 of 2 FirstFirst 12

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