Annotation of mstools/samples/sdktools/netwatch/netwatch.c, revision 1.1.1.2

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.