Taupie 0.20.5
Tiny Analyser
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 135 du fichier main.c.

136{
137 int guiLevel = GUI_FULL;
138
139 if (lpCmdLine && lpCmdLine[0])
140 {
141 int argc = 0;
142 wchar_t **wArgv = CommandLineToArgvW(lpCmdLine, &argc);
143
144 if (wArgv)
145 {
146 // convertit chaque argument de WideChar en UTF-8 pour pouvoir le traiter avec getopt
147 // et les éventuels caractères intranscriptibles en ASCII Latin-1
148
149 // ajoute aussi un premier argument vide car getopt passe toujours le premier argument !? (exécutable ?)
150
151 // et ajoute un dernier argument NULL (théoriquement attendu par la norme)
152
153 argc ++;
154
155 char *argv[argc + 1];
156
157 argv[0] = "";
158
159 for (int index = 0; index < argc; index ++)
160 {
161 argv[index + 1] = NULL;
162
163 if (wArgv[index])
164 {
165 int length = WideCharToMultiByte(CP_UTF8, 0, wArgv[index], -1, NULL, 0, NULL, NULL);
166
167 if (length > 0)
168 {
169 argv[index + 1] = calloc(length, sizeof(char));
170
171 if (argv[index + 1])
172 {
173 WideCharToMultiByte(CP_UTF8, 0, wArgv[index], -1, argv[index + 1], length, NULL, NULL);
174 }
175 }
176 }
177 }
178
179
180 // traitement des arguments par getopt
181
182 BOOL p_openProject = FALSE;
183 char *projectToOpen = NULL;
184
185 BOOL i_GUI = FALSE;
186
187 int option;
188
189 /*
190 * Taupie peut être lancé avec des paramètres :
191
192 * -p projet à ouvrir (base SQLite3)
193 * Par exemple : Taupie -b "D:\MesFichiers\MonProjet.taupie"
194
195 -i mode interactif
196
197 * En mode silencieux, une option absente est à FALSE, alors qu'en mode interactif, une option absente
198 * est à sa valeur courante par défaut (telle qu'enregistrée dans les préférences).
199 * Dans tous les cas, les préférences sont mises à jour par l'exécution de la ligne de commande.
200 */
201
202 while ((option = getopt(argc, argv, ":p:i")) != -1)
203 {
204 opterr = 0;
205
206 switch (option)
207 {
208 case 'p' :
209 {
210 p_openProject = TRUE;
211 projectToOpen = optarg;
212
213 if (!i_GUI)
214 {
215 guiLevel = GUI_NOPE;
216 }
217
218 break;
219 }
220
221
222 case 'i' :
223 {
224 i_GUI = TRUE;
225 guiLevel = GUI_TEMP;
226
227 break;
228 }
229
230 case ':' : // argument manquant
231 case '?' : // option inconnue
232 default :
233 {
234 break;
235 }
236 }
237 }
238
239
240 if (optind < argc)
241 {
242 p_openProject = TRUE;
243 projectToOpen = argv[optind];
244 }
245
246
247 // traitement par Taupie des options et arguments identifiés
248
249 if (p_openProject)
250 {
251 if (projectToOpen && projectToOpen[0])
252 {
253 size_t length = strlen(projectToOpen) + 1;
254 wchar_t *wProjectToOpen = calloc(length, sizeof(wchar_t));
255
256 if (wProjectToOpen)
257 {
258 MultiByteToWideChar(CP_UTF8, 0, projectToOpen, -1, wProjectToOpen, length);
259 SaveOption(SOFT_NAMEW, SOFT_NAMEW, OPTION_CURRENTPROJECT, wProjectToOpen);
260
261 free(wProjectToOpen);
262 }
263 }
264
265 //PostMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDM_INIT, guiLevel), 0);
266 }
267
268
269 // libération de la mémoire
270
271 LocalFree(wArgv);
272
273 for (int index = 1; index <= argc; index ++)
274 {
275 if (argv[index])
276 {
277 free(argv[index]);
278 }
279 }
280 }
281 }
282
283 return guiLevel;
284}
#define OPTION_CURRENTPROJECT
définitions relatives au fichier des options
Definition Defines.h:43
#define SOFT_NAMEW
Definition version.h:26
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 299 du fichier main.c.

303{
304 HANDLE hMutex = CreateMutex(NULL, FALSE, L"mutex " SOFT_NAMEW);
305
306 if (GetLastError() == ERROR_ALREADY_EXISTS)
307 {
308 //MessageBox(NULL, SOFT_NAMEW L" est d\351j\340 ouvert ...", L"", MB_ICONINFORMATION | MB_SYSTEMMODAL);
309
310 HWND hwnd = FindWindow(NULL, ABOUT_TEXTW);
311 if (hwnd)
312 {
313 SetForegroundWindow(hwnd);
314 }
315
316 ReleaseMutex(hMutex);
317 CloseHandle(hMutex);
318
319 return 0;
320 }
321
322
323 _wsetlocale(LC_ALL, TEXT(SETLOCALE));
324
325
326 // évite le plantage en cas d'utilisation de GetOpenFileName() ou de SHBrowseForFolder() sur le Bureau !!!
327
328 OleInitialize(NULL); // appelle aussi CoInitializeEx avec le modèle thread adéquat
329
330
331 WNDCLASSEX f_classe = {0};
332
333 f_classe.hInstance = hInstance;
334 f_classe.lpszClassName = L"mainWindowClass";
335 f_classe.lpfnWndProc = Main_Procedure;
336 f_classe.style = CS_HREDRAW | CS_VREDRAW;
337 f_classe.cbSize = sizeof(WNDCLASSEX);
338
339
340 f_classe.hIcon = LoadIcon(hInstance, L"mainIcon");
341 f_classe.hIconSm = LoadIcon(hInstance, L"mainIcon");
342 f_classe.hCursor = LoadCursor(NULL, IDC_ARROW);
343 f_classe.lpszMenuName = L"MainMenu";
344 f_classe.cbClsExtra = 0;
345 f_classe.cbWndExtra = 0;
346
347 // ne pas définir de fond par défaut :
348 // -> évite le clignotement lors des redimensionnements internes
349 // -> implique de dessiner soi-même les parties manquantes
350
351 //f_classe.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
352
353
354 if (!RegisterClassEx(&f_classe))
355 {
356 //DeleteObject(f_classe.hbrBackground);
357 OleUninitialize();
358
359 ReleaseMutex(hMutex);
360 CloseHandle(hMutex);
361
362 return 0;
363 }
364
365
366 HWND hwnd = CreateWindowEx(
367 0,
368 L"mainWindowClass",
370 WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS,
371 CW_USEDEFAULT,
372 CW_USEDEFAULT,
373 CW_USEDEFAULT,
374 CW_USEDEFAULT,
375 HWND_DESKTOP,
376 NULL,
377 hInstance,
378 NULL
379 );
380
381 ApplyDarkMode(hwnd, L"DarkMode_Explorer");
382
383
384 int guiLevel = ProcessCommandLine(hwnd, lpCmdLine);
385
386 switch (guiLevel)
387 {
388 case GUI_FULL :
389 {
390 ShowWindow(hwnd, SW_NORMAL);
391 break;
392 }
393
394 case GUI_TEMP :
395 {
396 ShowWindow(hwnd, SW_HIDE);
397 break;
398 }
399
400 case GUI_NOPE :
401 {
402 ShowWindow(hwnd, SW_HIDE);
403 break;
404 }
405
406 default :
407 {
408 ShowWindow(hwnd, SW_NORMAL);
409 break;
410 }
411 }
412
413
414 // gestion des messages de la fenêtre principale
415
416 MSG msg;
417 ZeroMemory(&msg, sizeof(msg));
418
419 while (TRUE)
420 {
421 if (msg.message == WM_QUIT)
422 {
423 break;
424 }
425
426 // ne pas utiliser PeekMessage(&msg,NULL,0,0,PM_REMOVE) car cela occupe le processeur en permanence !
427 // il vaut mieux utiliser GetMessage(&msg,NULL,0,0) qui ne retourne que lorsqu'il y a un message et
428 // laisse le processeur libre entre temps ...
429 if (GetMessage(&msg, NULL, 0, 0) > 0)
430 {
431 TranslateMessage(&msg);
432 DispatchMessage(&msg);
433 }
434 }
435
436
437 //DeleteObject(f_classe.hbrBackground);
438 OleUninitialize();
439
440 ReleaseMutex(hMutex);
441 CloseHandle(hMutex);
442
443 return msg.wParam;
444}
LRESULT CALLBACK Main_Procedure(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
procédure de la fenêtre principale.
Definition TaupieGUI.c:2661
#define SETLOCALE
Definition en_locale.h:79
static int ProcessCommandLine(HWND hwnd, wchar_t *lpCmdLine)
Traite les éventuels arguments passés au lancement de Taupie.
Definition main.c:135
#define ABOUT_TEXTW
Definition version.h:29
Voici le graphe d'appel pour cette fonction :