The R Project SVN R

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4394 ripley 1
/*
2
 * GraphApp - Cross-Platform Graphics Programming Library.
3
 *
4
 * File: init.c -- library initialisation code.
5
 * Platform: Windows  Version: 2.23  Date: 1997/09/09
6
 *
7
 * Version: 1.00  Changes: Original version by Lachlan Patrick.
8
 * Version: 2.00  Changes: New object class system.
9
 * Version: 2.20  Changes: Added EasyWin support in Borland C.
10
 * Version: 2.22  Changes: Now main doesn't use environ pointer.
11
 */
12
 
13
/* Copyright (C) 1993-1998 Lachlan Patrick
14
 
15
   This file is part of GraphApp, a cross-platform C graphics library.
16
 
17
   GraphApp is free software; you can redistribute it and/or modify it
18
   under the terms of the GNU Library General Public License.
19
   GraphApp is distributed in the hope that it will be useful, but
20
   WITHOUT ANY WARRANTY.
21
 
22
   See the file COPYLIB.TXT for details.
23
*/
24
 
25
#include "internal.h"
26
 
27
/*
28
 *  Windows implementation globals.
29
 */
30
 
31
	PROTECTED char * app_name = "GraphApp";
32
	PROTECTED int    app_initialised = 0;
33
	PROTECTED HANDLE this_instance = 0;
34
	PROTECTED HANDLE prev_instance = 0;
35
	PROTECTED int    cmd_show = 1;
36
 
37
/*
38
 *  Functions defined in this file.
39
 */
40
	static void setappname(char *title);
41
	static void getappname(HANDLE Instance);
42
 
43
	int initapp(int argc, char **argv);
44
	void exitapp(void);
45
	void gabeep(void);
46
 
47
/*
48
 *  Initialise application. Returns zero on failure.
49
 */
50
int initapp(int argc, char **argv)
51
{
52
	if (! app_initialised)
53
	{
54
		app_initialised = 1;
55
 
56
		init_objects();
57
		init_events();
58
		init_fonts();
59
		init_cursors();
60
		init_contexts();
61
		init_menus();
62
	}
63
	return (argc < 1) ? 1 : argc;
64
}
65
 
66
/*
67
 *  This function releases all GDI objects.
68
 */
69
PROTECTED
70
void app_cleanup(void)
71
{
72
	if (app_initialised) {
73
		app_initialised = 0;
74
		finish_contexts();
75
		finish_objects();
76
		finish_events();
77
	}
78
}
79
 
80
/*
81
 *  Standard quit application function.
82
 *  This function releases all GDI objects and terminates the program.
83
 *  It can be called at any time from within a program, or at the end,
84
 *  or else it will be called if all windows are closed.
85
 */
86
void exitapp(void)
87
{
88
	app_cleanup();
89
	active_windows = 0;
90
	exit(0);
91
}
92
 
93
/*
94
 *  Run an application program:
95
 */
96
int execapp(char *app)
97
{
98
	#ifdef __MSDOS__
99
		if (WinExec(app, SW_SHOW) < 32)
100
			return 0;
101
	#else
102
		if (system(app) != 0)
103
			return 0;
104
	#endif
105
	return 1;
106
}
107
 
108
 
109
 
110
/*
9184 ripley 111
 *  Play error sound
4394 ripley 112
 */
113
void gabeep(void)
114
{
9184 ripley 115
	MessageBeep(MB_ICONASTERISK);
4394 ripley 116
}
117
 
118
/*
119
 *  Take a name like "PROG.EXE" and set app_name to be "Prog".
120
 */
121
static void setappname(char *title)
122
{
123
	int len;
124
	char c;
125
 
126
	if (title[0] == '\0')
127
		return;
128
	for (len=1; (c=title[len]) != '\0'; len++)
129
		title[len] = tolower(c);
130
	if ((len-=4)<0)
131
		len = 0;
132
	if (! string_diff(title+len, ".exe"))
133
		title[len] = '\0';
134
 
135
	app_name = new_string(title);
136
}
137
 
138
/*
139
 *  Find out what the application is called.
140
 */
141
static void getappname(HANDLE Instance)
142
{
143
	char exename[120];
144
	char title[120];
145
 
146
	/* find out executable name */
147
	GetModuleFileName(Instance, exename, sizeof(exename));
148
	GetFileTitle(exename, title, sizeof(title));
149
	setappname(title);
150
}
151
 
152
/*
153
 *  Special function for making printf work on Windows systems.
154
 *  This function is never called, it merely tricks the compiler into
155
 *  including printf and scanf support.
156
 */
157
void app_init_printf(void)
158
{
159
 	#ifdef __BORLANDC__
160
 		#if __BORLANDC__ <= 0x410
161
 		_InitEasyWin();
162
 		#endif
163
 	#else
164
 	printf(" ");
165
 	#endif
166
}
167
 
168
/*
169
 *  The main Windows entry point is the WinMain function.
170
 */
171
 
172
 
173
 
174
void startgraphapp(HINSTANCE Instance, HINSTANCE PrevInstance, int CmdShow)
175
{
176
 	/*
177
	 *  Save some variables for later.
178
	 */
179
	this_instance = Instance;
180
	prev_instance = PrevInstance;
181
	cmd_show = CmdShow;
182
 
183
	/*
184
	 *  Initialise the graphical interface.
185
	 */
186
	initapp(0, NULL);
187
	getappname(Instance);
188
}
189