NO

Author Topic: Resource Editor: Copy of controls does not properly work for symbolic names  (Read 452 times)

Offline HelloWorld

  • Member
  • *
  • Posts: 3
Sometimes if I copy controls from one dialog to another dialog both controls have the same name. If I change name of one control other control will also change its name.

Steps to Reproduce:
1.) Start PellesC and create a new resource
2.) Add two dialogs to resource
3.) Open first dialog, add a new button, open properties tab and set button name to IDC_HELLO
4.) Copy the button via [Strg]+[c], open second dialog and insert button via [Strg]+[v]
5.) Name of inserted button is IDC_HELLO. Change it to IDC_HELLO_2.
6.) Switch to first dialog and look to the button name. Its name is IDC_HELLO_2 and not IDC_HELLO!

In this state both buttons seems to share the same internal string, ID or whatever. Whenever you change the name of one button other button will also receive new name.


I attached resource file containing .rc and .h file.

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2064
    • http://www.smorgasbordet.com
I can't see a bug here. This is how it works.

Dialog controls have a numeric id which the IDE attempts to map to symbolic names. See menu "Resource" -> "Symbols...".
No metadata of any kind (would be horribly complicated). A copy is a copy, so numeric id is copied (lets say 4001) and then you change the symbolic name of 4001 from "some_name_1" to "some_name_2". All ids with number 4001 is now mapped to "some_name_2". Clear?
/Pelle

Offline John Z

  • Member
  • *
  • Posts: 81
Hi HelloWorld,

A bit of further input.  This method of copying does not impair functionality.  Different dialog boxes can have the same Button ID and will work correctly, because the message is handled by the procedure assigned to the Dialog Box for processing.  So another box with the same Button ID will not be processed inadvertently, the message won't get to it.

However -

If you really, really, really want to change it you can do it this way.
First you open whatever .h file is being used for your resource file and add a symbol(s) and ID(s) you want to use for Dialog box 2, Button IDs.  If your resource file is main.rc then main.h would be opened

#define IDCANCEL2 4076  //example add (be sure number is not already is use)
Save the .h file

The open the .rc resource file as TEXT (right click on the file, 'open as', text)
In the resource file locate the second Dialog box definition
Find the button you want to change
  CONTROL "Cancel", IDCANCEL, "Button", WS_TABSTOP, 160, 23, 45, 15
change to
  CONTROL "Cancel", IDCANCEL2, "Button", WS_TABSTOP, 160, 23, 45, 15

Save the file.  Now it should have the new ID.

It takes a bit and not really necessary but it can be done.

John Z

Offline HelloWorld

  • Member
  • *
  • Posts: 3
Dialog controls have a numeric id which the IDE attempts to map to symbolic names. See menu "Resource" -> "Symbols...".
No metadata of any kind (would be horribly complicated). A copy is a copy, so numeric id is copied (lets say 4001) and then you change the symbolic name of 4001 from "some_name_1" to "some_name_2". All ids with number 4001 is now mapped to "some_name_2". Clear?


No because if you copy for example a button whose name is IDC_HELLO and insert it in the same dialog copied button will receive a new name (numeric id) like 4002. However if button is inserted into a foreign dialog its name is still IDC_NAME.

Why is there a difference?

What happend to me? I created a new dialog based on an other dialog. So I copied this dialog and changed it. I didn‘t recognized that by changing control names of new dialog old dialog would also be changed. And after a while I compiled project and realized that old dialog didn't work any more because numeric ids of old dialog changed.


Would it not be better if an inserted control would be receive a new numeric id by default? 

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2064
    • http://www.smorgasbordet.com
I could argue there is a difference between "copy" and "insert", but it doesn't really matter much. The choice was made many years ago, when I wrote this part of the IDE, and the behavior matched exactly what I wanted back then. Now it's a little late to change things...
/Pelle

Offline HelloWorld

  • Member
  • *
  • Posts: 3
I could argue there is a difference between "copy" and "insert", but it doesn't really matter much. The choice was made many years ago, when I wrote this part of the IDE, and the behavior matched exactly what I wanted back then. Now it's a little late to change things...
Ok, no problem.  :)

Then I cannot use copy in my way.  ;)

Offline John Z

  • Member
  • *
  • Posts: 81
Then I cannot use copy in my way.  ;)

Well you can but you need to decide if it is easier to create a new dialogue from scratch or copy one then edit it as I mentioned before.  In many cases you would not have to edit it because different dialogs can 'share' ID's. When you copy in the same dialog you can't have the same id doing something different so the id is automatically changed.  Copy to a new dialog does not have that restriction so a copy is a copy.

But - we all have our preferences, both ways work, just depends on what you are used to doing.

John Z