TITLE: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "{{DISPLAYTITLE:_TITLE}} The _TITLE statement provides the program name in the title bar of the program window. {{PageSyntax}} : _TITLE {{Parameter|text$}} {{Parameters}} * {{Parameter|text$}} can be any literal or variable STRING or ASCII character value. {{PageDescription}} * The title can be changed anywhere in a program procedure. * The title bar will say "Untitled" if a title is not set. * Change the title of the $CONSOLE windows created usi...")
 
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 7: Line 7:




{{Parameters}}
{{PageParameters}}
* {{Parameter|text$}} can be any literal or variable [[STRING]] or [[ASCII]] character value.
* {{Parameter|text$}} can be any literal or variable [[STRING]] or [[ASCII]] character value.


Line 20: Line 20:
{{PageExamples}}
{{PageExamples}}
''Example 1:'' How to create the window title bar.
''Example 1:'' How to create the window title bar.
{{CodeStart}} '' ''
{{CodeStart}}
{{Cl|_TITLE}} "My New Program" '' ''
{{Cl|_TITLE}} "My New Program"
{{CodeEnd}}
{{CodeEnd}}




''Example 2:'' How to find the currently running program module name and current path using a Windows API Library.
''Example 2:'' How to find the currently running program module name and current path using a Windows API Library.
{{CodeStart}} '' ''
{{CodeStart}}
{{Cl|_TITLE}} "My program"
{{Cl|_TITLE}} "My program"
{{Cl|_DELAY}} 5            '5 second delay
{{Cl|_DELAY}} 5            '5 second delay


{{Cl|_TITLE}} {{Cl|MID$}}(TITLE$, 1, {{Cl|INSTR}}(TITLE$, ".") - 1)
{{Cl|_TITLE}} {{Cl|MID$ (function)|MID$}}(TITLE$, 1, {{Cl|INSTR}}(TITLE$, ".") - 1)


{{Cl|PRINT}} PATH$
{{Cl|PRINT}} PATH$
Line 51: Line 51:
     start = posit + 1
     start = posit + 1
   {{Cl|LOOP}} {{Cl|UNTIL}} posit = 0
   {{Cl|LOOP}} {{Cl|UNTIL}} posit = 0
   TITLE$ = {{Cl|MID$}}(PATH$, last + 1)
   TITLE$ = {{Cl|MID$ (function)|MID$}}(PATH$, last + 1)
   PATH$ = {{Cl|LEFT$}}(PATH$, last)
   PATH$ = {{Cl|LEFT$}}(PATH$, last)
{{Cl|ELSE}} TITLE$ = "": PATH$ = ""
{{Cl|ELSE}} TITLE$ = "": PATH$ = ""
{{Cl|END IF}}
{{Cl|END IF}}
{{Cl|END FUNCTION}} '' ''
{{Cl|END FUNCTION}}
{{CodeEnd}}
{{CodeEnd}}
: ''Note:'' The actual module file name is returned. Not necessarily the Title value. The value returned can be used however.
: ''Note:'' The actual module file name is returned. Not necessarily the Title value. The value returned can be used however.
Line 61: Line 61:


{{PageSeeAlso}}
{{PageSeeAlso}}
* [[_TITLE$]] (function)
* [[_TITLE$]]
* [[_ICON]]
* [[_ICON]]
* [[_DELAY]]
* [[_DELAY]]

Latest revision as of 00:46, 26 February 2023

The _TITLE statement provides the program name in the title bar of the program window.


Syntax

_TITLE text$


Parameters

  • text$ can be any literal or variable STRING or ASCII character value.


Description

  • The title can be changed anywhere in a program procedure.
  • The title bar will say "Untitled" if a title is not set.
  • Change the title of the $CONSOLE windows created using _CONSOLETITLE
  • Note: A delay may be required before the title can be set. See _SCREENEXISTS.


Examples

Example 1: How to create the window title bar.

_TITLE "My New Program"


Example 2: How to find the currently running program module name and current path using a Windows API Library.

_TITLE "My program"
_DELAY 5             '5 second delay

_TITLE MID$(TITLE$, 1, INSTR(TITLE$, ".") - 1)

PRINT PATH$


FUNCTION TITLE$ '=== SHOW CURRENT PROGRAM
SHARED PATH$
DECLARE LIBRARY 'Directory Information using KERNEL32 provided by Dav
  FUNCTION GetModuleFileNameA (BYVAL Module AS LONG, FileName AS STRING, BYVAL nSize AS LONG)
END DECLARE

FileName$ = SPACE$(256)
Result = GetModuleFileNameA(0, FileName$, LEN(FileName$))
IF Result THEN
  PATH$ = LEFT$(FileName$, Result)
  start = 1
  DO
    posit = INSTR(start, PATH$, "\")
    IF posit THEN last = posit
    start = posit + 1
  LOOP UNTIL posit = 0
  TITLE$ = MID$(PATH$, last + 1)
  PATH$ = LEFT$(PATH$, last)
ELSE TITLE$ = "": PATH$ = ""
END IF
END FUNCTION
Note: The actual module file name is returned. Not necessarily the Title value. The value returned can be used however.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link