Hi Enrico,
there is absolutely no connection between the panel handle and the paneo resource ID defined in UIR file. You can load the panels in memory during program execution regardless of the order in which they are stored in the include file (moreover, you are not compelled at all to load all panels in memory during program starting, and you could even load a panel more than once and provided you store their handles in different variables each panel has an indipendent life and can be used/moved/addressed/discarded indipendently)
The concept to the basis of the mechanism is this one: when you load a panel in memory you assign a handle to that particular window, which holds some controls on it. Now, the resource is loaded in memory addressing it among all the resources that actually are present in a UIR file by the Panel Resource ID passed to LoadPanel function.This resource once loaded in memory is assigned a unique handle that is the return code from LoadPanel. This handle must be stored in a variable and used in all subsequent operations on the panel itself or on controls that lie on it.
When you operate on the panel, you must use its handle (not the resource ID!) to identify that particular istance in memory.
When you operate on the controls, you pass to SetCtrlVal or other function the panel handle and the control resource id, that is you manipulate the i-th control on the resource that is loaded in memory and identified by that handle.
SetCtrlVal has no interaction with the UIR and H file generated by the UIR editor, and addresses controls via their index inside the panel. What can be happening is that you are someway using wrong panel handles to operate on controls: if for example the 3rd control on one panel is a string and the 3rd control on a second panel is a numeric, exchanging panel handles let the "Invalid control ID" error arise, 'cause you are passing a double to a control that accepts only chars.
OK, resuming: load in memory all and only the panels you do need in some moment; store the return value from LoadPanel in (global) variables; pass this variables to SetCtrlVal and other functions to manipulate controls on that panel. This way the Invalid control ID error won't arise any more.