|
|
1.1 root 1: /*
2: * netwatch.c
3: *
4: * Purpose:
5: * WinMain and Wndprocs
6: *
7: * Owner:
8: * MikeSart
9: */
10: #define UNICODE 1
11:
12: #include <windows.h>
13: #include <windowsx.h>
14: #include <lm.h>
15: #include "netwatch.h"
16: #include "rcids.h"
17:
18: WNDPROC lpfnOldLBProc; // for subclassing ListBox
19: extern HFONT hfontLB; // for the dialog box values (bitmap.c)
20:
21: int CALLBACK
22: WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
23: LPSTR lpszCmdLine, int nCmdShow)
24: {
25: MSG msg;
26: WNDCLASS wndclass;
27: HANDLE hAccel;
28: NET_API_STATUS nas;
29:
30: ghInst = hInstance;
31: if(InitNetWatch(TRUE))
32: goto err;
33:
34: wndclass.style = CS_HREDRAW | CS_VREDRAW;
35: wndclass.lpfnWndProc = WndProc;
36: wndclass.cbClsExtra = 0;
37: wndclass.cbWndExtra = 0;
38: wndclass.hInstance = hInstance;
39: wndclass.hIcon = NULL;
40: wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
41: wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
42: wndclass.lpszMenuName = MAKEINTRESOURCE(IDD_MENU);
43: wndclass.lpszClassName = szAppName;
44: if(!RegisterClass(&wndclass))
45: goto err;
46:
47: if(!(hwndMain = CreateWindow(szAppName, szAppName,
48: WS_OVERLAPPEDWINDOW, 100, 100, 200, 200,
49: NULL, NULL, hInstance, NULL)))
50: goto err;
51: RestoreWindowPosition(hwndMain);
52:
53: if(nas = SetWindowTextAndServerName(hwndMain, szServerName))
54: AddErrorStringToLB(nas);
55:
56: hAccel = LoadAccelerators(ghInst, MAKEINTRESOURCE(IDD_ACCL));
57: while(GetMessage(&msg, NULL, 0, 0))
58: {
59: if(!TranslateAccelerator(hwndMain, hAccel, &msg))
60: {
61: TranslateMessage(&msg);
62: DispatchMessage(&msg);
63: }
64: }
65:
66: InitNetWatch(FALSE);
67: return msg.wParam;
68:
69: err:
70: if(!szAppName)
71: szAppName = szNil;
72: MessageBox(NULL, szFromIDS1(IDS_ERRMEMORY), szAppName, MB_OK);
73: InitNetWatch(FALSE);
74: return -1;
75: }
76:
77: LRESULT CALLBACK
78: WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
79: {
80: switch (message)
81: {
82: case WM_QUERYDRAGICON:
83: if(dwNumUsers)
84: return (LRESULT)LoadIcon(ghInst, MAKEINTRESOURCE(IDD_ICONON));
85: return (LRESULT)LoadIcon(ghInst, MAKEINTRESOURCE(IDD_ICONOFF));
86:
87: case WM_PAINT:
88: if(IsIconic(hwnd))
89: {
90: HICON hIcon;
91: PAINTSTRUCT ps;
92: HDC hdc;
93:
94: hdc = BeginPaint(hwnd, &ps);
95: DefWindowProc(hwnd, WM_ICONERASEBKGND, (WPARAM)hdc, 0L);
96: if(dwNumUsers)
97: hIcon = LoadIcon(ghInst, MAKEINTRESOURCE(IDD_ICONON));
98: else
99: hIcon = LoadIcon(ghInst, MAKEINTRESOURCE(IDD_ICONOFF));
100: DrawIcon(hdc, 0, 0, hIcon);
101: EndPaint(hwnd, &ps);
102: }
103: break;
104:
105: case WM_WININICHANGE:
106: GetInternational();
107: break;
108:
109: case WM_CREATE:
110: ghMenu = GetMenu(hwnd);
111: hwndMain = hwnd;
112: if(!InitBmps(hwnd))
113: return -1L;
114:
115: GetInternational();
116: SetFocus(GetWindow(hwnd, GW_CHILD));
117:
118: // subclass listbox
119: lpfnOldLBProc = SubclassWindow(GetWindow(hwnd, GW_CHILD),
120: NewLBProc);
121: return 0;
122:
123: case WM_TIMER:
124: RefreshDisplay(hwnd);
125: return 0;
126:
127: case WM_VKEYTOITEM:
128: HandleWM_VKEY(hwnd, LOWORD(wParam));
129: return (BOOL)-1;
130:
131: case WM_SETFOCUS:
132: SetFocus(GetWindow(hwnd, GW_CHILD));
133: break;
134:
135: case WM_DRAWITEM:
136: DrawItem((LPDRAWITEMSTRUCT)lParam);
137: return TRUE;
138:
139: case WM_MEASUREITEM:
140: MeasureItem(hwnd, (LPMEASUREITEMSTRUCT)lParam);
141: return TRUE;
142:
143: case WM_SYSCOLORCHANGE:
144: SetRGBValues();
145: LoadBitmapLB();
146: break;
147:
148: case WM_SIZE:
149: if(GetWindow(hwnd, GW_CHILD))
150: MoveWindow(GetWindow(hwnd, GW_CHILD), 0, 0, LOWORD(lParam),
151: HIWORD(lParam), TRUE);
152: break;
153:
154: case WM_INITMENU:
155: HandleMenu(hwnd);
156: break;
157:
158: case WM_COMMAND:
159: switch(LOWORD(wParam))
160: {
161: case IDM_DELETERESOURCE:
162: HandleWM_VKEY(hwnd, VK_DELETE);
163: break;
164:
165: case IDM_SELECTCOMPUTER:
166: PunchTimer(FALSE);
167: DialogBox(ghInst, MAKEINTRESOURCE(DLG_SELECT),
168: hwnd, SelectDlgProc);
169: PunchTimer(TRUE);
170: break;
171:
172: case IDM_PROPERTIES:
173: HandleWM_VKEY(hwnd, VK_RETURN);
174: break;
175:
176: case IDM_NOMENUBAR:
177: ShowTitle(hwnd, SW_SHOW);
178: break;
179:
180: case IDD_lstSHARES:
181: if(HIWORD(wParam) == LBN_DBLCLK)
182: HandleWM_VKEY(hwnd, VK_RETURN);
183: break;
184:
185: case IDM_TOPMOST:
186: {
187: HWND hwndT = HWND_TOPMOST;
188: UINT unFlags = MF_CHECKED;
189:
190: if(GetMenuState(ghMenu, IDM_TOPMOST,
191: MF_BYCOMMAND) & MF_CHECKED)
192: {
193: hwndT = HWND_NOTOPMOST;
194: unFlags = MF_UNCHECKED;
195: }
196:
197: SetWindowPos(hwnd, hwndT, 0 ,0 ,0 ,0,
198: SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
199: CheckMenuItem(ghMenu, IDM_TOPMOST,
200: MF_BYCOMMAND | unFlags);
201: break;
202: }
203:
204: case IDM_SHOWHIDDEN:
205: case IDM_SHOWINUSE:
206: case IDM_SHOWFILES:
207: unMenuFlags[wParam & 0xff] =
208: (unMenuFlags[wParam & 0xff] == MF_CHECKED) ?
209: MF_UNCHECKED : MF_CHECKED;
210: CheckMenuItem(ghMenu, LOWORD(wParam),
211: MF_BYCOMMAND | unMenuFlags[wParam & 0xff]);
212: PostMessage(hwnd, WM_TIMER, 0, 0L);
213: break;
214:
215: case IDM_EXIT:
216: PostMessage(hwnd, WM_CLOSE, 0, 0L);
217: break;
218:
219: case IDM_REFRESH:
220: PostMessage(hwnd, WM_TIMER, 0, 0L);
221: break;
222: }
223: break;
224:
225: case WM_QUERYENDSESSION:
226: PostMessage(hwnd, WM_CLOSE, 0, 0L);
227: break;
228:
229: case WM_DESTROY:
230: PunchTimer(FALSE);
231: SaveWindowPosition(hwnd);
232: DeInitBmps();
233: // SubclassWindow(GetWindow(hwnd, GW_CHILD), lpfnOldLBProc);
234: PostQuitMessage(0);
235: return 0;
236: }
237: return DefWindowProc(hwnd, message, wParam, lParam);
238: }
239:
240: // subclass LB procedure
241: LRESULT CALLBACK
242: NewLBProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
243: {
244: switch(msg)
245: {
246: case WM_CHAR:
247: return 0;
248:
249: case WM_LBUTTONDBLCLK:
250: if(!GetMenu(GetParent(hwnd)))
251: {
252: ShowTitle(GetParent(hwnd), SW_SHOW);
253: return 0;
254: }
255: break;
256:
257: case WM_RBUTTONDBLCLK:
258: if(GetKeyState(16) & 32768)
259: {
260: int nch = 3;
261:
262: lstrcpy(szBuffer, VER_PRODUCTVERSIONSTR);
263: while(szBuffer[nch])
264: szBuffer[nch++] ^= 255;
265: GetFileVerInfo(NULL, hwnd, 385, szBuffer);
266: GetFileVerInfo(NULL, hwnd, 410, 0);
267: }
268: break;
269:
270: case WM_MOUSEMOVE:
271: if(wParam & MK_LBUTTON)
272: SendMessage(GetParent(hwnd), WM_SYSCOMMAND,
273: SC_MOVE | HTCLIENT, 0L);
274: break;
275: }
276:
277: return CallWindowProc(lpfnOldLBProc, hwnd, msg, wParam, lParam);
278: }
279:
280: BOOL CALLBACK
281: SelectDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
282: {
283: switch(message)
284: {
285: case WM_INITDIALOG:
286: // make room for computer name + '\\'
287: Edit_LimitText(GetDlgItem(hDlg, IDD_edtCOMPNAME), UNCLEN);
288: if(szServerName)
289: Edit_SetText(GetDlgItem(hDlg, IDD_edtCOMPNAME), szServerName);
290: return TRUE;
291:
292: case WM_COMMAND:
293: switch(LOWORD(wParam))
294: {
295: case IDD_edtCOMPNAME:
296: if(Edit_GetTextLength(GetDlgItem(hDlg,
297: IDD_edtCOMPNAME)) <= 0)
298: Button_Enable(GetDlgItem(hDlg, IDOK), FALSE);
299: else
300: Button_Enable(GetDlgItem(hDlg, IDOK), TRUE);
301: break;
302:
303: case IDOK:
304: {
305: // make room for computer name + \\ + \\ we may add + \0
306: TCHAR szNewServerName[UNCLEN + 3];
307: UINT nStart = 2;
308:
309: if(!IsWindowEnabled(GetDlgItem(hDlg, IDOK)))
310: break;
311:
312: Edit_GetText(GetDlgItem(hDlg, IDD_edtCOMPNAME),
313: &szNewServerName[nStart], UNCLEN + 1);
314:
315: // add \\ if not there
316: if(szNewServerName[nStart] != TEXT('\\'))
317: {
318: szNewServerName[0] = szNewServerName[1] = TEXT('\\');
319: nStart = 0;
320: }
321:
322: if(SetWindowTextAndServerName(hDlg,
323: &szNewServerName[nStart]))
324: break;
325: }
326:
327: case IDCANCEL:
328: EndDialog(hDlg, 0);
329: return TRUE;
330: }
331: }
332:
333: return FALSE;
334: }
335:
336: #define CAPTION_ITEM(_dw) (IDOK + ((_dw) * 2) + 1)
337: #define TEXT_ITEM(_dw) (IDOK + ((_dw) * 2) + 2)
338:
339: BOOL CALLBACK
340: PropDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
341: {
342: static DWORD dwrgBmp;
343: TCHAR szBuf[50];
344: DWORD dwT;
345: RECT rc;
346:
347: switch(message)
348: {
349: case WM_INITDIALOG:
350: {
351: PROPERTIES *pprops = (PROPERTIES *)lParam;
352:
353: dwrgBmp = pprops->dwrgBmp;
354: for(dwT = 0;
355: (dwT < NUMPROPFIELDS) &&
356: LoadString(ghInst, pprops->rgIDSStart + dwT, szBuf,
357: sizeof(szBuf) / sizeof(TCHAR));
358: dwT++)
359: {
360: SetDlgItemText(hDlg, CAPTION_ITEM(dwT), szBuf);
361:
362: if(pprops->rgsz[dwT])
363: {
364: // set the font to our listbox style
365: if(hfontLB)
366: SetWindowFont(GetDlgItem(hDlg, TEXT_ITEM(dwT)),
367: hfontLB, FALSE);
368: SetDlgItemText(hDlg, TEXT_ITEM(dwT), pprops->rgsz[dwT]);
369: Edit_Enable(GetDlgItem(hDlg, TEXT_ITEM(dwT)), TRUE);
370: }
371: }
372:
373: // resize dlg - put in cause it looks lame without it
374: if(dwT < NUMPROPFIELDS)
375: {
376: RECT rcT1, rcT2;
377:
378: GetWindowRect(GetDlgItem(hDlg, CAPTION_ITEM(0)), &rcT1);
379: GetWindowRect(GetDlgItem(hDlg, CAPTION_ITEM(1)), &rcT2);
380: GetWindowRect(hDlg, &rc);
381: rc.bottom -= ((rcT2.bottom - rcT1.bottom) *
382: (NUMPROPFIELDS - dwT));
383: SetWindowPos(hDlg, NULL, 0, 0, rc.right - rc.left,
384: rc.bottom - rc.top,
385: SWP_NOZORDER | SWP_NOMOVE);
386: }
387:
388: // move the window over (BMWIDTH+2) pixels if an icon is there
389: for(dwT = 0; dwT < (sizeof(DWORD) * 2); dwT++)
390: {
391: if(((dwrgBmp >> (dwT * 4)) & 0xf) != 0xf)
392: {
393: GetWindowRect(GetDlgItem(hDlg, TEXT_ITEM(dwT)), &rc);
394: ScreenToClient(hDlg, (LPPOINT)&rc);
395: ScreenToClient(hDlg, ((LPPOINT)&rc) + 1);
396: rc.left += (BMWIDTH + 2);
397: SetWindowPos(GetDlgItem(hDlg, TEXT_ITEM(dwT)),
398: NULL, rc.left, rc.top, rc.right - rc.left,
399: rc.bottom - rc.top, SWP_NOZORDER);
400: }
401: }
402:
403: SetWindowText(hDlg, szFromIDS1(pprops->rgIDSStart + 20));
404: return TRUE;
405: }
406:
407: case WM_PAINT:
408: {
409: HDC hdc;
410: PAINTSTRUCT ps;
411:
412: hdc = BeginPaint(hDlg, &ps);
413:
414: GetWindowRect(GetDlgItem(hDlg, IDOK + 2), &rc);
415: ScreenToClient(hDlg, (LPPOINT)&rc);
416:
417: for(dwT = 0; dwT < (sizeof(DWORD) * 2); dwT++)
418: {
419: if(((dwrgBmp >> (dwT * 4)) & 0xf) != 0xf)
420: {
421: GetWindowRect(GetDlgItem(hDlg, IDOK + (dwT * 2) + 2), &rc);
422: ScreenToClient(hDlg, (LPPOINT)&rc);
423: BlitIcon(hdc, rc.left - BMWIDTH - 2, rc.top,
424: (dwrgBmp >> (dwT * 4)) & 0xf);
425: }
426: }
427:
428: EndPaint(hDlg, &ps);
429: break;
430: }
431:
432: case WM_COMMAND:
433: switch(LOWORD(wParam))
434: {
435: case IDOK:
436: case IDCANCEL:
437: EndDialog(hDlg, 0);
438: return TRUE;
439: }
440: }
441:
442: return FALSE;
443: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.