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

winmain.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:         ReactOS Applications Manager
00003  * LICENSE:         GPL - See COPYING in the top level directory
00004  * FILE:            base/applications/rapps/winmain.c
00005  * PURPOSE:         Main program
00006  * PROGRAMMERS:     Dmitry Chapyshev (dmitry@reactos.org)
00007  */
00008 
00009 #include "rapps.h"
00010 
00011 HWND hMainWnd;
00012 HINSTANCE hInst;
00013 HIMAGELIST hImageTreeView = NULL;
00014 INT SelectedEnumType = ENUM_ALL_COMPONENTS;
00015 SETTINGS_INFO SettingsInfo;
00016 
00017 
00018 VOID
00019 FillDafaultSettings(PSETTINGS_INFO pSettingsInfo)
00020 {
00021     pSettingsInfo->bSaveWndPos = TRUE;
00022     pSettingsInfo->bUpdateAtStart = FALSE;
00023     pSettingsInfo->bLogEnabled = TRUE;
00024     wcscpy(pSettingsInfo->szDownloadDir, L"C:\\Downloads");
00025     pSettingsInfo->bDelInstaller = FALSE;
00026 
00027     pSettingsInfo->Maximized = FALSE;
00028     pSettingsInfo->Left = 0;
00029     pSettingsInfo->Top = 0;
00030     pSettingsInfo->Right = 680;
00031     pSettingsInfo->Bottom = 450;
00032 }
00033 
00034 static BOOL
00035 LoadSettings(VOID)
00036 {
00037     HKEY hKey;
00038     DWORD dwSize;
00039 
00040     if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\ReactOS\\rapps", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
00041     {
00042         dwSize = sizeof(SETTINGS_INFO);
00043         if (RegQueryValueExW(hKey, L"Settings", NULL, NULL, (LPBYTE)&SettingsInfo, &dwSize) == ERROR_SUCCESS)
00044         {
00045             RegCloseKey(hKey);
00046             return TRUE;
00047         }
00048 
00049         RegCloseKey(hKey);
00050     }
00051 
00052     return FALSE;
00053 }
00054 
00055 VOID
00056 SaveSettings(HWND hwnd)
00057 {
00058     WINDOWPLACEMENT wp;
00059     HKEY hKey;
00060 
00061     if (SettingsInfo.bSaveWndPos)
00062     {
00063         wp.length = sizeof(WINDOWPLACEMENT);
00064         GetWindowPlacement(hwnd, &wp);
00065 
00066         SettingsInfo.Left = wp.rcNormalPosition.left;
00067         SettingsInfo.Top  = wp.rcNormalPosition.top;
00068         SettingsInfo.Right  = wp.rcNormalPosition.right;
00069         SettingsInfo.Bottom = wp.rcNormalPosition.bottom;
00070         SettingsInfo.Maximized = (IsZoomed(hwnd) || (wp.flags & WPF_RESTORETOMAXIMIZED));
00071     }
00072 
00073     if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"Software\\ReactOS\\rapps", 0, NULL,
00074         REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS)
00075     {
00076         RegSetValueEx(hKey, L"Settings", 0, REG_BINARY, (LPBYTE)&SettingsInfo, sizeof(SETTINGS_INFO));
00077         RegCloseKey(hKey);
00078     }
00079 }
00080 
00081 VOID
00082 FreeInstalledAppList(VOID)
00083 {
00084     INT Count = ListView_GetItemCount(hListView) - 1;
00085     PINSTALLED_INFO Info;
00086 
00087     while (Count >= 0)
00088     {
00089         Info = ListViewGetlParam(Count);
00090         if (Info)
00091         {
00092             RegCloseKey(Info->hSubKey);
00093             HeapFree(GetProcessHeap(), 0, Info);
00094         }
00095         Count--;
00096     }
00097 }
00098 
00099 BOOL
00100 CALLBACK
00101 EnumInstalledAppProc(INT ItemIndex, LPWSTR lpName, INSTALLED_INFO Info)
00102 {
00103     PINSTALLED_INFO ItemInfo;
00104     WCHAR szText[MAX_PATH];
00105     INT Index;
00106 
00107     ItemInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(INSTALLED_INFO));
00108     if (!ItemInfo) return FALSE;
00109 
00110     *ItemInfo = Info;
00111 
00112     Index = ListViewAddItem(ItemIndex, 0, lpName, (LPARAM)ItemInfo);
00113 
00114     /* Get version info */
00115     GetApplicationString((HKEY)ItemInfo->hSubKey, L"DisplayVersion", szText);
00116     ListView_SetItemText(hListView, Index, 1, szText);
00117     /* Get comments */
00118     GetApplicationString((HKEY)ItemInfo->hSubKey, L"Comments", szText);
00119     ListView_SetItemText(hListView, Index, 2, szText);
00120 
00121     return TRUE;
00122 }
00123 
00124 VOID
00125 FreeAvailableAppList(VOID)
00126 {
00127     INT Count = ListView_GetItemCount(hListView) - 1;
00128     PVOID Info;
00129 
00130     while (Count >= 0)
00131     {
00132         Info = ListViewGetlParam(Count);
00133         if (Info)
00134             HeapFree(GetProcessHeap(), 0, Info);
00135         Count--;
00136     }
00137 }
00138 
00139 BOOL
00140 CALLBACK
00141 EnumAvailableAppProc(APPLICATION_INFO Info)
00142 {
00143     PAPPLICATION_INFO ItemInfo;
00144     INT Index;
00145 
00146     /* Only add a ListView entry if...
00147          - no RegName was supplied (so we cannot determine whether the application is installed or not) or
00148          - a RegName was supplied and the application is not installed
00149     */
00150     if (!*Info.szRegName || (!IsInstalledApplication(Info.szRegName, FALSE) && !IsInstalledApplication(Info.szRegName, TRUE)))
00151     {
00152         ItemInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(APPLICATION_INFO));
00153         if (!ItemInfo) return FALSE;
00154 
00155         *ItemInfo = Info;
00156 
00157         Index = ListViewAddItem(Info.Category, 0, Info.szName, (LPARAM)ItemInfo);
00158         ListView_SetItemText(hListView, Index, 1, Info.szVersion);
00159         ListView_SetItemText(hListView, Index, 2, Info.szDesc);
00160     }
00161 
00162     return TRUE;
00163 }
00164 
00165 VOID
00166 UpdateApplicationsList(INT EnumType)
00167 {
00168     WCHAR szBuffer1[MAX_STR_LEN], szBuffer2[MAX_STR_LEN];
00169     HICON hIcon;
00170     HIMAGELIST hImageListView;
00171 
00172     (VOID) ListView_DeleteAllItems(hListView);
00173 
00174     /* Create image list */
00175     hImageListView = ImageList_Create(LISTVIEW_ICON_SIZE,
00176                                       LISTVIEW_ICON_SIZE,
00177                                       GetSystemColorDepth() | ILC_MASK,
00178                                       0, 1);
00179 
00180     hIcon = LoadImage(hInst,
00181                       MAKEINTRESOURCE(IDI_MAIN),
00182                       IMAGE_ICON,
00183                       LISTVIEW_ICON_SIZE,
00184                       LISTVIEW_ICON_SIZE,
00185                       LR_CREATEDIBSECTION);
00186 
00187     ImageList_AddIcon(hImageListView, hIcon);
00188     DestroyIcon(hIcon);
00189 
00190     if (EnumType == -1) EnumType = SelectedEnumType;
00191 
00192     if (IS_INSTALLED_ENUM(SelectedEnumType))
00193         FreeInstalledAppList();
00194     else if (IS_AVAILABLE_ENUM(SelectedEnumType))
00195         FreeAvailableAppList();
00196 
00197     if (IS_INSTALLED_ENUM(EnumType))
00198     {
00199         /* Enum installed applications and updates */
00200         EnumInstalledApplications(EnumType, TRUE, EnumInstalledAppProc);
00201         EnumInstalledApplications(EnumType, FALSE, EnumInstalledAppProc);
00202     }
00203     else if (IS_AVAILABLE_ENUM(EnumType))
00204     {
00205         /* Enum availabled applications */
00206         EnumAvailableApplications(EnumType, EnumAvailableAppProc);
00207     }
00208 
00209     /* Set image list for ListView */
00210     hImageListView = ListView_SetImageList(hListView, hImageListView, LVSIL_SMALL);
00211 
00212     /* Destroy old image list */
00213     if (hImageListView)
00214         ImageList_Destroy(hImageListView);
00215 
00216     SelectedEnumType = EnumType;
00217 
00218     LoadStringW(hInst, IDS_APPS_COUNT, szBuffer2, sizeof(szBuffer2) / sizeof(WCHAR));
00219     swprintf(szBuffer1, szBuffer2, ListView_GetItemCount(hListView));
00220     SetStatusBarText(szBuffer1);
00221 
00222     SetWelcomeText();
00223 }
00224 
00225 VOID
00226 InitApplicationsList(VOID)
00227 {
00228     WCHAR szText[MAX_STR_LEN];
00229 
00230     /* Add columns to ListView */
00231     LoadStringW(hInst, IDS_APP_NAME, szText, sizeof(szText) / sizeof(WCHAR));
00232     ListViewAddColumn(0, szText, 200, LVCFMT_LEFT);
00233 
00234     LoadStringW(hInst, IDS_APP_INST_VERSION, szText, sizeof(szText) / sizeof(WCHAR));
00235     ListViewAddColumn(1, szText, 90, LVCFMT_RIGHT);
00236 
00237     LoadStringW(hInst, IDS_APP_DESCRIPTION, szText, sizeof(szText) / sizeof(WCHAR));
00238     ListViewAddColumn(3, szText, 250, LVCFMT_LEFT);
00239 
00240     UpdateApplicationsList(ENUM_ALL_COMPONENTS);
00241 }
00242 
00243 HTREEITEM
00244 AddCategory(HTREEITEM hRootItem, UINT TextIndex, UINT IconIndex)
00245 {
00246     WCHAR szText[MAX_STR_LEN];
00247     INT Index;
00248     HICON hIcon;
00249 
00250     hIcon = LoadImage(hInst,
00251                       MAKEINTRESOURCE(IconIndex),
00252                       IMAGE_ICON,
00253                       TREEVIEW_ICON_SIZE,
00254                       TREEVIEW_ICON_SIZE,
00255                       LR_CREATEDIBSECTION);
00256 
00257     Index = ImageList_AddIcon(hImageTreeView, hIcon);
00258     DestroyIcon(hIcon);
00259 
00260     LoadStringW(hInst, TextIndex, szText, sizeof(szText) / sizeof(TCHAR));
00261 
00262     return TreeViewAddItem(hRootItem, szText, Index, Index, TextIndex);
00263 }
00264 
00265 VOID
00266 InitCategoriesList(VOID)
00267 {
00268     HTREEITEM hRootItem1, hRootItem2;
00269 
00270     /* Create image list */
00271     hImageTreeView = ImageList_Create(TREEVIEW_ICON_SIZE,
00272                                       TREEVIEW_ICON_SIZE,
00273                                       GetSystemColorDepth() | ILC_MASK,
00274                                       0, 1);
00275 
00276     hRootItem1 = AddCategory(TVI_ROOT, IDS_INSTALLED, IDI_CATEGORY);
00277     AddCategory(hRootItem1, IDS_APPLICATIONS, IDI_APPS);
00278     AddCategory(hRootItem1, IDS_UPDATES, IDI_APPUPD);
00279 
00280     hRootItem2 = AddCategory(TVI_ROOT, IDS_AVAILABLEFORINST, IDI_CATEGORY);
00281     AddCategory(hRootItem2, IDS_CAT_AUDIO, IDI_CAT_AUDIO);
00282     AddCategory(hRootItem2, IDS_CAT_VIDEO, IDI_CAT_VIDEO);
00283     AddCategory(hRootItem2, IDS_CAT_GRAPHICS, IDI_CAT_GRAPHICS);
00284     AddCategory(hRootItem2, IDS_CAT_GAMES, IDI_CAT_GAMES);
00285     AddCategory(hRootItem2, IDS_CAT_INTERNET, IDI_CAT_INTERNET);
00286     AddCategory(hRootItem2, IDS_CAT_OFFICE, IDI_CAT_OFFICE);
00287     AddCategory(hRootItem2, IDS_CAT_DEVEL, IDI_CAT_DEVEL);
00288     AddCategory(hRootItem2, IDS_CAT_EDU, IDI_CAT_EDU);
00289     AddCategory(hRootItem2, IDS_CAT_ENGINEER, IDI_CAT_ENGINEER);
00290     AddCategory(hRootItem2, IDS_CAT_FINANCE, IDI_CAT_FINANCE);
00291     AddCategory(hRootItem2, IDS_CAT_SCIENCE, IDI_CAT_SCIENCE);
00292     AddCategory(hRootItem2, IDS_CAT_TOOLS, IDI_CAT_TOOLS);
00293     AddCategory(hRootItem2, IDS_CAT_DRIVERS, IDI_CAT_DRIVERS);
00294     AddCategory(hRootItem2, IDS_CAT_LIBS, IDI_CAT_LIBS);
00295     AddCategory(hRootItem2, IDS_CAT_OTHER, IDI_CAT_OTHER);
00296 
00297     (VOID) TreeView_SetImageList(hTreeView, hImageTreeView, TVSIL_NORMAL);
00298 
00299     (VOID) TreeView_Expand(hTreeView, hRootItem2, TVE_EXPAND);
00300     (VOID) TreeView_Expand(hTreeView, hRootItem1, TVE_EXPAND);
00301 
00302     (VOID) TreeView_SelectItem(hTreeView, hRootItem1);
00303 }
00304 
00305 BOOL
00306 InitControls(HWND hwnd)
00307 {
00308     if (SettingsInfo.bSaveWndPos)
00309     {
00310         MoveWindow(hwnd, SettingsInfo.Left, SettingsInfo.Top,
00311                    SettingsInfo.Right - SettingsInfo.Left,
00312                    SettingsInfo.Bottom - SettingsInfo.Top, TRUE);
00313 
00314         if (SettingsInfo.Maximized) ShowWindow(hwnd, SW_MAXIMIZE);
00315     }
00316 
00317     if (CreateStatusBar(hwnd) &&
00318         CreateToolBar(hwnd) &&
00319         CreateListView(hwnd) &&
00320         CreateTreeView(hwnd) &&
00321         CreateRichEdit(hwnd) &&
00322         CreateVSplitBar(hwnd) &&
00323         CreateHSplitBar(hwnd))
00324     {
00325         WCHAR szBuffer1[MAX_STR_LEN], szBuffer2[MAX_STR_LEN];
00326 
00327         InitApplicationsList();
00328 
00329         InitCategoriesList();
00330 
00331         LoadStringW(hInst, IDS_APPS_COUNT, szBuffer2, sizeof(szBuffer2) / sizeof(WCHAR));
00332         swprintf(szBuffer1, szBuffer2, ListView_GetItemCount(hListView));
00333         SetStatusBarText(szBuffer1);
00334         return TRUE;
00335     }
00336 
00337     return FALSE;
00338 }
00339 
00340 VOID
00341 MainWndOnCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
00342 {
00343     WORD wCommand = LOWORD(wParam);
00344 
00345     if (lParam == (LPARAM)hSearchBar)
00346     {
00347         WCHAR szBuf[MAX_STR_LEN];
00348 
00349         switch (HIWORD(wParam))
00350         {
00351             case EN_SETFOCUS:
00352             {
00353                 WCHAR szWndText[MAX_STR_LEN];
00354 
00355                 LoadStringW(hInst, IDS_SEARCH_TEXT, szBuf, sizeof(szBuf) / sizeof(WCHAR));
00356                 GetWindowTextW(hSearchBar, szWndText, MAX_STR_LEN);
00357                 if (wcscmp(szBuf, szWndText) == 0) SetWindowTextW(hSearchBar, L"");
00358             }
00359             break;
00360 
00361             case EN_KILLFOCUS:
00362             {
00363                 GetWindowTextW(hSearchBar, szBuf, MAX_STR_LEN);
00364                 if (wcslen(szBuf) < 1)
00365                 {
00366                     LoadStringW(hInst, IDS_SEARCH_TEXT, szBuf, sizeof(szBuf) / sizeof(WCHAR));
00367                     SetWindowTextW(hSearchBar, szBuf);
00368                 }
00369             }
00370             break;
00371 
00372             case EN_CHANGE:
00373                 /* TODO: Implement search */
00374                 break;
00375         }
00376 
00377         return;
00378     }
00379 
00380     switch (wCommand)
00381     {
00382         case ID_OPEN_LINK:
00383             ShellExecuteW(hwnd, L"open", pLink, NULL, NULL, SW_SHOWNOACTIVATE);
00384             HeapFree(GetProcessHeap(), 0, pLink);
00385             break;
00386 
00387         case ID_COPY_LINK:
00388             CopyTextToClipboard(pLink);
00389             HeapFree(GetProcessHeap(), 0, pLink);
00390             break;
00391 
00392         case ID_SETTINGS:
00393             CreateSettingsDlg(hwnd);
00394             break;
00395 
00396         case ID_EXIT:
00397             PostMessageW(hwnd, WM_CLOSE, 0, 0);
00398             break;
00399 
00400         case ID_INSTALL:
00401             if (DownloadApplication(-1))
00402             /* TODO: Implement install dialog
00403              *   if (InstallApplication(-1))
00404              */
00405                 UpdateApplicationsList(-1);
00406             break;
00407 
00408         case ID_UNINSTALL:
00409             if (UninstallApplication(-1, FALSE))
00410                 UpdateApplicationsList(-1);
00411             break;
00412 
00413         case ID_MODIFY:
00414             if (UninstallApplication(-1, TRUE))
00415                 UpdateApplicationsList(-1);
00416             break;
00417 
00418         case ID_REGREMOVE:
00419             RemoveAppFromRegistry(-1);
00420             break;
00421 
00422         case ID_REFRESH:
00423             UpdateApplicationsList(-1);
00424             break;
00425 
00426         case ID_HELP:
00427             MessageBoxW(hwnd, L"Help not implemented yet", NULL, MB_OK);
00428             break;
00429 
00430         case ID_ABOUT:
00431             ShowAboutDialog();
00432             break;
00433     }
00434 }
00435 
00436 VOID
00437 MainWndOnSize(HWND hwnd, WPARAM wParam, LPARAM lParam)
00438 {
00439     HDWP hdwp = BeginDeferWindowPos(5);
00440     INT SearchBarWidth = GetWindowWidth(hSearchBar);
00441     INT RichPos = GetWindowHeight(hRichEdit);
00442     INT NewPos = HIWORD(lParam) - (RichPos + SPLIT_WIDTH + GetWindowHeight(hStatusBar));
00443     INT VSplitterPos;
00444 
00445     /* Size status bar */
00446     SendMessage(hStatusBar, WM_SIZE, 0, 0);
00447 
00448     /* Size tool bar */
00449     SendMessage(hToolBar, TB_AUTOSIZE, 0, 0);
00450 
00451     /* Size SearchBar */
00452     MoveWindow(hSearchBar, LOWORD(lParam) - SearchBarWidth - 4, 5, SearchBarWidth, 22, TRUE);
00453 
00454     /*
00455      * HIWORD(lParam) - Height of main window
00456      * LOWORD(lParam) - Width of main window
00457      */
00458 
00459     /* Size vertical splitter bar */
00460     DeferWindowPos(hdwp,
00461                    hVSplitter,
00462                    0,
00463                    (VSplitterPos = GetWindowWidth(hTreeView)),
00464                    GetWindowHeight(hToolBar),
00465                    SPLIT_WIDTH,
00466                    HIWORD(lParam) - GetWindowHeight(hToolBar) - GetWindowHeight(hStatusBar),
00467                    SWP_NOZORDER|SWP_NOACTIVATE);
00468 
00469     /* Size TreeView */
00470     DeferWindowPos(hdwp,
00471                    hTreeView,
00472                    0,
00473                    0,
00474                    GetWindowHeight(hToolBar),
00475                    VSplitterPos,
00476                    HIWORD(lParam) - GetWindowHeight(hToolBar) - GetWindowHeight(hStatusBar),
00477                    SWP_NOZORDER|SWP_NOACTIVATE);
00478 
00479     while (NewPos < SPLIT_WIDTH + GetWindowHeight(hToolBar))
00480     {
00481         RichPos--;
00482         NewPos = HIWORD(lParam) - (RichPos +
00483                  SPLIT_WIDTH + GetWindowHeight(hStatusBar));
00484     }
00485     SetHSplitterPos(NewPos);
00486 
00487     /* Size ListView */
00488     DeferWindowPos(hdwp,
00489                    hListView,
00490                    0,
00491                    VSplitterPos + SPLIT_WIDTH,
00492                    GetWindowHeight(hToolBar),
00493                    LOWORD(lParam) - (VSplitterPos + SPLIT_WIDTH),
00494                    GetHSplitterPos() - GetWindowHeight(hToolBar),
00495                    SWP_NOZORDER|SWP_NOACTIVATE);
00496 
00497     /* Size RichEdit */
00498     DeferWindowPos(hdwp,
00499                    hRichEdit,
00500                    0,
00501                    VSplitterPos + SPLIT_WIDTH,
00502                    GetHSplitterPos() + SPLIT_WIDTH,
00503                    LOWORD(lParam) - (VSplitterPos + SPLIT_WIDTH),
00504                    RichPos,
00505                    SWP_NOZORDER|SWP_NOACTIVATE);
00506 
00507     /* Size horizontal splitter bar */
00508     DeferWindowPos(hdwp,
00509                    hHSplitter,
00510                    0,
00511                    VSplitterPos + SPLIT_WIDTH,
00512                    GetHSplitterPos(),
00513                    LOWORD(lParam) - (VSplitterPos + SPLIT_WIDTH),
00514                    SPLIT_WIDTH,
00515                    SWP_NOZORDER|SWP_NOACTIVATE);
00516 
00517     EndDeferWindowPos(hdwp);
00518 }
00519 
00520 LRESULT CALLBACK
00521 MainWindowProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
00522 {
00523     switch (Msg)
00524     {
00525         case WM_CREATE:
00526             if (!InitControls(hwnd))
00527                 PostMessage(hwnd, WM_CLOSE, 0, 0);
00528 
00529             if (SettingsInfo.bUpdateAtStart)
00530                 UpdateAppsDB();
00531             break;
00532 
00533         case WM_COMMAND:
00534             MainWndOnCommand(hwnd, wParam, lParam);
00535             break;
00536 
00537         case WM_NOTIFY:
00538         {
00539             LPNMHDR data = (LPNMHDR)lParam;
00540 
00541             switch (data->code)
00542             {
00543                 case TVN_SELCHANGED:
00544                 {
00545                     if (data->hwndFrom == hTreeView)
00546                     {
00547                         switch (((LPNMTREEVIEW)lParam)->itemNew.lParam)
00548                         {
00549                             case IDS_INSTALLED:
00550                                 UpdateApplicationsList(ENUM_ALL_COMPONENTS);
00551                                 break;
00552 
00553                             case IDS_APPLICATIONS:
00554                                 UpdateApplicationsList(ENUM_APPLICATIONS);
00555                                 break;
00556 
00557                             case IDS_UPDATES:
00558                                 UpdateApplicationsList(ENUM_UPDATES);
00559                                 break;
00560 
00561                             case IDS_AVAILABLEFORINST:
00562                                 UpdateApplicationsList(ENUM_ALL_AVAILABLE);
00563                                 break;
00564 
00565                             case IDS_CAT_AUDIO:
00566                                 UpdateApplicationsList(ENUM_CAT_AUDIO);
00567                                 break;
00568 
00569                             case IDS_CAT_DEVEL:
00570                                 UpdateApplicationsList(ENUM_CAT_DEVEL);
00571                                 break;
00572 
00573                             case IDS_CAT_DRIVERS:
00574                                 UpdateApplicationsList(ENUM_CAT_DRIVERS);
00575                                 break;
00576 
00577                             case IDS_CAT_EDU:
00578                                 UpdateApplicationsList(ENUM_CAT_EDU);
00579                                 break;
00580 
00581                             case IDS_CAT_ENGINEER:
00582                                 UpdateApplicationsList(ENUM_CAT_ENGINEER);
00583                                 break;
00584 
00585                             case IDS_CAT_FINANCE:
00586                                 UpdateApplicationsList(ENUM_CAT_FINANCE);
00587                                 break;
00588 
00589                             case IDS_CAT_GAMES:
00590                                 UpdateApplicationsList(ENUM_CAT_GAMES);
00591                                 break;
00592 
00593                             case IDS_CAT_GRAPHICS:
00594                                 UpdateApplicationsList(ENUM_CAT_GRAPHICS);
00595                                 break;
00596 
00597                             case IDS_CAT_INTERNET:
00598                                 UpdateApplicationsList(ENUM_CAT_INTERNET);
00599                                 break;
00600 
00601                             case IDS_CAT_LIBS:
00602                                 UpdateApplicationsList(ENUM_CAT_LIBS);
00603                                 break;
00604 
00605                             case IDS_CAT_OFFICE:
00606                                 UpdateApplicationsList(ENUM_CAT_OFFICE);
00607                                 break;
00608 
00609                             case IDS_CAT_OTHER:
00610                                 UpdateApplicationsList(ENUM_CAT_OTHER);
00611                                 break;
00612 
00613                             case IDS_CAT_SCIENCE:
00614                                 UpdateApplicationsList(ENUM_CAT_SCIENCE);
00615                                 break;
00616 
00617                             case IDS_CAT_TOOLS:
00618                                 UpdateApplicationsList(ENUM_CAT_TOOLS);
00619                                 break;
00620 
00621                             case IDS_CAT_VIDEO:
00622                                 UpdateApplicationsList(ENUM_CAT_VIDEO);
00623                                 break;
00624                         }
00625                     }
00626                 }
00627                 break;
00628 
00629                 case LVN_KEYDOWN:
00630                 {
00631                     LPNMLVKEYDOWN pnkd = (LPNMLVKEYDOWN) lParam;
00632 
00633                     if (pnkd->hdr.hwndFrom == hListView)
00634                     {
00635                         INT ItemIndex = (INT) SendMessage(hListView, LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
00636 
00637                         if (pnkd->wVKey == VK_UP) ItemIndex -= 1;
00638                         if (pnkd->wVKey == VK_DOWN) ItemIndex += 1;
00639 
00640                         if (IS_INSTALLED_ENUM(SelectedEnumType))
00641                             ShowInstalledAppInfo(ItemIndex);
00642                         if (IS_AVAILABLE_ENUM(SelectedEnumType))
00643                             ShowAvailableAppInfo(ItemIndex);
00644                     }
00645                 }
00646                 break;
00647 
00648                 case LVN_COLUMNCLICK:
00649                 {
00650                     LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
00651 
00652                     (VOID) ListView_SortItems(hListView, ListViewCompareFunc, pnmv->iSubItem);
00653                     bAscending = !bAscending;
00654                 }
00655                 break;
00656 
00657                 case NM_CLICK:
00658                     if (data->hwndFrom == hListView)
00659                     {
00660                         if (IS_INSTALLED_ENUM(SelectedEnumType))
00661                             ShowInstalledAppInfo(-1);
00662                         if (IS_AVAILABLE_ENUM(SelectedEnumType))
00663                             ShowAvailableAppInfo(-1);
00664                     }
00665                     break;
00666 
00667                 case NM_RCLICK:
00668                     if (data->hwndFrom == hListView)
00669                         ShowPopupMenu(hListView, IDR_APPLICATIONMENU);
00670                     break;
00671 
00672                 case EN_LINK:
00673                     RichEditOnLink(hwnd, (ENLINK*)lParam);
00674                     break;
00675 
00676                 case TTN_GETDISPINFO:
00677                     ToolBarOnGetDispInfo((LPTOOLTIPTEXT)lParam);
00678                     break;
00679             }
00680         }
00681         break;
00682 
00683         case WM_PAINT:
00684         break;
00685 
00686         case WM_SIZE:
00687         {
00688             if ((GetClientWindowHeight(hMainWnd) - GetWindowHeight(hStatusBar) - SPLIT_WIDTH) < GetHSplitterPos())
00689             {
00690                 INT NewSplitPos = GetClientWindowHeight(hwnd) - 100 - GetWindowHeight(hStatusBar) - SPLIT_WIDTH;
00691                 if (NewSplitPos > GetWindowHeight(hToolBar) + SPLIT_WIDTH)
00692                     SetHSplitterPos(NewSplitPos);
00693             }
00694 
00695             MainWndOnSize(hwnd, wParam, lParam);
00696         }
00697         break;
00698 
00699         case WM_SIZING:
00700         {
00701             int RichEditHeight = GetWindowHeight(hRichEdit);
00702             LPRECT pRect = (LPRECT)lParam;
00703 
00704             while (RichEditHeight <= 100)
00705             {
00706                 if (GetHSplitterPos() - 1 < GetWindowHeight(hToolBar) + GetWindowHeight(hListView) + SPLIT_WIDTH)
00707                     break;
00708                 SetHSplitterPos(GetHSplitterPos() - 1);
00709                 RichEditHeight++;
00710             }
00711 
00712             if (pRect->right-pRect->left < 565)
00713                 pRect->right = pRect->left + 565;
00714 
00715             if (pRect->bottom-pRect->top < 300)
00716                 pRect->bottom = pRect->top + 300;
00717             return TRUE;
00718         }
00719 
00720         case WM_SYSCOLORCHANGE:
00721         {
00722             /* Forward WM_SYSCOLORCHANGE to common controls */
00723             SendMessage(hListView, WM_SYSCOLORCHANGE, 0, 0);
00724             SendMessage(hTreeView, WM_SYSCOLORCHANGE, 0, 0);
00725             SendMessage(hToolBar, WM_SYSCOLORCHANGE, 0, 0);
00726             SendMessageW(hRichEdit, EM_SETBKGNDCOLOR, 0, GetSysColor(COLOR_BTNFACE));
00727         }
00728         break;
00729 
00730         case WM_DESTROY:
00731         {
00732             ShowWindow(hwnd, SW_HIDE);
00733             SaveSettings(hwnd);
00734 
00735             FreeLogs();
00736 
00737             if (IS_AVAILABLE_ENUM(SelectedEnumType))
00738                 FreeAvailableAppList();
00739             if (IS_INSTALLED_ENUM(SelectedEnumType))
00740                 FreeInstalledAppList();
00741             if (hImageTreeView) ImageList_Destroy(hImageTreeView);
00742 
00743             PostQuitMessage(0);
00744             return 0;
00745         }
00746         break;
00747     }
00748 
00749     return DefWindowProc(hwnd, Msg, wParam, lParam);
00750 }
00751 
00752 int WINAPI
00753 wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
00754 {
00755     WNDCLASSEXW WndClass = {0};
00756     WCHAR szWindowClass[] = L"ROSAPPMGR";
00757     WCHAR szWindowName[MAX_STR_LEN];
00758     WCHAR szErrorText[MAX_STR_LEN];
00759     HANDLE hMutex = NULL;
00760     MSG Msg;
00761 
00762     hInst = hInstance;
00763 
00764     if (!IsUserAnAdmin())
00765     {
00766         LoadStringW(hInst, IDS_USER_NOT_ADMIN, szErrorText, sizeof(szErrorText) / sizeof(WCHAR));
00767         MessageBox(0, szErrorText, NULL, MB_OK | MB_ICONWARNING);
00768         return 1;
00769     }
00770 
00771     hMutex = CreateMutexW(NULL, FALSE, szWindowClass);
00772     if ((!hMutex) || (GetLastError() == ERROR_ALREADY_EXISTS))
00773     {
00774         /* If already started, it is found its window */
00775         HWND hWindow = FindWindowW(szWindowClass, NULL);
00776 
00777         /* Activate window */
00778         ShowWindow(hWindow, SW_SHOWNORMAL);
00779         SetForegroundWindow(hWindow);
00780         return 1;
00781     }
00782 
00783     if (!LoadSettings())
00784     {
00785         FillDafaultSettings(&SettingsInfo);
00786     }
00787 
00788     InitLogs();
00789 
00790     InitCommonControls();
00791 
00792     /* Create the window */
00793     WndClass.cbSize        = sizeof(WNDCLASSEXW);
00794     WndClass.lpszClassName = szWindowClass;
00795     WndClass.lpfnWndProc   = MainWindowProc;
00796     WndClass.hInstance     = hInstance;
00797     WndClass.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MAIN));
00798     WndClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
00799     WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
00800     WndClass.lpszMenuName  = MAKEINTRESOURCEW(IDR_MAINMENU);
00801 
00802     if (RegisterClassExW(&WndClass) == (ATOM)0) goto Exit;
00803 
00804     LoadStringW(hInst, IDS_APPTITLE, szWindowName, sizeof(szWindowName) / sizeof(WCHAR));
00805 
00806     hMainWnd = CreateWindowExW(WS_EX_WINDOWEDGE,
00807                                szWindowClass,
00808                                szWindowName,
00809                                WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
00810                                CW_USEDEFAULT,
00811                                CW_USEDEFAULT,
00812                                680,
00813                                450,
00814                                NULL,
00815                                NULL,
00816                                hInstance,
00817                                NULL);
00818 
00819     if (!hMainWnd) goto Exit;
00820 
00821     /* Show it */
00822     ShowWindow(hMainWnd, SW_SHOW);
00823     UpdateWindow(hMainWnd);
00824 
00825     /* Message Loop */
00826     while (GetMessage(&Msg, NULL, 0, 0))
00827     {
00828         TranslateMessage(&Msg);
00829         DispatchMessage(&Msg);
00830     }
00831 
00832 Exit:
00833     if (hMutex) CloseHandle(hMutex);
00834 
00835     return 0;
00836 }

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