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

Contents of /trunk/init/GPGOEInit.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations)
Fri Mar 24 13:36:54 2006 UTC (19 years, 1 month ago) by twoaday
File MIME type: text/plain
File size: 3411 byte(s)
Initial checkin of the GPGOE code.


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
23 #include "resource.h"
24
25 /*-- GPGOE DLL calls --*/
26 int gpgoe_initialize (void);
27 int gpgoe_remove (void);
28
29 static HINSTANCE glob_hinst = NULL;
30
31
32 LRESULT CALLBACK
33 gpgoe_main_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
34 {
35 NOTIFYICONDATA NID;
36 int id;
37
38 switch (msg)
39 {
40 case WM_CREATE:
41 NID.cbSize = sizeof(NID);
42 NID.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
43 NID.uCallbackMessage = WM_USER;
44 NID.hWnd = hwnd;
45 NID.hIcon = LoadIcon(glob_hinst, MAKEINTRESOURCE(IDI_GPGOE));
46 strcpy(NID.szTip, "GPG for Outlook Express");
47 Shell_NotifyIcon (NIM_ADD, &NID);
48 DestroyIcon (NID.hIcon);
49 if (gpgoe_initialize ()) {
50 MessageBox (hwnd, "Couldn't register GPG OE hook", "Error", MB_ICONERROR|MB_OK);
51 ExitProcess (0);
52 }
53 break;
54
55 case WM_DESTROY:
56 case WM_ENDSESSION:
57 gpgoe_remove ();
58 Shell_NotifyIcon(NIM_DELETE, &NID);
59 PostQuitMessage (0);
60 ExitProcess (0);
61 return 0;
62
63 case WM_USER:
64 switch (lparam) {
65 case WM_LBUTTONDBLCLK:
66 SetForegroundWindow(hwnd);
67 id = MessageBox (NULL, "Remove the GPG OE plug-in from the system?",
68 "Are you sure?", MB_YESNO|MB_ICONINFORMATION);
69 if (id == IDYES)
70 SendMessage (hwnd, WM_DESTROY, 0, 0);
71 break;
72
73 case WM_RBUTTONUP:
74 {
75 POINT p;
76 HMENU hm, popup;
77
78 GetCursorPos (&p);
79 hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_INIT));
80 popup = GetSubMenu (hm, 0);
81 TrackPopupMenu (popup, TPM_RIGHTALIGN, p.x, p.y, 0, hwnd, NULL);
82 DestroyMenu (popup);
83 DestroyMenu (hm);
84 }
85 break;
86 }
87 break;
88
89 case WM_COMMAND:
90 if (LOWORD (wparam) == ID_INIT_QUIT)
91 SendMessage(hwnd, WM_DESTROY, 0, 0);
92 break;
93 }
94 return DefWindowProc(hwnd, msg, wparam, lparam);
95 }
96
97
98 int WINAPI
99 WinMain (HINSTANCE hinst, HINSTANCE prev, LPSTR cmdline, int cmd_show)
100 {
101 WNDCLASS wc;
102 HWND hwnd;
103 MSG msg;
104
105 glob_hinst = hinst;
106 CreateMutex (NULL, 1, "GPGOE");
107 if (GetLastError () == ERROR_ALREADY_EXISTS)
108 return 0;
109
110 memset(&wc, 0, sizeof(wc));
111 wc.hInstance = hinst;
112 wc.lpszClassName = "GPGOE";
113 wc.lpfnWndProc = (WNDPROC)gpgoe_main_proc;
114 if (!RegisterClass(&wc)) {
115 MessageBox(NULL, "Couldn't register the window class", "Error",
116 MB_ICONERROR|MB_OK);
117 return 1;
118 }
119
120 hwnd = CreateWindow ("GPGOE", "GPGOE", 0, 0, 0, 0, 0, NULL, NULL, hinst, NULL);
121 if (!hwnd) {
122 MessageBox (NULL, "Couldn't create window", "Error", MB_ICONERROR|MB_OK);
123 return 1;
124 }
125 UpdateWindow (hwnd);
126 while (GetMessage (&msg, hwnd, 0, 0)) {
127 TranslateMessage (&msg);
128 DispatchMessage (&msg);
129 }
130 return 0;
131 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26