Get the caption of a running form

Here is a small tip on how you from code can get the caption of a running form:

 static void GetCaption(Args _args)
{
    Args args = new Args(formstr(CustTable));
    FormRun fr = ClassFactory::formRunClassOnClient(args);
    ;
    print Winapi::getWindowText(Winapi::getForegroundWindow());
    print Winapi::getWindowText(Winapi::getFocus());
    
    fr.init();
    fr.run();
    
    print Winapi::getWindowText(fr.hWnd());
    
    fr.close();
    
    pause;
}

You can use Winapi::setWindowText(...) to set the text. In most forms you would do that by overriding the active method on the datasource provding data for window title and add a line like this:

     Winapi::setWindowText(element.hWnd(), "MY WINDOW TEXT");

Thanks to Gregory Christiaens for this tip.

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at https://www.microsoft.com/info/cpyright.htm