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 Device Managment
00003  * LICENSE:     GPL - See COPYING in the top level directory
00004  * FILE:        base/system/devmgmt/mainwnd.c
00005  * PURPOSE:     Main window message handler
00006  * COPYRIGHT:   Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
00007  *
00008  */
00009 
00010 #include "precomp.h"
00011 
00012 static BOOL pCreateToolbar(PMAIN_WND_INFO Info);
00013 
00014 static const TCHAR szMainWndClass[] = TEXT("DevMgmtWndClass");
00015 
00016 
00017 /* Toolbar buttons */
00018 TBBUTTON Buttons [] =
00019 {   /* iBitmap, idCommand, fsState, fsStyle, bReserved[2], dwData, iString */
00020     {TBICON_PROP,    IDC_PROP,    TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0},   /* properties */
00021     {TBICON_REFRESH, IDC_REFRESH, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},   /* refresh */
00022 
00023     /* Note: First item for a seperator is its width in pixels */
00024     {15, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0},                           /* separator */
00025 
00026     {TBICON_HELP,    IDC_PROGHELP,TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 },  /* help */
00027     {TBICON_EXIT,    IDC_EXIT,    TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 },  /* exit */
00028 
00029 };
00030 
00031 
00032 /* menu hints */
00033 static const MENU_HINT MainMenuHintTable[] = {
00034     /* File Menu */
00035     {IDC_EXIT,     IDS_HINT_EXIT},
00036 
00037     /* Action Menu */
00038     {IDC_REFRESH,  IDS_HINT_REFRESH},
00039     {IDC_PROP,     IDS_HINT_PROP},
00040 
00041     /* Help Menu */
00042     {IDC_PROGHELP, IDS_HINT_HELP},
00043     {IDC_ABOUT,    IDS_HINT_ABOUT}
00044 };
00045 
00046 /* system menu hints */
00047 static const MENU_HINT SystemMenuHintTable[] = {
00048     {SC_RESTORE,    IDS_HINT_SYS_RESTORE},
00049     {SC_MOVE,       IDS_HINT_SYS_MOVE},
00050     {SC_SIZE,       IDS_HINT_SYS_SIZE},
00051     {SC_MINIMIZE,   IDS_HINT_SYS_MINIMIZE},
00052     {SC_MAXIMIZE,   IDS_HINT_SYS_MAXIMIZE},
00053     {SC_CLOSE,      IDS_HINT_SYS_CLOSE},
00054 };
00055 
00056 
00057 static BOOL
00058 MainWndMenuHint(PMAIN_WND_INFO Info,
00059                 WORD CmdId,
00060                 const MENU_HINT *HintArray,
00061                 DWORD HintsCount,
00062                 UINT DefHintId)
00063 {
00064     BOOL Found = FALSE;
00065     const MENU_HINT *LastHint;
00066     UINT HintId = DefHintId;
00067 
00068     LastHint = HintArray + HintsCount;
00069     while (HintArray != LastHint)
00070     {
00071         if (HintArray->CmdId == CmdId)
00072         {
00073             HintId = HintArray->HintId;
00074             Found = TRUE;
00075             break;
00076         }
00077         HintArray++;
00078     }
00079 
00080     StatusBarLoadString(Info->hStatus,
00081                         SB_SIMPLEID,
00082                         hInstance,
00083                         HintId);
00084 
00085     return Found;
00086 }
00087 
00088 
00089 static VOID
00090 UpdateMainStatusBar(PMAIN_WND_INFO Info)
00091 {
00092     if (Info->hStatus != NULL)
00093     {
00094         SendMessage(Info->hStatus,
00095                     SB_SIMPLE,
00096                     (WPARAM)Info->InMenuLoop,
00097                     0);
00098     }
00099 }
00100 
00101 
00102 static BOOL
00103 pCreateToolbar(PMAIN_WND_INFO Info)
00104 {
00105     INT NumButtons = sizeof(Buttons) / sizeof(Buttons[0]);
00106 
00107     Info->hTool = CreateWindowEx(0,
00108                                  TOOLBARCLASSNAME,
00109                                  NULL,
00110                                  WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS,
00111                                  0, 0, 0, 0,
00112                                  Info->hMainWnd,
00113                                  (HMENU)IDC_TOOLBAR,
00114                                  hInstance,
00115                                  NULL);
00116     if(Info->hTool != NULL)
00117     {
00118         HIMAGELIST hImageList;
00119 
00120         SendMessage(Info->hTool,
00121                     TB_SETEXTENDEDSTYLE,
00122                     0,
00123                     TBSTYLE_EX_HIDECLIPPEDBUTTONS);
00124 
00125         SendMessage(Info->hTool,
00126                     TB_BUTTONSTRUCTSIZE,
00127                     sizeof(Buttons[0]),
00128                     0);
00129 
00130         hImageList = InitImageList(IDB_PROP,
00131                                    IDB_EXIT,
00132                                    16,
00133                                    16);
00134         if (hImageList == NULL)
00135             return FALSE;
00136 
00137         ImageList_Destroy((HIMAGELIST)SendMessage(Info->hTool,
00138                                                   TB_SETIMAGELIST,
00139                                                   0,
00140                                                   (LPARAM)hImageList));
00141 
00142         SendMessage(Info->hTool,
00143                     TB_ADDBUTTONS,
00144                     NumButtons,
00145                     (LPARAM)Buttons);
00146 
00147         return TRUE;
00148     }
00149 
00150     return FALSE;
00151 }
00152 
00153 
00154 static BOOL
00155 CreateTreeView(PMAIN_WND_INFO Info)
00156 {
00157     Info->hTreeView = CreateWindowEx(WS_EX_CLIENTEDGE,
00158                                      WC_TREEVIEW,
00159                                      NULL,
00160                                      WS_CHILD | WS_VISIBLE | WS_BORDER | TVS_HASLINES |
00161                                       TVS_HASBUTTONS | TVS_SHOWSELALWAYS | TVS_LINESATROOT,
00162                                      0, 0, 0, 0,
00163                                      Info->hMainWnd,
00164                                      (HMENU)IDC_TREEVIEW,
00165                                      hInstance,
00166                                      NULL);
00167     if (Info->hTreeView == NULL)
00168     {
00169         DisplayString(_T("Could not create TreeView."));
00170         return FALSE;
00171     }
00172 
00173     return TRUE;
00174 }
00175 
00176 static BOOL
00177 CreateStatusBar(PMAIN_WND_INFO Info)
00178 {
00179     INT StatWidths[] = {110, -1}; /* widths of status bar */
00180 
00181     Info->hStatus = CreateWindowEx(0,
00182                                    STATUSCLASSNAME,
00183                                    NULL,
00184                                    WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,
00185                                    0, 0, 0, 0,
00186                                    Info->hMainWnd,
00187                                    (HMENU)IDC_STATUSBAR,
00188                                    hInstance,
00189                                    NULL);
00190     if(Info->hStatus == NULL)
00191         return FALSE;
00192 
00193 
00194     SendMessage(Info->hStatus,
00195                 SB_SETPARTS,
00196                 sizeof(StatWidths) / sizeof(INT),
00197                 (LPARAM)StatWidths);
00198 
00199     return TRUE;
00200 }
00201 
00202 
00203 static DWORD WINAPI
00204 DeviceEnumThread(LPVOID lpParameter)
00205 {
00206     PMAIN_WND_INFO Info;
00207     HTREEITEM hRoot;
00208 
00209     Info = (PMAIN_WND_INFO)lpParameter;
00210 
00211     if (Info->hTreeView)
00212         FreeDeviceStrings(Info->hTreeView);
00213 
00214     hRoot = InitTreeView(Info->hTreeView);
00215     if (hRoot)
00216     {
00217         switch (Info->Display)
00218         {
00219             case DevicesByType:
00220                 ListDevicesByType(Info->hTreeView, hRoot, Info->bShowHidden);
00221                 break;
00222 
00223             case DevicesByConnection:
00224                 ListDevicesByConnection(Info->hTreeView, hRoot, Info->bShowHidden);
00225                 break;
00226 
00227             default:
00228                 break;
00229         }
00230         return 0;
00231     }
00232 
00233     return -1;
00234 }
00235 
00236 
00237 static VOID
00238 UpdateViewMenu(PMAIN_WND_INFO Info)
00239 {
00240     UINT id = IDC_DEVBYTYPE;
00241     HMENU hMenu;
00242 
00243     hMenu = GetMenu(Info->hMainWnd);
00244 
00245     switch (Info->Display)
00246     {
00247         case DevicesByType:
00248             id = IDC_DEVBYTYPE;
00249             break;
00250         case DevicesByConnection:
00251             id = IDC_DEVBYCONN;
00252             break;
00253         case RessourcesByType:
00254             id = IDC_RESBYTYPE;
00255             break;
00256         case RessourcesByConnection:
00257             id = IDC_RESBYCONN;
00258             break;
00259     }
00260 
00261     CheckMenuRadioItem(hMenu,
00262                        IDC_DEVBYTYPE,
00263                        IDC_RESBYCONN,
00264                        id,
00265                        MF_BYCOMMAND);
00266 
00267     CheckMenuItem(hMenu,
00268                   IDC_SHOWHIDDEN,
00269                   MF_BYCOMMAND | (Info->bShowHidden) ? MF_CHECKED : MF_UNCHECKED);
00270 }
00271 
00272 
00273 static BOOL
00274 InitMainWnd(PMAIN_WND_INFO Info)
00275 {
00276     HANDLE DevEnumThread;
00277     HMENU hMenu;
00278 
00279     if (!pCreateToolbar(Info))
00280         DisplayString(_T("error creating toolbar"));
00281 
00282     if (!CreateTreeView(Info))
00283     {
00284         DisplayString(_T("error creating list view"));
00285         return FALSE;
00286     }
00287 
00288     if (!CreateStatusBar(Info))
00289         DisplayString(_T("error creating status bar"));
00290 
00291     UpdateViewMenu(Info);
00292 
00293     /* make 'properties' bold */
00294     hMenu = GetMenu(Info->hMainWnd);
00295     hMenu = GetSubMenu(hMenu, 1);
00296     SetMenuDefaultItem(hMenu, IDC_PROP, FALSE);
00297 
00298     /* Create Popup Menu */
00299     Info->hShortcutMenu = LoadMenu(hInstance,
00300                                    MAKEINTRESOURCE(IDR_POPUP));
00301     Info->hShortcutMenu = GetSubMenu(Info->hShortcutMenu,
00302                                      0);
00303     SetMenuDefaultItem(Info->hShortcutMenu, IDC_PROP, FALSE);
00304 
00305     /* create seperate thread to emum devices */
00306     DevEnumThread = CreateThread(NULL,
00307                                  0,
00308                                  DeviceEnumThread,
00309                                  Info,
00310                                  0,
00311                                  NULL);
00312     if (!DevEnumThread)
00313     {
00314         DisplayString(_T("Failed to enumerate devices"));
00315         return FALSE;
00316     }
00317 
00318     CloseHandle(DevEnumThread);
00319     return TRUE;
00320 }
00321 
00322 
00323 static VOID
00324 OnContext(PMAIN_WND_INFO Info,
00325           LPARAM lParam)
00326 {
00327     HTREEITEM hSelected;
00328     POINT pt;
00329     RECT rc;
00330 
00331     INT xPos = GET_X_LPARAM(lParam);
00332     INT yPos = GET_Y_LPARAM(lParam);
00333 
00334     hSelected = TreeView_GetSelection(Info->hTreeView);
00335 
00336     if (TreeView_GetItemRect(Info->hTreeView,
00337                          hSelected,
00338                          &rc,
00339                          TRUE))
00340     {
00341         if (GetCursorPos(&pt) &&
00342             ScreenToClient(Info->hTreeView, &pt) &&
00343             PtInRect(&rc, pt))
00344         {
00345             TrackPopupMenuEx(Info->hShortcutMenu,
00346                              TPM_RIGHTBUTTON,
00347                              xPos,
00348                              yPos,
00349                              Info->hMainWnd,
00350                              NULL);
00351         }
00352     }
00353 }
00354 
00355 
00356 static LRESULT
00357 OnNotify(PMAIN_WND_INFO Info,
00358          LPARAM lParam)
00359 {
00360     LPNMHDR pnmhdr = (LPNMHDR)lParam;
00361     LRESULT ret = 0;
00362 
00363     switch (pnmhdr->code)
00364     {
00365         case TVN_SELCHANGED:
00366         {
00367             LPNM_TREEVIEW pnmtv = (LPNM_TREEVIEW)lParam;
00368 
00369             if (Info->Display == DevicesByType)
00370             {
00371                 if (!TreeView_GetChild(Info->hTreeView,
00372                                        pnmtv->itemNew.hItem))
00373                 {
00374                     SendMessage(Info->hTool,
00375                                 TB_SETSTATE,
00376                                 IDC_PROP,
00377                                 (LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
00378 
00379                     EnableMenuItem(GetMenu(Info->hMainWnd), IDC_PROP, MF_ENABLED);
00380                     EnableMenuItem(Info->hShortcutMenu, IDC_PROP, MF_ENABLED);
00381                 }
00382                 else
00383                 {
00384                     SendMessage(Info->hTool,
00385                                 TB_SETSTATE,
00386                                 IDC_PROP,
00387                                 (LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
00388 
00389                     EnableMenuItem(GetMenu(Info->hMainWnd), IDC_PROP, MF_GRAYED);
00390                     EnableMenuItem(Info->hShortcutMenu, IDC_PROP, MF_GRAYED);
00391                 }
00392             }
00393             else if (Info->Display == DevicesByConnection)
00394             {
00395                 if (pnmtv->itemNew.hItem == TreeView_GetRoot(Info->hTreeView))
00396                 {
00397                     SendMessage(Info->hTool,
00398                                 TB_SETSTATE,
00399                                 IDC_PROP,
00400                                 (LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
00401 
00402                     EnableMenuItem(GetMenu(Info->hMainWnd), IDC_PROP, MF_GRAYED);
00403                     EnableMenuItem(Info->hShortcutMenu, IDC_PROP, MF_GRAYED);
00404                 }
00405                 else
00406                 {
00407                     SendMessage(Info->hTool,
00408                                 TB_SETSTATE,
00409                                 IDC_PROP,
00410                                 (LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
00411 
00412                     EnableMenuItem(GetMenu(Info->hMainWnd), IDC_PROP, MF_ENABLED);
00413                     EnableMenuItem(Info->hShortcutMenu, IDC_PROP, MF_ENABLED);
00414                 }
00415             }
00416         }
00417         break;
00418 
00419         case NM_DBLCLK:
00420         {
00421             HTREEITEM hSelected = TreeView_GetSelection(Info->hTreeView);
00422             TV_HITTESTINFO HitTest;
00423 
00424             if (Info->Display == DevicesByType)
00425             {
00426                 if (!TreeView_GetChild(Info->hTreeView,
00427                                        hSelected))
00428                 {
00429                     if (GetCursorPos(&HitTest.pt) &&
00430                         ScreenToClient(Info->hTreeView, &HitTest.pt))
00431                     {
00432                         if (TreeView_HitTest(Info->hTreeView, &HitTest))
00433                         {
00434                             if (HitTest.hItem == hSelected)
00435                             {
00436                                 OpenPropSheet(Info->hTreeView,
00437                                               hSelected);
00438                                 ret = TRUE;
00439                             }
00440                         }
00441                     }
00442                 }
00443             }
00444             else if (Info->Display == DevicesByConnection)
00445             {
00446                 if (hSelected != TreeView_GetRoot(Info->hTreeView))
00447                 {
00448                     if (GetCursorPos(&HitTest.pt) &&
00449                         ScreenToClient(Info->hTreeView, &HitTest.pt))
00450                     {
00451                         if (TreeView_HitTest(Info->hTreeView, &HitTest))
00452                         {
00453                             if (HitTest.hItem == hSelected)
00454                             {
00455                                 OpenPropSheet(Info->hTreeView,
00456                                               hSelected);
00457                                 ret = TRUE;
00458                             }
00459                         }
00460                     }
00461                 }
00462             }
00463         }
00464         break;
00465 
00466         case NM_RCLICK:
00467         {
00468             TV_HITTESTINFO HitTest;
00469 
00470             if (GetCursorPos(&HitTest.pt) &&
00471                 ScreenToClient(Info->hTreeView, &HitTest.pt))
00472             {
00473                 if (TreeView_HitTest(Info->hTreeView, &HitTest))
00474                     (void)TreeView_SelectItem(Info->hTreeView, HitTest.hItem);
00475             }
00476         }
00477         break;
00478 
00479         case TTN_GETDISPINFO:
00480         {
00481             LPTOOLTIPTEXT lpttt;
00482             UINT idButton;
00483 
00484             lpttt = (LPTOOLTIPTEXT)lParam;
00485 
00486             idButton = (UINT)lpttt->hdr.idFrom;
00487             switch (idButton)
00488             {
00489                 case IDC_PROP:
00490                     lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_PROP);
00491                 break;
00492 
00493                 case IDC_REFRESH:
00494                     lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_REFRESH);
00495                 break;
00496 
00497                 case IDC_PROGHELP:
00498                     lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_HELP);
00499                 break;
00500 
00501                 case IDC_EXIT:
00502                     lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_EXIT);
00503                 break;
00504             }
00505         }
00506         break;
00507     }
00508 
00509     return ret;
00510 }
00511 
00512 
00513 static VOID
00514 OnRefresh(PMAIN_WND_INFO Info)
00515 {
00516     HANDLE DevEnumThread;
00517 
00518     SendMessage(Info->hTool,
00519                 TB_SETSTATE,
00520                 IDC_PROP,
00521                 (LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
00522 
00523     EnableMenuItem(GetMenu(Info->hMainWnd), IDC_PROP, MF_GRAYED);
00524     EnableMenuItem(Info->hShortcutMenu, IDC_PROP, MF_GRAYED);
00525 
00526     /* create seperate thread to emum devices */
00527     DevEnumThread = CreateThread(NULL,
00528                                  0,
00529                                  DeviceEnumThread,
00530                                  Info,
00531                                  0,
00532                                  NULL);
00533     if (!DevEnumThread)
00534     {
00535         DisplayString(_T("Failed to enumerate devices"));
00536         return;
00537     }
00538 
00539     CloseHandle(DevEnumThread);
00540 }
00541 
00542 
00543 static VOID
00544 MainWndCommand(PMAIN_WND_INFO Info,
00545                WORD CmdId,
00546                HWND hControl)
00547 {
00548     UNREFERENCED_PARAMETER(hControl);
00549 
00550     switch (CmdId)
00551     {
00552         case IDC_PROP:
00553         {
00554             HTREEITEM hSelected = TreeView_GetSelection(Info->hTreeView);
00555             OpenPropSheet(Info->hTreeView,
00556                           hSelected);
00557         }
00558         break;
00559 
00560         case IDC_REFRESH:
00561         {
00562             OnRefresh(Info);
00563         }
00564         break;
00565 
00566         case IDC_PROGHELP:
00567         {
00568             DisplayString(_T("Help is not yet implemented\n"));
00569             SetFocus(Info->hTreeView);
00570         }
00571         break;
00572 
00573         case IDC_EXIT:
00574         {
00575             PostMessage(Info->hMainWnd,
00576                         WM_CLOSE,
00577                         0,
00578                         0);
00579         }
00580         break;
00581 
00582         case IDC_ABOUT:
00583         {
00584             DialogBox(hInstance,
00585                       MAKEINTRESOURCE(IDD_ABOUTBOX),
00586                       Info->hMainWnd,
00587                       AboutDialogProc);
00588 
00589             SetFocus(Info->hTreeView);
00590         }
00591         break;
00592 
00593         case IDC_DEVBYTYPE:
00594         {
00595             Info->Display = DevicesByType;
00596             UpdateViewMenu(Info);
00597             OnRefresh(Info);
00598         }
00599         break;
00600 
00601         case IDC_DEVBYCONN:
00602         {
00603             Info->Display = DevicesByConnection;
00604             UpdateViewMenu(Info);
00605             OnRefresh(Info);
00606         }
00607         break;
00608 
00609         case IDC_SHOWHIDDEN:
00610         {
00611             Info->bShowHidden = !Info->bShowHidden;
00612             UpdateViewMenu(Info);
00613             OnRefresh(Info);
00614         }
00615         break;
00616     }
00617 }
00618 
00619 
00620 static VOID CALLBACK
00621 MainWndResize(PMAIN_WND_INFO Info,
00622               WORD cx,
00623               WORD cy)
00624 {
00625     RECT rcClient, rcTool, rcStatus;
00626     int lvHeight, iToolHeight, iStatusHeight;
00627 
00628     /* Size toolbar and get height */
00629     SendMessage(Info->hTool, TB_AUTOSIZE, 0, 0);
00630     GetWindowRect(Info->hTool, &rcTool);
00631     iToolHeight = rcTool.bottom - rcTool.top;
00632 
00633     /* Size status bar and get height */
00634     SendMessage(Info->hStatus, WM_SIZE, 0, 0);
00635     GetWindowRect(Info->hStatus, &rcStatus);
00636     iStatusHeight = rcStatus.bottom - rcStatus.top;
00637 
00638     /* Calculate remaining height and size list view */
00639     GetClientRect(Info->hMainWnd, &rcClient);
00640     lvHeight = rcClient.bottom - iToolHeight - iStatusHeight;
00641     SetWindowPos(Info->hTreeView,
00642                  NULL,
00643                  0,
00644                  iToolHeight,
00645                  rcClient.right,
00646                  lvHeight,
00647                  SWP_NOZORDER);
00648 }
00649 
00650 
00651 static LRESULT CALLBACK
00652 MainWndProc(HWND hwnd,
00653             UINT msg,
00654             WPARAM wParam,
00655             LPARAM lParam)
00656 {
00657     PMAIN_WND_INFO Info;
00658     LRESULT Ret = 0;
00659 
00660     /* Get the window context */
00661     Info = (PMAIN_WND_INFO)GetWindowLongPtr(hwnd,
00662                                             GWLP_USERDATA);
00663     if (Info == NULL && msg != WM_CREATE)
00664     {
00665         goto HandleDefaultMessage;
00666     }
00667 
00668     switch(msg)
00669     {
00670         case WM_CREATE:
00671         {
00672             Info = (PMAIN_WND_INFO)(((LPCREATESTRUCT)lParam)->lpCreateParams);
00673 
00674             /* Initialize the main window context */
00675             Info->hMainWnd = hwnd;
00676 
00677             SetWindowLongPtr(hwnd,
00678                              GWLP_USERDATA,
00679                              (LONG_PTR)Info);
00680 
00681             if (!InitMainWnd(Info))
00682                 SendMessage(hwnd, WM_CLOSE, 0, 0);
00683 
00684             /* Show the window */
00685             ShowWindow(hwnd,
00686                        Info->nCmdShow);
00687         }
00688         break;
00689 
00690         case WM_SETFOCUS:
00691         {
00692             if (Info->hTreeView != NULL)
00693                 SetFocus(Info->hTreeView);
00694         }
00695         break;
00696 
00697         case WM_SIZE:
00698         {
00699             MainWndResize(Info,
00700                           LOWORD(lParam),
00701                           HIWORD(lParam));
00702         }
00703         break;
00704 
00705         case WM_NOTIFY:
00706         {
00707             Ret = OnNotify(Info, lParam);
00708         }
00709         break;
00710 
00711         case WM_CONTEXTMENU:
00712         {
00713             OnContext(Info, lParam);
00714         }
00715         break;
00716 
00717         case WM_COMMAND:
00718         {
00719             MainWndCommand(Info,
00720                            LOWORD(wParam),
00721                            (HWND)lParam);
00722             goto HandleDefaultMessage;
00723         }
00724 
00725         case WM_MENUSELECT:
00726         {
00727             if (Info->hStatus != NULL)
00728             {
00729                 if (!MainWndMenuHint(Info,
00730                                      LOWORD(wParam),
00731                                      MainMenuHintTable,
00732                                      sizeof(MainMenuHintTable) / sizeof(MainMenuHintTable[0]),
00733                                      IDS_HINT_BLANK))
00734                 {
00735                     MainWndMenuHint(Info,
00736                                     LOWORD(wParam),
00737                                     SystemMenuHintTable,
00738                                     sizeof(SystemMenuHintTable) / sizeof(SystemMenuHintTable[0]),
00739                                     IDS_HINT_BLANK);
00740                 }
00741             }
00742         }
00743         break;
00744 
00745         case WM_ENTERMENULOOP:
00746         {
00747             Info->InMenuLoop = TRUE;
00748             UpdateMainStatusBar(Info);
00749             break;
00750         }
00751 
00752         case WM_EXITMENULOOP:
00753         {
00754             Info->InMenuLoop = FALSE;
00755             UpdateMainStatusBar(Info);
00756             break;
00757         }
00758 
00759         case WM_CLOSE:
00760         {
00761             FreeDeviceStrings(Info->hTreeView);
00762             DestroyMenu(Info->hShortcutMenu);
00763             DestroyWindow(hwnd);
00764         }
00765         break;
00766 
00767         case WM_DESTROY:
00768         {
00769             HeapFree(ProcessHeap,
00770                      0,
00771                      Info);
00772             SetWindowLongPtr(hwnd,
00773                              GWLP_USERDATA,
00774                              0);
00775 
00776             /* Break the message queue loop */
00777             PostQuitMessage(0);
00778         }
00779         break;
00780 
00781         default:
00782         {
00783 HandleDefaultMessage:
00784 
00785             Ret = DefWindowProc(hwnd,
00786                                 msg,
00787                                 wParam,
00788                                 lParam);
00789         }
00790         break;
00791     }
00792     return Ret;
00793 }
00794 
00795 
00796 
00797 HWND
00798 CreateMainWindow(LPCTSTR lpCaption,
00799                  int nCmdShow)
00800 {
00801     PMAIN_WND_INFO Info;
00802     HWND hMainWnd = NULL;
00803 
00804     Info = (PMAIN_WND_INFO)HeapAlloc(ProcessHeap,
00805                                      HEAP_ZERO_MEMORY,
00806                                      sizeof(MAIN_WND_INFO));
00807 
00808     if (Info != NULL)
00809     {
00810         Info->nCmdShow = nCmdShow;
00811         Info->Display = DevicesByType;
00812         Info->bShowHidden = TRUE;
00813 
00814         hMainWnd = CreateWindowEx(WS_EX_WINDOWEDGE,
00815                                   szMainWndClass,
00816                                   lpCaption,
00817                                   WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
00818                                   CW_USEDEFAULT,
00819                                   CW_USEDEFAULT,
00820                                   600,
00821                                   450,
00822                                   NULL,
00823                                   NULL,
00824                                   hInstance,
00825                                   Info);
00826         if (hMainWnd == NULL)
00827         {
00828             GetError();
00829             HeapFree(ProcessHeap,
00830                      0,
00831                      Info);
00832         }
00833     }
00834 
00835     return hMainWnd;
00836 }
00837 
00838 BOOL
00839 InitMainWindowImpl(VOID)
00840 {
00841     WNDCLASSEX wc = {0};
00842 
00843     wc.cbSize = sizeof(WNDCLASSEX);
00844     wc.lpfnWndProc = MainWndProc;
00845     wc.hInstance = hInstance;
00846     wc.hIcon = LoadIcon(hInstance,
00847                         MAKEINTRESOURCE(IDI_MAIN_ICON));
00848     wc.hCursor = LoadCursor(NULL,
00849                             IDC_ARROW);
00850     wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
00851     wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU);
00852     wc.lpszClassName = szMainWndClass;
00853     wc.hIconSm = (HICON)LoadImage(hInstance,
00854                                   MAKEINTRESOURCE(IDI_MAIN_ICON),
00855                                   IMAGE_ICON,
00856                                   16,
00857                                   16,
00858                                   LR_SHARED);
00859 
00860     return RegisterClassEx(&wc) != (ATOM)0;
00861 }
00862 
00863 
00864 VOID
00865 UninitMainWindowImpl(VOID)
00866 {
00867     UnregisterClass(szMainWndClass,
00868                     hInstance);
00869 }
00870 
00871 

Generated on Sat May 26 2012 04:15:52 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.