| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 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 |
} |
|---|