Display name in Windows Taskbar and Version info

Gary040897
Gary040897 used Ask the Experts™
on
1.  How do I assign a value for what is displayed in the Windows Taskbar when a program is running? Right now it says program_name probably because the exe file is named program_name.exe.  I want it display Program Name.

2. In project>options>version info you can "Include version information in project". Where does this information get included to and how is it visible. Right now I manually put information in the version Label in About.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
1. Project->Options->Application->Title

2. You can see the version info if you right click on the *.exe filename and select properties.

To access the version info insode your progam use something like the following code:

  TVersionInfo = Class(TObject)
  private
    FTranslation: Cardinal;
    FTranslationString: string;
    FCompanyName: string;
    FFileDescription: string;
    FFileVersion: string;
    FInternalName: string;
    FLegalCopyright: string;
    FOriginalFilename: string;
    FProductName: string;
    FProductVersion: string;
    FComments: string;
    FV1: integer;
    FV2: integer;
    FV3: integer;
    FV4: integer;


  public
    constructor Create;

    property Translation: Cardinal read FTranslation;
    property TranslationString: string read FTranslationString;
    property CompanyName: string read FCompanyName;
    property FileDescription: string read FFileDescription;
    property FileVersion: string read FFileVersion;
    property InternalName: string read FInternalName;
    property LegalCopyright: string read FLegalCopyright;
    property OriginalFilename: string read FOriginalFilename;
    property ProductName: string read FProductName;
    property ProductVersion: string read FProductVersion;
    property Comments: string read FComments;
    property V1: integer read FV1;
    property V2: integer read FV2;
    property V3: integer read FV3;
    property V4: integer read FV4;
  end;

constructor TVersionInfo.Create;
var
  VerInfoSize: DWord;
  VerInfo: Pointer;
  VerValueSize: DWord;
  VerValue: PVSFixedFileInfo;
  verString: Pointer;
  Dummy: DWord;
  path: string;
begin
  VerInfoSize := GetFileVersionInfoSize(PChar(Application.ExeName),dummy);
  if ( VerInfoSize<>0 ) then
  begin
    GetMem(VerInfo,VerInfoSize);
    GetFileVersionInfo(PChar(Application.ExeName),0,VerInfoSize,VerInfo);
    if ( VerInfo<>NIL ) then
    begin
      VerQueryValue(VerInfo,'\',Pointer(VerValue),VerValueSize);
      FV1 := VerValue.dwFileVersionMS shr 16;
      FV2 := VerValue.dwFileVersionMS and $FFFF;
      FV3 := VerValue.dwFileVersionLS shr 16;
      FV4 := VerValue.dwFileVersionLS and $FFFF;
    end;

    VerQueryValue(VerInfo,'\\VarFileInfo\\Translation',verString,VerValueSize);
    if ( verValueSize>0 ) then
    begin
      FTranslation := Cardinal(VerString^);
      FTranslationString := Format('%4.4x%4.4x',[(FTranslation and $0000FFFF),((FTranslation shr 16) and $0000FFFF)]);
    end;

    path := Format('\StringFileInfo\%s\CompanyName',[FTranslationString]);
    VerQueryValue(VerInfo,PChar(path),verString,VerValueSize);
    if ( verValueSize>0 ) then
      FCompanyName := PChar(VerString);

    path := Format('\StringFileInfo\%s\FileDescription',[FTranslationString]);
    VerQueryValue(VerInfo,PChar(path),verString,VerValueSize);
    if ( verValueSize>0 ) then
      FFileDescription := PChar(VerString);

    path := Format('\StringFileInfo\%s\FileVersion',[FTranslationString]);
    VerQueryValue(VerInfo,PChar(path),verString,VerValueSize);
    if ( verValueSize>0 ) then
      FFileVersion := PChar(VerString);

    path := Format('\StringFileInfo\%s\InternalName',[FTranslationString]);
    VerQueryValue(VerInfo,PChar(path),verString,VerValueSize);
    if ( verValueSize>0 ) then
      FInternalName := PChar(VerString);

    path := Format('\StringFileInfo\%s\LegalCopyright',[FTranslationString]);
    VerQueryValue(VerInfo,PChar(path),verString,VerValueSize);
    if ( verValueSize>0 ) then
      FLegalCopyright := PChar(VerString);

    path := Format('\StringFileInfo\%s\OriginalFilename',[FTranslationString]);
    VerQueryValue(VerInfo,PChar(path),verString,VerValueSize);
    if ( verValueSize>0 ) then
      FOriginalFilename := PChar(VerString);

    path := Format('\StringFileInfo\%s\ProductName',[FTranslationString]);
    VerQueryValue(VerInfo,PChar(path),verString,VerValueSize);
    if ( verValueSize>0 ) then
      FProductName := PChar(VerString);

    path := Format('\StringFileInfo\%s\ProductVersion',[FTranslationString]);
    VerQueryValue(VerInfo,PChar(path),verString,VerValueSize);
    if ( verValueSize>0 ) then
      FProductVersion := PChar(VerString);

    path := Format('\StringFileInfo\%s\Comments',[FTranslationString]);
    VerQueryValue(VerInfo,PChar(path),verString,VerValueSize);
    if ( verValueSize>0 ) then
      FComments := PChar(VerString);

    FreeMem(VerInfo,VerInfoSize);
  end;
end;

Author

Commented:
1. Thanks that worked.

2. Is the only place that info is displayed to the user in Windows Explorer, right click, properties? All the code above is generated by Delphi on Compile?

Commented:
The code I pasted does not influence the "right click properties version info". That will appear if/when you add version info to your project.

The code I posted is not generated by Delphi - you have to add it to your application somewhere. I put it in my About form and create the object in the FormCreate event.

Define a public variable like this:

TfAbout = class(TForm)
...
public
  vi: TVersionInfo;
end;

...

procedure TfAbout.FormCreate(Sender: TObject);
begin
  vi := TVersionInfo.Create;
  lblVersion.Caption := Format('Version %d.%d.%d (Build %d)',[vi.V1,vi.V2,vi.V3,vi.V4]);
  lblCopyright.Caption := vi.LegalCopyright;
end;

procedure TfAbout.FormDestroy(Sender: TObject);
begin
  if ( Assigned(vi) ) then
    vi.Free;
end;
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

Author

Commented:
Instead of adding that code in my About form, would I accomplish the same thing by placing a label on the form. Then name it and put the info in the caption? What's the difference?

Commented:
You can put the info into any label (or any other control) on any form. The code I provided shows how to GET the version information from the datathat you enter in Project->Options->Version.

This code:

 lblVersion.Caption := Format('Version %d.%d.%d (Build %d)',[vi.V1,vi.V2,vi.V3,vi.V4]);
 lblCopyright.Caption := vi.LegalCopyright;

is just populating the caption of two labels in my about form. The labels could just as easily be on your main form.

Or have I mis-understood your question?

Author

Commented:
>>Or have I mis-understood your question?

Maybe a little but I learned another way of doing something. What I was wanting to know is if the project>options>version info "Include version information in project" would somehow affect what I was already putting in my About box by the use of Labels. I wanted to be sure that there wasn't a conflict in what I had done in the About box. I now see that there isn't a conflict and that the Label way of doing it conveys the information to the user in the pretty much the same way as inserting the code above. I did learn that the project>options>version info  would give you the info by right click, properties.

Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial