Taupie
Tiny Analyser for Universal Purpose Integration & Exploration
Chargement...
Recherche...
Aucune correspondance
Référence du fichier main.c

Implémentation de la procédure de fenêtre et de l'interface. Plus de détails...

#include <stdio.h>
#include <locale.h>
#include <wchar.h>
#include <windows.h>
#include <commctrl.h>
#include "TaupieGUI.h"
#include "../_TkT2/Defines.h"
#include "resource.h"
#include "../_TkT2/EasyWin32.h"
Graphe des dépendances par inclusion de main.c:

Aller au code source de ce fichier.

Fonctions

static int ProcessCommandLine (HWND hwnd, wchar_t *lpCmdLine)
 Traite les éventuels arguments passés au lancement de Taupie.
int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
 Procédure principale - point d'entrée du programme.

Description détaillée

Implémentation de la procédure de fenêtre et de l'interface.

Auteur
Denis MARTIN
dmart.nosp@m.in@t.nosp@m.aupie.nosp@m..net

Définition dans le fichier main.c.

Documentation des fonctions

◆ ProcessCommandLine()

int ProcessCommandLine ( HWND hwnd,
wchar_t * lpCmdLine )
static

Traite les éventuels arguments passés au lancement de Taupie.

Paramètres
hwnd: handle de la fenêtre principale.
lpCmdLine: paramètres de la ligne de commande.
Renvoie
indique le niveau de GUI à appliquer.

Définition à la ligne 37 du fichier main.c.

38{
39 int guiLevel = GUI_FULL;
40
41 if (lpCmdLine && lpCmdLine[0])
42 {
43 int argc = 0;
44 wchar_t **wArgv = CommandLineToArgvW(lpCmdLine, &argc);
45
46 if (wArgv)
47 {
48 // convertit chaque argument de WideChar en UTF-8 pour pouvoir le traiter avec getopt
49 // et les éventuels caractères intranscriptibles en ASCII Latin-1
50
51 // ajoute aussi un premier argument vide car getopt passe toujours le premier argument !? (exécutable ?)
52
53 // et ajoute un dernier argument NULL (théoriquement attendu par la norme)
54
55 argc ++;
56
57 char *argv[argc + 1];
58
59 argv[0] = "";
60
61 for (int index = 0; index < argc; index ++)
62 {
63 argv[index + 1] = NULL;
64
65 if (wArgv[index])
66 {
67 int length = WideCharToMultiByte(CP_UTF8, 0, wArgv[index], -1, NULL, 0, NULL, NULL);
68
69 if (length > 0)
70 {
71 argv[index + 1] = calloc(length, sizeof(char));
72
73 if (argv[index + 1])
74 {
75 WideCharToMultiByte(CP_UTF8, 0, wArgv[index], -1, argv[index + 1], length, NULL, NULL);
76 }
77 }
78 }
79 }
80
81
82 // traitement des arguments par getopt
83
84 BOOL p_openProject = FALSE;
85 char *projectToOpen = NULL;
86
87 BOOL i_GUI = FALSE;
88
89 int option;
90
91 /*
92 * Taupie peut être lancé avec des paramètres :
93
94 * -p projet à ouvrir (base SQLite3)
95 * Par exemple : Taupie -p "D:\MesFichiers\MonProjet.taupie"
96
97 -i mode interactif
98
99 * En mode silencieux, une option absente est à FALSE, alors qu'en mode interactif, une option absente
100 * est à sa valeur courante par défaut (telle qu'enregistrée dans les préférences).
101 * Dans tous les cas, les préférences sont mises à jour par l'exécution de la ligne de commande.
102 */
103
104 while ((option = getopt(argc, argv, ":p:i")) != -1)
105 {
106 opterr = 0;
107
108 switch (option)
109 {
110 case 'p' :
111 {
112 p_openProject = TRUE;
113 projectToOpen = optarg;
114
115 if (!i_GUI)
116 {
117 guiLevel = GUI_NOPE;
118 }
119
120 break;
121 }
122
123
124 case 'i' :
125 {
126 i_GUI = TRUE;
127 guiLevel = GUI_TEMP;
128
129 break;
130 }
131
132 case ':' : // argument manquant
133 case '?' : // option inconnue
134 default :
135 {
136 break;
137 }
138 }
139 }
140
141
142 // ouvre aussi le projet s'il est fourni en argument direct (sans l'option -p)
143
144 if (optind < argc)
145 {
146 p_openProject = TRUE;
147 projectToOpen = argv[optind];
148 }
149
150
151 // traitement par Taupie des options et arguments identifiés
152
153 if (p_openProject)
154 {
155 if (projectToOpen && projectToOpen[0])
156 {
157 size_t length = strlen(projectToOpen) + 1;
158 wchar_t *wProjectToOpen = calloc(length, sizeof(wchar_t));
159
160 if (wProjectToOpen)
161 {
162 // le projet courant est automatiquement chargé au démarrage
163 // donc il suffit d'inscrire le nom du fichier comme projet courant
164
165 MultiByteToWideChar(CP_UTF8, 0, projectToOpen, -1, wProjectToOpen, length);
166 SaveOption(SOFT_NAMEW, SOFT_NAMEW, OPTION_CURRENTPROJECT, wProjectToOpen);
167
168 free(wProjectToOpen);
169 }
170 }
171
172 //PostMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDM_INIT, guiLevel), 0);
173 }
174
175
176 // libération de la mémoire
177
178 LocalFree(wArgv);
179
180 for (int index = 1; index <= argc; index ++)
181 {
182 if (argv[index])
183 {
184 free(argv[index]);
185 }
186 }
187 }
188 }
189
190 return guiLevel;
191}
#define OPTION_CURRENTPROJECT
définitions relatives au fichier des options
Définition Defines.h:44
#define SOFT_NAMEW
Définition version.h:26
Voici le graphe d'appel pour cette fonction :
Voici le graphe des appelants de cette fonction :

◆ wWinMain()

int WINAPI wWinMain ( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int nShowCmd )

Procédure principale - point d'entrée du programme.

Paramètres
hInstance: instance du programme
hPrevInstance: toujours NULL
lpCmdLine: paramètres de la ligne de commande
nShowCmd: affichage demandé
Renvoie
zéro si le programme se termine normalement
une valeur non nulle dans le cas contraire

Définition à la ligne 206 du fichier main.c.

210{
211 HANDLE hMutex = CreateMutex(NULL, FALSE, L"mutex " SOFT_NAMEW);
212
213 if (GetLastError() == ERROR_ALREADY_EXISTS)
214 {
215 //MessageBox(NULL, SOFT_NAMEW L" est d\351j\340 ouvert ...", L"", MB_ICONINFORMATION | MB_SYSTEMMODAL);
216
217 HWND hwnd = FindWindow(NULL, ABOUT_TEXTW);
218 if (hwnd)
219 {
220 SetForegroundWindow(hwnd);
221 }
222
223 ReleaseMutex(hMutex);
224 CloseHandle(hMutex);
225
226 return 0;
227 }
228
229
230 _wsetlocale(LC_ALL, TEXT(SETLOCALE));
231
232
233 // évite le plantage en cas d'utilisation de GetOpenFileName() ou de SHBrowseForFolder() sur le Bureau !!!
234
235 OleInitialize(NULL); // appelle aussi CoInitializeEx avec le modèle thread adéquat
236
237
238 HINSTANCE hre = LoadLibrary(RICHEDIT_DLL);
239
240
241 WNDCLASSEX f_classe = {0};
242
243 f_classe.hInstance = hInstance;
244 f_classe.lpszClassName = L"mainWindowClass";
245 f_classe.lpfnWndProc = Main_Procedure;
246 f_classe.style = CS_HREDRAW | CS_VREDRAW;
247 f_classe.cbSize = sizeof(WNDCLASSEX);
248
249
250 f_classe.hIcon = LoadIcon(hInstance, L"mainIcon");
251 f_classe.hIconSm = LoadIcon(hInstance, L"mainIcon");
252 f_classe.hCursor = LoadCursor(NULL, IDC_ARROW);
253 f_classe.lpszMenuName = L"MainMenu";
254 f_classe.cbClsExtra = 0;
255 f_classe.cbWndExtra = 0;
256
257 // ne pas définir de fond par défaut :
258 // -> évite le clignotement lors des redimensionnements internes
259 // -> implique de dessiner soi-même les parties manquantes
260
261 //f_classe.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
262
263
264 if (!RegisterClassEx(&f_classe))
265 {
266 //DeleteObject(f_classe.hbrBackground);
267 FreeLibrary(hre);
268 OleUninitialize();
269
270 ReleaseMutex(hMutex);
271 CloseHandle(hMutex);
272
273 return 0;
274 }
275
276
277 HWND hwnd = CreateWindowEx(
278 0,
279 L"mainWindowClass",
281 WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS,
282 CW_USEDEFAULT,
283 CW_USEDEFAULT,
284 CW_USEDEFAULT,
285 CW_USEDEFAULT,
286 HWND_DESKTOP,
287 NULL,
288 hInstance,
289 NULL
290 );
291
292 ApplyDarkMode(hwnd, L"DarkMode_Explorer");
293
294
295 int guiLevel = ProcessCommandLine(hwnd, lpCmdLine);
296
297 switch (guiLevel)
298 {
299 case GUI_FULL :
300 {
301 ShowWindow(hwnd, SW_NORMAL);
302 break;
303 }
304
305 case GUI_TEMP :
306 {
307 ShowWindow(hwnd, SW_HIDE);
308 break;
309 }
310
311 case GUI_NOPE :
312 {
313 ShowWindow(hwnd, SW_HIDE);
314 break;
315 }
316
317 default :
318 {
319 ShowWindow(hwnd, SW_NORMAL);
320 break;
321 }
322 }
323
324
325 // gestion des messages de la fenêtre principale
326
327 MSG msg;
328 ZeroMemory(&msg, sizeof(msg));
329
330
331 while (TRUE)
332 {
333 if (msg.message == WM_QUIT)
334 {
335 break;
336 }
337
338 // ne pas utiliser PeekMessage(&msg,NULL,0,0,PM_REMOVE) car cela occupe le processeur en permanence !
339 // il vaut mieux utiliser GetMessage(&msg,NULL,0,0) qui ne retourne que lorsqu'il y a un message et
340 // laisse le processeur libre entre temps ...
341 if (GetMessage(&msg, NULL, 0, 0) > 0)
342 {
343 TranslateMessage(&msg);
344 DispatchMessage(&msg);
345 }
346 }
347
348
349 //DeleteObject(f_classe.hbrBackground);
350
351 FreeLibrary(hre);
352 OleUninitialize();
353
354 ReleaseMutex(hMutex);
355 CloseHandle(hMutex);
356
357 return msg.wParam;
358}
LRESULT CALLBACK Main_Procedure(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
procédure de la fenêtre principale.
Définition TaupieGUI.c:2860
#define SETLOCALE
Définition en_locale.h:79
static int ProcessCommandLine(HWND hwnd, wchar_t *lpCmdLine)
Traite les éventuels arguments passés au lancement de Taupie.
Définition main.c:37
#define ABOUT_TEXTW
Définition version.h:29
#define RICHEDIT_DLL
Définition version.h:35
Voici le graphe d'appel pour cette fonction :
Voici le graphe des appelants de cette fonction :