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

Annotation of /trunk/init/GPGOEInit.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (hide annotations)
Sat Mar 25 09:02:36 2006 UTC (19 years, 1 month ago) by twoaday
File MIME type: text/plain
File size: 3569 byte(s)
Complete autoconf support and cleanups.


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26