root/trunk/lib-src/progdlg.c

Revision 3104, 4.4 kB (checked in by himi, 5 years ago)

set svn:eol-style

  • Property svn:eol-style set to native
Line 
1 /* movemail foo bar -- move file foo to file bar,
2    locking file foo the way /bin/mail respects.
3    Copyright (C) 1986, 1992, 1993, 1994, 1996, 1997 Free Software Foundation, Inc.
4
5 This file is part of GNU Emacs.
6
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING.  If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 /*
23  * Modified Feb, 1998 by OOBA, Koichiro <koichiro@ca.mbn.or.jp>
24  *
25  * Added progress dialog.
26  * All modified code is within #ifdef PROGRESS_DIALOG
27  * It works only under x86-win32 systems.
28  * (It requires progdlg.c/progdlg.h/progdlg.rc)
29  * Special thanks to TSUKAHARA, Hiroki.
30  *
31  */
32
33 #include <windows.h>
34 #include <commctrl.h>
35
36 #define MOVEMAIL_USER_KEY  "SOFTWARE\\GNU\\Mule\\Movemail"
37
38 #define REG_RECT_TOP       "Top"
39 #define REG_RECT_LEFT      "Left"
40
41
42 static HINSTANCE s_hInst = NULL;
43 static HWND s_hWnd = NULL;
44 static int s_max;
45 static int s_current;
46
47 void
48 resume_window_pos (HWND hWnd)
49 {
50   HKEY hkey;
51   long ret;
52   DWORD type;
53   DWORD length;
54   DWORD left;
55   DWORD top;
56
57   if (hWnd == 0) return;
58
59   ret = RegOpenKeyEx(HKEY_CURRENT_USER, MOVEMAIL_USER_KEY, 0,
60                      KEY_READ, &hkey);
61   if (ret != ERROR_SUCCESS) return;
62
63   type = REG_DWORD;
64   length = sizeof(left);
65   ret = RegQueryValueEx(hkey, REG_RECT_LEFT, NULL, &type,
66                         (LPBYTE) &left, &length);
67   if (ret != ERROR_SUCCESS) {
68     RegCloseKey(hkey);
69     return;
70   }
71  
72   type = REG_DWORD;
73   length = sizeof(top);
74   ret = RegQueryValueEx(hkey, REG_RECT_TOP, NULL, &type,
75                         (LPBYTE) &top, &length);
76   if (ret != ERROR_SUCCESS) {
77     RegCloseKey(hkey);
78     return;
79   }
80  
81   SetWindowPos(hWnd, NULL, left, top, 0, 0,
82                SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
83   RegCloseKey(hkey);
84 }
85
86 void
87 save_window_pos (HWND hWnd)
88 {
89   HKEY hkey;
90   long ret;
91   RECT rect;
92   DWORD disposition;
93
94   if (hWnd == 0) return;
95   ret = GetWindowRect(hWnd, &rect);
96   if (ret == 0) return;
97
98   ret = RegCreateKeyEx(HKEY_CURRENT_USER, MOVEMAIL_USER_KEY, 0,
99                        REG_NONE, REG_OPTION_NON_VOLATILE,
100                        KEY_WRITE, NULL, &hkey,
101                        &disposition);
102   if (ret != ERROR_SUCCESS) return;
103
104   ret = RegSetValueEx(hkey, REG_RECT_TOP, 0, REG_DWORD,
105                       (LPBYTE) &rect.top, sizeof(DWORD));
106   ret = RegSetValueEx(hkey, REG_RECT_LEFT, 0, REG_DWORD,
107                       (LPBYTE) &rect.left, sizeof(DWORD));
108   RegCloseKey(hkey);
109 }
110
111 BOOL CALLBACK
112 DlgProc (HWND hWnd,
113          UINT uMsg,
114          WPARAM wParam,
115          LPARAM lParam)
116 {
117   static char buf[32];
118   switch (uMsg)
119     {
120     case WM_INITDIALOG:
121       resume_window_pos(hWnd);
122       wsprintf(buf, "%d/%d", s_current, s_max);
123       SendMessage(GetDlgItem(hWnd, 2), WM_SETTEXT, 0, (LPARAM) buf);
124       return TRUE;
125     case WM_DESTROY:
126       save_window_pos(hWnd);
127       return TRUE;
128     case WM_COMMAND:
129       SendMessage(GetDlgItem(hWnd, 1), PBM_STEPIT, 0, 0);
130       wsprintf(buf, "%d/%d", s_current, s_max);
131       SendMessage(GetDlgItem(hWnd, 2), WM_SETTEXT, 0, (LPARAM) buf);
132       return TRUE;
133     }
134
135   return FALSE;
136 }
137
138 void
139 progress_open (int max)
140 {
141   HWND hwndProgress;
142
143   if (s_hInst != NULL) return;
144   InitCommonControls();
145
146   s_max = max;
147   s_current = 0;
148
149   s_hInst = GetModuleHandle(NULL);
150   s_hWnd = CreateDialog(s_hInst, MAKEINTRESOURCE(1), NULL, DlgProc);
151   hwndProgress = GetDlgItem(s_hWnd, 1);
152
153   SendMessage(hwndProgress, PBM_SETRANGE, 0, MAKELPARAM(0, max));
154   SendMessage(hwndProgress, PBM_SETSTEP, 1, 0);
155   SendMessage(hwndProgress, PBM_SETPOS, 0, 0);
156
157   ShowWindow(s_hWnd, SW_SHOWNOACTIVATE);
158   UpdateWindow(s_hWnd);
159 }
160
161 void
162 progress_stepit ()
163 {
164   if (s_hWnd != 0) {
165     s_current++;
166     if (s_current <= s_max) {
167       SendMessage(s_hWnd, WM_COMMAND, 0, 0);
168     }
169   }
170 }
171
172 void
173 progress_close ()
174 {
175   if (s_hWnd != 0) {
176     DestroyWindow(s_hWnd);
177     s_hWnd = NULL;
178     s_hInst = NULL;
179   }
180 }
181
182 void
183 progress_winmain ()
184 {
185   MSG msg;
186
187   if( s_hWnd != 0 ){
188     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
189       TranslateMessage(&msg);
190       DispatchMessage(&msg);
191     }
192   }
193 }
Note: See TracBrowser for help on using the browser.