ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

mainwnd.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:     ReactOS Services
00003  * LICENSE:     GPL - See COPYING in the top level directory
00004  * FILE:        base/applications/mscutils/servman/mainwnd.c
00005  * PURPOSE:     Main window message handler
00006  * COPYRIGHT:   Copyright 2006-2007 Ged Murphy <gedmurphy@reactos.org>
00007  *
00008  */
00009 
00010 #include "precomp.h"
00011 
00012 static const TCHAR szMainWndClass[] = TEXT("ServManWndClass");
00013 
00014 BOOL bSortAscending = TRUE;
00015 
00016 
00017 /* Toolbar buttons */
00018 static const TBBUTTON Buttons [] =
00019 {   /* iBitmap, idCommand, fsState, fsStyle, bReserved[2], dwData, iString */
00020     {TBICON_PROP,    ID_PROP,    TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0},    /* properties */
00021     {TBICON_REFRESH, ID_REFRESH, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},          /* refresh */
00022     {TBICON_EXPORT,  ID_EXPORT,  TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},          /* export */
00023 
00024     /* Note: First item for a seperator is its width in pixels */
00025     {15, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0},                                  /* separator */
00026 
00027     {TBICON_CREATE,  ID_CREATE,  TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0 },         /* create */
00028     {TBICON_DELETE,  ID_DELETE,  TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0 },   /* delete */
00029 
00030     {15, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0},                                  /* separator */
00031 
00032     {TBICON_START,   ID_START,   TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0 },   /* start */
00033     {TBICON_STOP,    ID_STOP,    TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0 },   /* stop */
00034     {TBICON_PAUSE,   ID_PAUSE,   TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0 },   /* pause */
00035     {TBICON_RESTART, ID_RESTART, TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0 },   /* restart */
00036 };
00037 
00038 
00039 /* menu hints */
00040 static const MENU_HINT MainMenuHintTable[] = {
00041     /* File Menu */
00042     {ID_EXPORT,    IDS_HINT_EXPORT},
00043     {ID_EXIT,      IDS_HINT_EXIT},
00044 
00045     /* Action Menu */
00046     {ID_CONNECT,  IDS_HINT_CONNECT},
00047     {ID_START,    IDS_HINT_START},
00048     {ID_STOP,     IDS_HINT_STOP},
00049     {ID_PAUSE,    IDS_HINT_PAUSE},
00050     {ID_RESUME,   IDS_HINT_RESUME},
00051     {ID_RESTART,  IDS_HINT_RESTART},
00052     {ID_REFRESH,  IDS_HINT_REFRESH},
00053     {ID_EDIT,     IDS_HINT_EDIT},
00054     {ID_CREATE,   IDS_HINT_CREATE},
00055     {ID_DELETE,   IDS_HINT_DELETE},
00056     {ID_PROP,     IDS_HINT_PROP},
00057 
00058     /* View menu */
00059     {ID_VIEW_LARGE,   IDS_HINT_LARGE},
00060     {ID_VIEW_SMALL,   IDS_HINT_SMALL},
00061     {ID_VIEW_LIST,    IDS_HINT_LIST},
00062     {ID_VIEW_DETAILS, IDS_HINT_DETAILS},
00063     {ID_VIEW_CUST,    IDS_HINT_CUST},
00064 
00065     /* Help Menu */
00066     {ID_HELP,     IDS_HINT_HELP},
00067     {ID_ABOUT,    IDS_HINT_ABOUT}
00068 };
00069 /* system menu hints */
00070 static const MENU_HINT SystemMenuHintTable[] = {
00071     {SC_RESTORE,    IDS_HINT_SYS_RESTORE},
00072     {SC_MOVE,       IDS_HINT_SYS_MOVE},
00073     {SC_SIZE,       IDS_HINT_SYS_SIZE},
00074     {SC_MINIMIZE,   IDS_HINT_SYS_MINIMIZE},
00075     {SC_MAXIMIZE,   IDS_HINT_SYS_MAXIMIZE},
00076     {SC_CLOSE,      IDS_HINT_SYS_CLOSE},
00077 };
00078 
00079 
00080 static BOOL
00081 MainWndMenuHint(PMAIN_WND_INFO Info,
00082                 WORD CmdId,
00083                 const MENU_HINT *HintArray,
00084                 DWORD HintsCount,
00085                 UINT DefHintId)
00086 {
00087     BOOL Found = FALSE;
00088     const MENU_HINT *LastHint;
00089     UINT HintId = DefHintId;
00090 
00091     LastHint = HintArray + HintsCount;
00092     while (HintArray != LastHint)
00093     {
00094         if (HintArray->CmdId == CmdId)
00095         {
00096             HintId = HintArray->HintId;
00097             Found = TRUE;
00098             break;
00099         }
00100         HintArray++;
00101     }
00102 
00103     StatusBarLoadString(Info->hStatus,
00104                         SB_SIMPLEID,
00105                         hInstance,
00106                         HintId);
00107 
00108     return Found;
00109 }
00110 
00111 
00112 static VOID
00113 UpdateMainStatusBar(PMAIN_WND_INFO Info)
00114 {
00115     if (Info->hStatus != NULL)
00116     {
00117         SendMessage(Info->hStatus,
00118                     SB_SIMPLE,
00119                     (WPARAM)Info->bInMenuLoop,
00120                     0);
00121     }
00122 }
00123 
00124 VOID
00125 UpdateServiceCount(PMAIN_WND_INFO Info)
00126 {
00127     LPTSTR lpNumServices;
00128 
00129     if (AllocAndLoadString(&lpNumServices,
00130                            hInstance,
00131                            IDS_NUM_SERVICES))
00132     {
00133         TCHAR szNumServices[32];
00134 
00135         INT NumListedServ = ListView_GetItemCount(Info->hListView);
00136 
00137         _sntprintf(szNumServices,
00138                    31,
00139                    lpNumServices,
00140                    NumListedServ);
00141 
00142         SendMessage(Info->hStatus,
00143                     SB_SETTEXT,
00144                     0,
00145                     (LPARAM)szNumServices);
00146 
00147         LocalFree(lpNumServices);
00148     }
00149 }
00150 
00151 
00152 VOID SetMenuAndButtonStates(PMAIN_WND_INFO Info)
00153 {
00154     HMENU hMainMenu;
00155     UINT i;
00156 
00157     /* get handle to menu */
00158     hMainMenu = GetMenu(Info->hMainWnd);
00159 
00160     /* set all to greyed */
00161     for (i = ID_START; i <= ID_RESTART; i++)
00162     {
00163         EnableMenuItem(hMainMenu, i, MF_GRAYED);
00164         EnableMenuItem(GetSubMenu(Info->hShortcutMenu, 0), i, MF_GRAYED);
00165         SendMessage(Info->hTool, TB_SETSTATE, i,
00166                     (LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
00167     }
00168 
00169     if (Info->SelectedItem != NO_ITEM_SELECTED)
00170     {
00171         LPQUERY_SERVICE_CONFIG lpServiceConfig = NULL;
00172         DWORD Flags, State;
00173 
00174         /* allow user to delete service */
00175         if (Info->bIsUserAnAdmin)
00176         {
00177             SendMessage(Info->hTool, TB_SETSTATE, ID_DELETE,
00178                        (LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
00179             EnableMenuItem(hMainMenu, ID_DELETE, MF_ENABLED);
00180             EnableMenuItem(GetSubMenu(Info->hShortcutMenu, 0), ID_DELETE, MF_ENABLED);
00181         }
00182 
00183         Flags = Info->pCurrentService->ServiceStatusProcess.dwControlsAccepted;
00184         State = Info->pCurrentService->ServiceStatusProcess.dwCurrentState;
00185 
00186         lpServiceConfig = GetServiceConfig(Info->pCurrentService->lpServiceName);
00187 
00188         if (lpServiceConfig && lpServiceConfig->dwStartType != SERVICE_DISABLED)
00189         {
00190             if (State == SERVICE_STOPPED)
00191             {
00192                 EnableMenuItem(hMainMenu, ID_START, MF_ENABLED);
00193                 EnableMenuItem(GetSubMenu(Info->hShortcutMenu, 0), ID_START, MF_ENABLED);
00194                 SendMessage(Info->hTool, TB_SETSTATE, ID_START,
00195                        (LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
00196             }
00197 
00198             if ( (Flags & SERVICE_ACCEPT_STOP) && (State == SERVICE_RUNNING) )
00199             {
00200                 EnableMenuItem(hMainMenu, ID_RESTART, MF_ENABLED);
00201                 EnableMenuItem(GetSubMenu(Info->hShortcutMenu, 0), ID_RESTART, MF_ENABLED);
00202                 SendMessage(Info->hTool, TB_SETSTATE, ID_RESTART,
00203                        (LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
00204             }
00205 
00206             HeapFree(GetProcessHeap(), 0, lpServiceConfig);
00207         }
00208 
00209         if ( (Flags & SERVICE_ACCEPT_STOP) && (State == SERVICE_RUNNING) )
00210         {
00211             EnableMenuItem(hMainMenu, ID_STOP, MF_ENABLED);
00212             EnableMenuItem(GetSubMenu(Info->hShortcutMenu, 0), ID_STOP, MF_ENABLED);
00213             SendMessage(Info->hTool, TB_SETSTATE, ID_STOP,
00214                    (LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
00215         }
00216 
00217         if ( (Flags & SERVICE_ACCEPT_PAUSE_CONTINUE) && (State == SERVICE_RUNNING) )
00218         {
00219             EnableMenuItem(hMainMenu, ID_PAUSE, MF_ENABLED);
00220             EnableMenuItem(GetSubMenu(Info->hShortcutMenu, 0), ID_PAUSE, MF_ENABLED);
00221             SendMessage(Info->hTool, TB_SETSTATE, ID_PAUSE,
00222                    (LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
00223         }
00224     }
00225     else
00226     {
00227         /* disable tools which rely on a selected service */
00228         EnableMenuItem(hMainMenu, ID_PROP, MF_GRAYED);
00229         EnableMenuItem(hMainMenu, ID_DELETE, MF_GRAYED);
00230         EnableMenuItem(GetSubMenu(Info->hShortcutMenu, 0), ID_PROP, MF_GRAYED);
00231         EnableMenuItem(GetSubMenu(Info->hShortcutMenu, 0), ID_DELETE, MF_GRAYED);
00232         SendMessage(Info->hTool, TB_SETSTATE, ID_PROP,
00233                    (LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
00234         SendMessage(Info->hTool, TB_SETSTATE, ID_DELETE,
00235                    (LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
00236     }
00237 
00238 }
00239 
00240 
00241 static INT CALLBACK
00242 CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
00243 {
00244     ENUM_SERVICE_STATUS_PROCESS *Param1;
00245     ENUM_SERVICE_STATUS_PROCESS *Param2;
00246 //    INT iSubItem = (LPARAM)lParamSort;
00247 
00248     if (bSortAscending) {
00249         Param1 = (ENUM_SERVICE_STATUS_PROCESS *)lParam1;
00250         Param2 = (ENUM_SERVICE_STATUS_PROCESS *)lParam2;
00251     }
00252     else
00253     {
00254         Param1 = (ENUM_SERVICE_STATUS_PROCESS *)lParam2;
00255         Param2 = (ENUM_SERVICE_STATUS_PROCESS *)lParam1;
00256     }
00257     return _tcsicmp(Param1->lpDisplayName, Param2->lpDisplayName);
00258 }
00259 
00260 
00261 static BOOL
00262 pCreateToolbar(PMAIN_WND_INFO Info)
00263 {
00264     INT numButtons = sizeof(Buttons) / sizeof(Buttons[0]);
00265 
00266     Info->hTool = CreateWindowEx(0,
00267                                  TOOLBARCLASSNAME,
00268                                  NULL,
00269                                  WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS,
00270                                  0, 0, 0, 0,
00271                                  Info->hMainWnd,
00272                                  0,
00273                                  hInstance,
00274                                  NULL);
00275     if(Info->hTool != NULL)
00276     {
00277         HIMAGELIST hImageList;
00278 
00279         SendMessage(Info->hTool,
00280                     TB_SETEXTENDEDSTYLE,
00281                     0,
00282                     TBSTYLE_EX_HIDECLIPPEDBUTTONS);
00283 
00284         SendMessage(Info->hTool,
00285                     TB_BUTTONSTRUCTSIZE,
00286                     sizeof(Buttons[0]),
00287                     0);
00288 
00289         hImageList = InitImageList(IDB_PROP,
00290                                    IDB_RESTART,
00291                                    GetSystemMetrics(SM_CXSMICON),
00292                                    GetSystemMetrics(SM_CXSMICON),
00293                                    IMAGE_BITMAP);
00294         if (hImageList == NULL)
00295             return FALSE;
00296 
00297         ImageList_Destroy((HIMAGELIST)SendMessage(Info->hTool,
00298                                                   TB_SETIMAGELIST,
00299                                                   0,
00300                                                   (LPARAM)hImageList));
00301 
00302         SendMessage(Info->hTool,
00303                     TB_ADDBUTTONS,
00304                     numButtons,
00305                     (LPARAM)Buttons);
00306 
00307         return TRUE;
00308     }
00309 
00310     return FALSE;
00311 }
00312 
00313 static BOOL
00314 CreateStatusBar(PMAIN_WND_INFO Info)
00315 {
00316     INT StatWidths[] = {110, -1}; /* widths of status bar */
00317 
00318     Info->hStatus = CreateWindowEx(0,
00319                                    STATUSCLASSNAME,
00320                                    NULL,
00321                                    WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,
00322                                    0, 0, 0, 0,
00323                                    Info->hMainWnd,
00324                                    (HMENU)IDC_STATUSBAR,
00325                                    hInstance,
00326                                    NULL);
00327     if(Info->hStatus == NULL)
00328         return FALSE;
00329 
00330     SendMessage(Info->hStatus,
00331                 SB_SETPARTS,
00332                 sizeof(StatWidths) / sizeof(INT),
00333                 (LPARAM)StatWidths);
00334 
00335     return TRUE;
00336 }
00337 
00338 
00339 static BOOL
00340 InitMainWnd(PMAIN_WND_INFO Info)
00341 {
00342     if (!pCreateToolbar(Info))
00343     {
00344         DisplayString(_T("error creating toolbar"));
00345         return FALSE;
00346     }
00347 
00348     if (!CreateListView(Info))
00349     {
00350         DisplayString(_T("error creating list view"));
00351         return FALSE;
00352     }
00353 
00354     if (!CreateStatusBar(Info))
00355         DisplayString(_T("error creating status bar"));
00356 
00357     /* Create Popup Menu */
00358     Info->hShortcutMenu = LoadMenu(hInstance,
00359                                    MAKEINTRESOURCE(IDR_POPUP));
00360 
00361     Info->bIsUserAnAdmin = IsUserAnAdmin();
00362     if (Info->bIsUserAnAdmin)
00363     {
00364         HMENU hMainMenu = GetMenu(Info->hMainWnd);
00365 
00366         SendMessage(Info->hTool,
00367                     TB_SETSTATE,
00368                     ID_CREATE,
00369                     (LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
00370         if (hMainMenu)
00371         {
00372             EnableMenuItem(hMainMenu,
00373                            ID_CREATE,
00374                            MF_ENABLED);
00375         }
00376         EnableMenuItem(GetSubMenu(Info->hShortcutMenu, 0),
00377                        ID_CREATE,
00378                        MF_ENABLED);
00379     }
00380 
00381     return TRUE;
00382 }
00383 
00384 
00385 static VOID
00386 MainWndCommand(PMAIN_WND_INFO Info,
00387                WORD CmdId,
00388                HWND hControl)
00389 {
00390     UNREFERENCED_PARAMETER(hControl);
00391 
00392     switch (CmdId)
00393     {
00394         case ID_PROP:
00395         {
00396             if (Info->SelectedItem != NO_ITEM_SELECTED)
00397             {
00398                 Info->bDlgOpen = TRUE;
00399                 OpenPropSheet(Info);
00400                 Info->bDlgOpen = FALSE;
00401                 SetMenuAndButtonStates(Info);
00402             }
00403         }
00404         break;
00405 
00406         case ID_REFRESH:
00407         {
00408             RefreshServiceList(Info);
00409             Info->SelectedItem = NO_ITEM_SELECTED;
00410 
00411             /* disable menus and buttons */
00412             SetMenuAndButtonStates(Info);
00413 
00414             /* clear the service in the status bar */
00415             SendMessage(Info->hStatus,
00416                         SB_SETTEXT,
00417                         1,
00418                         _T('\0'));
00419         }
00420         break;
00421 
00422         case ID_EXPORT:
00423         {
00424             ExportFile(Info);
00425             SetFocus(Info->hListView);
00426         }
00427         break;
00428 
00429         case ID_CREATE:
00430         {
00431             INT ret;
00432 
00433             ret = DialogBoxParam(hInstance,
00434                                  MAKEINTRESOURCE(IDD_DLG_CREATE),
00435                                  Info->hMainWnd,
00436                                  CreateDialogProc,
00437                                  (LPARAM)Info);
00438             if (ret == IDOK)
00439                 RefreshServiceList(Info);
00440 
00441             SetFocus(Info->hListView);
00442         }
00443         break;
00444 
00445         case ID_DELETE:
00446         {
00447             if (Info->pCurrentService->ServiceStatusProcess.dwCurrentState != SERVICE_RUNNING)
00448             {
00449                 DialogBoxParam(hInstance,
00450                                MAKEINTRESOURCE(IDD_DLG_DELETE),
00451                                Info->hMainWnd,
00452                                DeleteDialogProc,
00453                                (LPARAM)Info);
00454             }
00455             else
00456             {
00457                 TCHAR Buf[60];
00458                 LoadString(hInstance,
00459                            IDS_DELETE_STOP,
00460                            Buf,
00461                            sizeof(Buf) / sizeof(TCHAR));
00462                 DisplayString(Buf);
00463             }
00464 
00465             SetFocus(Info->hListView);
00466 
00467         }
00468         break;
00469 
00470         case ID_START:
00471         {
00472             if (DoStart(Info, NULL))
00473             {
00474                 UpdateServiceStatus(Info->pCurrentService);
00475                 ChangeListViewText(Info, Info->pCurrentService, LVSTATUS);
00476                 SetMenuAndButtonStates(Info);
00477                 SetFocus(Info->hListView);
00478             }
00479         }
00480         break;
00481 
00482         case ID_STOP:
00483             if (DoStop(Info))
00484             {
00485                 UpdateServiceStatus(Info->pCurrentService);
00486                 ChangeListViewText(Info, Info->pCurrentService, LVSTATUS);
00487                 SetMenuAndButtonStates(Info);
00488                 SetFocus(Info->hListView);
00489             }
00490         break;
00491 
00492         case ID_PAUSE:
00493             DoPause(Info);
00494         break;
00495 
00496         case ID_RESUME:
00497             DoResume(Info);
00498         break;
00499 
00500         case ID_RESTART:
00501             if (DoStop(Info))
00502             {
00503                 DoStart(Info, NULL);
00504                 UpdateServiceStatus(Info->pCurrentService);
00505                 ChangeListViewText(Info, Info->pCurrentService, LVSTATUS);
00506                 SetMenuAndButtonStates(Info);
00507                 SetFocus(Info->hListView);
00508             }
00509         break;
00510 
00511         case ID_HELP:
00512             MessageBox(NULL,
00513                        _T("Help is not yet implemented\n"),
00514                        _T("Note!"),
00515                        MB_OK | MB_ICONINFORMATION);
00516             SetFocus(Info->hListView);
00517         break;
00518 
00519         case ID_EXIT:
00520             PostMessage(Info->hMainWnd,
00521                         WM_CLOSE,
00522                         0,
00523                         0);
00524         break;
00525 
00526         case ID_VIEW_LARGE:
00527             SetListViewStyle(Info->hListView,
00528                              LVS_ICON);
00529             CheckMenuRadioItem(GetMenu(Info->hMainWnd),
00530                                ID_VIEW_LARGE,
00531                                ID_VIEW_DETAILS,
00532                                ID_VIEW_LARGE,
00533                                MF_BYCOMMAND);
00534         break;
00535 
00536         case ID_VIEW_SMALL:
00537             SetListViewStyle(Info->hListView,
00538                              LVS_SMALLICON);
00539             CheckMenuRadioItem(GetMenu(Info->hMainWnd),
00540                                ID_VIEW_LARGE,
00541                                ID_VIEW_DETAILS,
00542                                ID_VIEW_SMALL,
00543                                MF_BYCOMMAND);
00544         break;
00545 
00546         case ID_VIEW_LIST:
00547             SetListViewStyle(Info->hListView,
00548                              LVS_LIST);
00549             CheckMenuRadioItem(GetMenu(Info->hMainWnd),
00550                                ID_VIEW_LARGE,
00551                                ID_VIEW_DETAILS,
00552                                ID_VIEW_LIST,
00553                                MF_BYCOMMAND);
00554         break;
00555 
00556         case ID_VIEW_DETAILS:
00557             SetListViewStyle(Info->hListView,
00558                              LVS_REPORT);
00559             CheckMenuRadioItem(GetMenu(Info->hMainWnd),
00560                                ID_VIEW_LARGE,
00561                                ID_VIEW_DETAILS,
00562                                ID_VIEW_DETAILS,
00563                                MF_BYCOMMAND);
00564         break;
00565 
00566         case ID_VIEW_CUST:
00567         break;
00568 
00569         case ID_ABOUT:
00570             DialogBox(hInstance,
00571                       MAKEINTRESOURCE(IDD_ABOUTBOX),
00572                       Info->hMainWnd,
00573                       AboutDialogProc);
00574             SetFocus(Info->hListView);
00575         break;
00576 
00577     }
00578 }
00579 
00580 
00581 static VOID CALLBACK
00582 MainWndResize(PMAIN_WND_INFO Info,
00583               WORD cx,
00584               WORD cy)
00585 {
00586     RECT rcClient, rcTool, rcStatus;
00587     int lvHeight, iToolHeight, iStatusHeight;
00588 
00589     /* Size toolbar and get height */
00590     SendMessage(Info->hTool, TB_AUTOSIZE, 0, 0);
00591     GetWindowRect(Info->hTool, &rcTool);
00592     iToolHeight = rcTool.bottom - rcTool.top;
00593 
00594     /* Size status bar and get height */
00595     SendMessage(Info->hStatus, WM_SIZE, 0, 0);
00596     GetWindowRect(Info->hStatus, &rcStatus);
00597     iStatusHeight = rcStatus.bottom - rcStatus.top;
00598 
00599     /* Calculate remaining height and size list view */
00600     GetClientRect(Info->hMainWnd, &rcClient);
00601     lvHeight = rcClient.bottom - iToolHeight - iStatusHeight;
00602     SetWindowPos(Info->hListView,
00603                  NULL,
00604                  0,
00605                  iToolHeight,
00606                  rcClient.right,
00607                  lvHeight,
00608                  SWP_NOZORDER);
00609 }
00610 
00611 
00612 static LRESULT CALLBACK
00613 MainWndProc(HWND hwnd,
00614             UINT msg,
00615             WPARAM wParam,
00616             LPARAM lParam)
00617 {
00618     PMAIN_WND_INFO Info;
00619     LRESULT Ret = 0;
00620 
00621     /* Get the window context */
00622     Info = (PMAIN_WND_INFO)GetWindowLongPtr(hwnd,
00623                                             GWLP_USERDATA);
00624     if (Info == NULL && msg != WM_CREATE)
00625     {
00626         goto HandleDefaultMessage;
00627     }
00628 
00629     switch(msg)
00630     {
00631         case WM_CREATE:
00632         {
00633             Info = (PMAIN_WND_INFO)(((LPCREATESTRUCT)lParam)->lpCreateParams);
00634 
00635             /* Initialize the main window context */
00636             Info->hMainWnd = hwnd;
00637             Info->SelectedItem = NO_ITEM_SELECTED;
00638 
00639             SetWindowLongPtr(hwnd,
00640                              GWLP_USERDATA,
00641                              (LONG_PTR)Info);
00642 
00643             if (!InitMainWnd(Info))
00644                 return -1;
00645 
00646             /* Fill the list-view before showing the main window */
00647             RefreshServiceList(Info);
00648 
00649             /* Show the window */
00650             ShowWindow(hwnd,
00651                        Info->nCmdShow);
00652 
00653             SetFocus(Info->hListView);
00654         }
00655         break;
00656 
00657         case WM_SIZE:
00658         {
00659             MainWndResize(Info,
00660                           LOWORD(lParam),
00661                           HIWORD(lParam));
00662         }
00663         break;
00664 
00665         case WM_NOTIFY:
00666         {
00667             LPNMHDR pnmhdr = (LPNMHDR)lParam;
00668 
00669             switch (pnmhdr->code)
00670             {
00671                 case NM_DBLCLK:
00672                 {
00673                     POINT pt;
00674                     RECT rect;
00675 
00676                     GetCursorPos(&pt);
00677                     GetWindowRect(Info->hListView, &rect);
00678 
00679                     if (PtInRect(&rect, pt))
00680                     {
00681                         SendMessage(hwnd,
00682                                     WM_COMMAND,
00683                                     //ID_PROP,
00684                                     MAKEWPARAM((WORD)ID_PROP, (WORD)0),
00685                                     0);
00686                     }
00687 
00688                     //OpenPropSheet(Info);
00689                 }
00690                 break;
00691 
00692                 case NM_RETURN:
00693                 {
00694                     SendMessage(hwnd,
00695                                 WM_COMMAND,
00696                                 //ID_PROP,
00697                                 MAKEWPARAM((WORD)ID_PROP, (WORD)0),
00698                                 0);
00699                 }
00700                 break;
00701 
00702                 case LVN_COLUMNCLICK:
00703                 {
00704                     LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
00705 
00706                     (void)ListView_SortItems(Info->hListView,
00707                                              CompareFunc,
00708                                              pnmv->iSubItem);
00709                     bSortAscending = !bSortAscending;
00710                 }
00711                 break;
00712 
00713                 case LVN_ITEMCHANGED:
00714                 {
00715                     LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
00716 
00717                     if (pnmv->uNewState != 0)
00718                     {
00719                         ListViewSelectionChanged(Info, pnmv);
00720                         SetMenuAndButtonStates(Info);
00721                     }
00722                 }
00723                 break;
00724 
00725                 case TTN_GETDISPINFO:
00726                 {
00727                     LPTOOLTIPTEXT lpttt;
00728                     UINT idButton;
00729 
00730                     lpttt = (LPTOOLTIPTEXT)lParam;
00731 
00732                     /* Specify the resource identifier of the descriptive
00733                      * text for the given button. */
00734                     idButton = (UINT)lpttt->hdr.idFrom;
00735                     switch (idButton)
00736                     {
00737                         case ID_PROP:
00738                             lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_PROP);
00739                         break;
00740 
00741                         case ID_REFRESH:
00742                             lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_REFRESH);
00743                         break;
00744 
00745                         case ID_EXPORT:
00746                             lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_EXPORT);
00747                         break;
00748 
00749                         case ID_CREATE:
00750                             lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_CREATE);
00751                         break;
00752 
00753                         case ID_DELETE:
00754                             lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_DELETE);
00755                         break;
00756 
00757                         case ID_START:
00758                             lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_START);
00759                         break;
00760 
00761                         case ID_STOP:
00762                             lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_STOP);
00763                         break;
00764 
00765                         case ID_PAUSE:
00766                             lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_PAUSE);
00767                         break;
00768 
00769                         case ID_RESTART:
00770                             lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_RESTART);
00771                         break;
00772                     }
00773                 }
00774                 break;
00775             }
00776         }
00777         break;
00778 
00779         case WM_CONTEXTMENU:
00780             {
00781                 POINT pt;
00782                 RECT lvRect;
00783 
00784                 INT xPos = GET_X_LPARAM(lParam);
00785                 INT yPos = GET_Y_LPARAM(lParam);
00786 
00787                 GetCursorPos(&pt);
00788 
00789                 /* display popup when cursor is in the list view */
00790                 GetWindowRect(Info->hListView, &lvRect);
00791                 if (PtInRect(&lvRect, pt))
00792                 {
00793                     TrackPopupMenuEx(GetSubMenu(Info->hShortcutMenu, 0),
00794                                      TPM_RIGHTBUTTON,
00795                                      xPos,
00796                                      yPos,
00797                                      Info->hMainWnd,
00798                                      NULL);
00799                 }
00800             }
00801         break;
00802 
00803         case WM_COMMAND:
00804         {
00805             MainWndCommand(Info,
00806                            LOWORD(wParam),
00807                            (HWND)lParam);
00808             goto HandleDefaultMessage;
00809         }
00810 
00811         case WM_MENUSELECT:
00812         {
00813             if (Info->hStatus != NULL)
00814             {
00815                 if (!MainWndMenuHint(Info,
00816                                      LOWORD(wParam),
00817                                      MainMenuHintTable,
00818                                      sizeof(MainMenuHintTable) / sizeof(MainMenuHintTable[0]),
00819                                      IDS_HINT_BLANK))
00820                 {
00821                     MainWndMenuHint(Info,
00822                                     LOWORD(wParam),
00823                                     SystemMenuHintTable,
00824                                     sizeof(SystemMenuHintTable) / sizeof(SystemMenuHintTable[0]),
00825                                     IDS_HINT_BLANK);
00826                 }
00827             }
00828         }
00829         break;
00830 
00831         case WM_ENTERMENULOOP:
00832         {
00833             Info->bInMenuLoop = TRUE;
00834             UpdateMainStatusBar(Info);
00835             break;
00836         }
00837 
00838         case WM_EXITMENULOOP:
00839         {
00840             Info->bInMenuLoop = FALSE;
00841             UpdateMainStatusBar(Info);
00842             break;
00843         }
00844 
00845         case WM_CLOSE:
00846         {
00847             HeapFree(ProcessHeap,
00848                      0,
00849                      Info->pAllServices);
00850 
00851             DestroyMenu(Info->hShortcutMenu);
00852             DestroyWindow(hwnd);
00853         }
00854         break;
00855 
00856         case WM_DESTROY:
00857         {
00858             HeapFree(ProcessHeap,
00859                      0,
00860                      Info);
00861             SetWindowLongPtr(hwnd,
00862                              GWLP_USERDATA,
00863                              0);
00864 
00865             PostQuitMessage(0);
00866         }
00867         break;
00868 
00869         default:
00870         {
00871 HandleDefaultMessage:
00872 
00873             Ret = DefWindowProc(hwnd,
00874                                 msg,
00875                                 wParam,
00876                                 lParam);
00877         }
00878         break;
00879     }
00880 
00881     return Ret;
00882 }
00883 
00884 
00885 
00886 HWND
00887 CreateMainWindow(LPCTSTR lpCaption,
00888                  int nCmdShow)
00889 {
00890     PMAIN_WND_INFO Info;
00891     HWND hMainWnd = NULL;
00892 
00893     Info = (MAIN_WND_INFO*) HeapAlloc(ProcessHeap,
00894                      HEAP_ZERO_MEMORY,
00895                      sizeof(MAIN_WND_INFO));
00896 
00897     if (Info != NULL)
00898     {
00899         Info->nCmdShow = nCmdShow;
00900 
00901         hMainWnd = CreateWindowEx(WS_EX_WINDOWEDGE,
00902                                   szMainWndClass,
00903                                   lpCaption,
00904                                   WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
00905                                   CW_USEDEFAULT,
00906                                   CW_USEDEFAULT,
00907                                   680,
00908                                   450,
00909                                   NULL,
00910                                   NULL,
00911                                   hInstance,
00912                                   Info);
00913         if (hMainWnd == NULL)
00914         {
00915             //int ret;
00916             //ret = GetLastError();
00917             GetError();
00918             HeapFree(ProcessHeap,
00919                      0,
00920                      Info);
00921         }
00922     }
00923 
00924     return hMainWnd;
00925 }
00926 
00927 BOOL
00928 InitMainWindowImpl(VOID)
00929 {
00930     WNDCLASSEX wc = {0};
00931 
00932     wc.cbSize = sizeof(WNDCLASSEX);
00933     wc.lpfnWndProc = MainWndProc;
00934     wc.hInstance = hInstance;
00935     wc.hIcon = LoadIcon(hInstance,
00936                         MAKEINTRESOURCE(IDI_SM_ICON));
00937     wc.hCursor = LoadCursor(NULL,
00938                             IDC_ARROW);
00939     wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
00940     wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU);
00941     wc.lpszClassName = szMainWndClass;
00942     wc.hIconSm = (HICON)LoadImage(hInstance,
00943                                   MAKEINTRESOURCE(IDI_SM_ICON),
00944                                   IMAGE_ICON,
00945                                   16,
00946                                   16,
00947                                   LR_SHARED);
00948 
00949     return RegisterClassEx(&wc) != (ATOM)0;
00950 }
00951 
00952 
00953 VOID
00954 UninitMainWindowImpl(VOID)
00955 {
00956     UnregisterClass(szMainWndClass,
00957                     hInstance);
00958 }

Generated on Mon May 28 2012 04:16:54 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.