1Tk_Main(3) Tk Library Procedures Tk_Main(3)
2
3
4
5______________________________________________________________________________
6
8 Tk_Main - main program for Tk-based applications
9
11 #include <tk.h>
12
13 Tk_Main(argc, argv, appInitProc)
14
16 int argc (in) Number of elements in argv.
17
18 char *argv[] (in) Array of strings containing
19 command-line arguments. On
20 Windows, when using -DUNI‐
21 CODE, the parameter type
22 changes to wchar_t *.
23
24 Tcl_AppInitProc *appInitProc (in) Address of an application-
25 specific initialization pro‐
26 cedure. The value for this
27 argument is usually
28 Tcl_AppInit.
29______________________________________________________________________________
30
32 Tk_Main acts as the main program for most Tk-based applications.
33 Starting with Tk 4.0 it is not called main anymore because it is part
34 of the Tk library and having a function main in a library (particularly
35 a shared library) causes problems on many systems. Having main in the
36 Tk library would also make it hard to use Tk in C++ programs, since C++
37 programs must have special C++ main functions.
38
39 Normally each application contains a small main function that does
40 nothing but invoke Tk_Main. Tk_Main then does all the work of creating
41 and running a wish-like application.
42
43 When it is has finished its own initialization, but before it processes
44 commands, Tk_Main calls the procedure given by the appInitProc argu‐
45 ment. This procedure provides a “hook” for the application to perform
46 its own initialization, such as defining application-specific commands.
47 The procedure must have an interface that matches the type Tcl_AppInit‐
48 Proc:
49 typedef int Tcl_AppInitProc(
50 Tcl_Interp *interp);
51 AppInitProc is almost always a pointer to Tcl_AppInit; for more details
52 on this procedure, see the documentation for Tcl_AppInit.
53
54 Tk_Main functions much the same as Tcl_Main. In particular, Tk_Main
55 supports both an interactive mode and a startup script mode, with the
56 file name and encoding of a startup script under the control of the
57 Tcl_SetStartupScript and Tcl_GetStartupScript routines. However it
58 calls Tk_MainLoop after processing any supplied script, and in interac‐
59 tive uses events registered with Tcl_CreateFileHandler to process user
60 input.
61
63 Tcl_DoOneEvent(3)
64
66 application-specific initialization, command-line arguments, main pro‐
67 gram
68
69
70
71Tk 4.0 Tk_Main(3)