/[gpgoe]/trunk/init/GPGOEInit.c
ViewVC logotype

Contents of /trunk/init/GPGOEInit.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations)
Fri Mar 24 16:43:49 2006 UTC (19 years, 1 month ago) by twoaday
File MIME type: text/plain
File size: 3521 byte(s)
Cleanups.


1 /* GPGOEInit.c - GPGOE DLL Loader
2 * Copyright (C) 2001, 2002, 2006 Timo Schulz
3 *
4 * This file is part of GPGOE.
5 *
6 * GPGOE is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
10 *
11 * GPGOE is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with GPGOE; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19 */
20
21 #include <windows.h>
22 #include "resource.h"
23
24 /*-- GPGOE DLL calls --*/
25 int gpgoe_initialize (void);
26 int gpgoe_remove (void);
27
28
29 /* Global hinstance for this module. */
30 static HINSTANCE glob_hinst = NULL;
31
32
33 /* Main procedure for the taskbar program. */
34 LRESULT CALLBACK
35 gpgoe_main_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
36 {
37 NOTIFYICONDATA NID;
38 int id;
39
40 switch (msg) {
41 case WM_CREATE:
42 NID.cbSize = sizeof (NID);
43 NID.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
44 NID.uCallbackMessage = WM_USER;
45 NID.hWnd = hwnd;
46 NID.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_GPGOE));
47 strcpy (NID.szTip, "GPG for Outlook Express");
48 Shell_NotifyIcon (NIM_ADD, &NID);
49 DestroyIcon (NID.hIcon);
50 if (gpgoe_initialize ()) {
51 MessageBox (hwnd, "Couldn't register GPG OE hook",
52 "Error", MB_ICONERROR|MB_OK);
53 ExitProcess (0);
54 }
55 break;
56
57 case WM_DESTROY:
58 case WM_ENDSESSION:
59 gpgoe_remove ();
60 Shell_NotifyIcon (NIM_DELETE, &NID);
61 PostQuitMessage (0);
62 ExitProcess (0);
63 return 0;
64
65 case WM_USER:
66 switch (lparam) {
67 case WM_LBUTTONDBLCLK:
68 SetForegroundWindow (hwnd);
69 id = MessageBox (NULL, "Remove the GPG OE plug-in from the system?",
70 "Are you sure?", MB_YESNO|MB_ICONINFORMATION);
71 if (id == IDYES)
72 SendMessage (hwnd, WM_DESTROY, 0, 0);
73 break;
74
75 case WM_RBUTTONUP:
76 {
77 POINT p;
78 HMENU hm, popup;
79
80 GetCursorPos (&p);
81 hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_INIT));
82 popup = GetSubMenu (hm, 0);
83 TrackPopupMenu (popup, TPM_RIGHTALIGN, p.x, p.y, 0, hwnd, NULL);
84 DestroyMenu (popup);
85 DestroyMenu (hm);
86 }
87 break;
88 }
89 break;
90
91 case WM_COMMAND:
92 if (LOWORD (wparam) == ID_INIT_QUIT)
93 SendMessage (hwnd, WM_DESTROY, 0, 0);
94 break;
95 }
96 return DefWindowProc (hwnd, msg, wparam, lparam);
97 }
98
99
100 int WINAPI
101 WinMain (HINSTANCE hinst, HINSTANCE prev, LPSTR cmdline, int cmd_show)
102 {
103 WNDCLASS wc;
104 HWND hwnd;
105 MSG msg;
106
107 glob_hinst = hinst;
108 CreateMutex (NULL, 1, "GPGOE");
109 if (GetLastError () == ERROR_ALREADY_EXISTS)
110 return 0;
111
112 memset (&wc, 0, sizeof(wc));
113 wc.hInstance = hinst;
114 wc.lpszClassName = "GPGOE";
115 wc.lpfnWndProc = (WNDPROC)gpgoe_main_proc;
116 if (!RegisterClass (&wc)) {
117 MessageBox (NULL, "Couldn't register the window class",
118 "Error", MB_ICONERROR|MB_OK);
119 return 1;
120 }
121
122 hwnd = CreateWindow ("GPGOE", "GPGOE", 0, 0, 0, 0, 0,
123 NULL, NULL, hinst, NULL);
124 if (!hwnd) {
125 MessageBox (NULL, "Couldn't create window",
126 "Error", MB_ICONERROR|MB_OK);
127 return 1;
128 }
129 UpdateWindow (hwnd);
130 while (GetMessage (&msg, hwnd, 0, 0)) {
131 TranslateMessage (&msg);
132 DispatchMessage (&msg);
133 }
134 return 0;
135 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26