Page 1 of 1
Check if ID exist in resource
Posted: Sun Jan 15, 2012 10:29 am
by Marc Vanzegbroeck
Hi,
Is there a way to check if an ID exist in a resource.
I want to use the same program for different customers, and some customers don't a some input-fields (option).
I can offcource add the field in the resource of all customers, an hide, or disable it if it is not available, but sometimes I want to use
that place for something else for that customer.
So I want someting like:
Code: Select all
IF existid(201)
REDEFINE GET test ID 201 OF oDlg
ENDIF
Is this possible?
Thanks,
Marc
Re: Check if ID exist in resource
Posted: Sun Jan 15, 2012 12:56 pm
by Antonio Linares
Marc,
You could use:
GetDlgItem( hDlg, nID ) --> hControl
hControl will be zero if such control does not exist.
The problem with this function is that you can not use it until you have the hWnd of the dialog, in other words: it will only work from the ON INIT clause:
ACTIVATE DIALOG oDlg ON INIT CheckControlsAndRedefineThem()
Re: Check if ID exist in resource
Posted: Sun Jan 15, 2012 7:33 pm
by Marc Vanzegbroeck
Antonio,
GetDlgItem( hDlg, nID ) allways returned 0 but oDlg:getitem(nID) is working fine.
The only problem I have now is to redefine a control in the function called in the ON INIT,it doesn't work.
Is it an other syntax I have to use?
Regards,
Marc
Re: Check if ID exist in resource
Posted: Sun Jan 15, 2012 7:52 pm
by IBTC
Hi Marc,
Marc Vanzegbroeck wrote:
The only problem I have now is to redefine a control in the function called in the ON INIT,it doesn't work.
Maybe this will be a solution: first find out what controls are there, put it in e.g. aControl and use this information in the Redefine-section.
Code: Select all
aControl := aGetDlgControl( cResource )
...
DEFINE DIALOG oDlg NAME cResource
...
IF ASCAN( aControl, 3002 )>0
REDEFINE ... ID 3002 OF oDlg
ENDIF
Code: Select all
FUNCTION aGetDlgControl( cResource )
local oDlg
local aControl := {}
DEFINE DIALOG oDlg NAME cResource
oDlg:Hide()
ACTIVATE DIALOG oDlg;
ON INIT( aControl := _aGetControl( oDlg:hWnd ), oDlg:End() )
return aControl
function _aGetControl( hDlg )
local hCtrl := GetWindow( hDlg, GW_CHILD )
local aControl := {}
while hCtrl != 0 .and. GetParent( hCtrl ) == hDlg
AADD( aControl, GetWindowLong( hCtrl, GWL_ID ) )
hCtrl = GetWindow( hCtrl, GW_HWNDNEXT )
end
return aControl
Re: Check if ID exist in resource
Posted: Sun Jan 15, 2012 8:06 pm
by Marc Vanzegbroeck
Thanks Ruediger,
This is working fine!
Regards,
Marc
Re: Check if ID exist in resource
Posted: Sun Jan 15, 2012 10:11 pm
by Antonio Linares
Very good solution