HIMAGELIST InitImageList(VOID) { HIMAGELIST hImageList; /* Create the toolbar icon image list */ hImageList = ImageList_Create(TOOLBAR_HEIGHT,//GetSystemMetrics(SM_CXSMICON), TOOLBAR_HEIGHT,//GetSystemMetrics(SM_CYSMICON), ILC_MASK | GetSystemColorDepth(), 1, 1); if (!hImageList) { /* TODO: Error message */ return NULL; } AddImageToImageList(hImageList, IDI_INSTALL); AddImageToImageList(hImageList, IDI_UNINSTALL); AddImageToImageList(hImageList, IDI_MODIFY); AddImageToImageList(hImageList, IDI_REFRESH); AddImageToImageList(hImageList, IDI_SETTINGS); AddImageToImageList(hImageList, IDI_EXIT); return hImageList; }
BOOL InitControls() { /* Create image list */ hImageTreeView = ImageList_Create(TREEVIEW_ICON_SIZE, TREEVIEW_ICON_SIZE, GetSystemColorDepth() | ILC_MASK, 0, 1); if (CreateLayout()) { WCHAR szBuffer1[MAX_STR_LEN], szBuffer2[MAX_STR_LEN]; InitApplicationsList(); InitCategoriesList(); LoadStringW(hInst, IDS_APPS_COUNT, szBuffer2, _countof(szBuffer2)); StringCbPrintfW(szBuffer1, sizeof(szBuffer1), szBuffer2, m_ListView->GetItemCount()); m_StatusBar->SetText(szBuffer1); return TRUE; } return FALSE; }
VOID UpdateApplicationsList(INT EnumType) { WCHAR szBuffer1[MAX_STR_LEN], szBuffer2[MAX_STR_LEN]; HICON hIcon; HIMAGELIST hImageListView; (VOID) ListView_DeleteAllItems(hListView); /* Create image list */ hImageListView = ImageList_Create(LISTVIEW_ICON_SIZE, LISTVIEW_ICON_SIZE, GetSystemColorDepth() | ILC_MASK, 0, 1); hIcon = LoadImage(hInst, MAKEINTRESOURCE(IDI_MAIN), IMAGE_ICON, LISTVIEW_ICON_SIZE, LISTVIEW_ICON_SIZE, LR_CREATEDIBSECTION); ImageList_AddIcon(hImageListView, hIcon); DestroyIcon(hIcon); if (EnumType == -1) EnumType = SelectedEnumType; if (IS_INSTALLED_ENUM(SelectedEnumType)) FreeInstalledAppList(); else if (IS_AVAILABLE_ENUM(SelectedEnumType)) FreeAvailableAppList(); if (IS_INSTALLED_ENUM(EnumType)) { /* Enum installed applications and updates */ EnumInstalledApplications(EnumType, TRUE, EnumInstalledAppProc); EnumInstalledApplications(EnumType, FALSE, EnumInstalledAppProc); } else if (IS_AVAILABLE_ENUM(EnumType)) { /* Enum availabled applications */ EnumAvailableApplications(EnumType, EnumAvailableAppProc); } /* Set image list for ListView */ hImageListView = ListView_SetImageList(hListView, hImageListView, LVSIL_SMALL); /* Destroy old image list */ if (hImageListView) ImageList_Destroy(hImageListView); SelectedEnumType = EnumType; LoadStringW(hInst, IDS_APPS_COUNT, szBuffer2, sizeof(szBuffer2) / sizeof(WCHAR)); swprintf(szBuffer1, szBuffer2, ListView_GetItemCount(hListView)); SetStatusBarText(szBuffer1); SetWelcomeText(); }
VOID InitCategoriesList(VOID) { HTREEITEM hRootItem1, hRootItem2; /* Create image list */ hImageTreeView = ImageList_Create(TREEVIEW_ICON_SIZE, TREEVIEW_ICON_SIZE, GetSystemColorDepth() | ILC_MASK, 0, 1); hRootItem1 = AddCategory(TVI_ROOT, IDS_INSTALLED, IDI_CATEGORY); AddCategory(hRootItem1, IDS_APPLICATIONS, IDI_APPS); AddCategory(hRootItem1, IDS_UPDATES, IDI_APPUPD); hRootItem2 = AddCategory(TVI_ROOT, IDS_AVAILABLEFORINST, IDI_CATEGORY); AddCategory(hRootItem2, IDS_CAT_AUDIO, IDI_CAT_AUDIO); AddCategory(hRootItem2, IDS_CAT_VIDEO, IDI_CAT_VIDEO); AddCategory(hRootItem2, IDS_CAT_GRAPHICS, IDI_CAT_GRAPHICS); AddCategory(hRootItem2, IDS_CAT_GAMES, IDI_CAT_GAMES); AddCategory(hRootItem2, IDS_CAT_INTERNET, IDI_CAT_INTERNET); AddCategory(hRootItem2, IDS_CAT_OFFICE, IDI_CAT_OFFICE); AddCategory(hRootItem2, IDS_CAT_DEVEL, IDI_CAT_DEVEL); AddCategory(hRootItem2, IDS_CAT_EDU, IDI_CAT_EDU); AddCategory(hRootItem2, IDS_CAT_ENGINEER, IDI_CAT_ENGINEER); AddCategory(hRootItem2, IDS_CAT_FINANCE, IDI_CAT_FINANCE); AddCategory(hRootItem2, IDS_CAT_SCIENCE, IDI_CAT_SCIENCE); AddCategory(hRootItem2, IDS_CAT_TOOLS, IDI_CAT_TOOLS); AddCategory(hRootItem2, IDS_CAT_DRIVERS, IDI_CAT_DRIVERS); AddCategory(hRootItem2, IDS_CAT_LIBS, IDI_CAT_LIBS); AddCategory(hRootItem2, IDS_CAT_OTHER, IDI_CAT_OTHER); (VOID) TreeView_SetImageList(hTreeView, hImageTreeView, TVSIL_NORMAL); (VOID) TreeView_Expand(hTreeView, hRootItem2, TVE_EXPAND); (VOID) TreeView_Expand(hTreeView, hRootItem1, TVE_EXPAND); (VOID) TreeView_SelectItem(hTreeView, hRootItem1); }
INT_PTR CALLBACK ApplicationPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { RECT rc; int nXDifference; int nYDifference; LV_COLUMN column; WCHAR szTemp[256]; int cx, cy; switch (message) { case WM_INITDIALOG: /* Save the width and height */ GetClientRect(hDlg, &rc); nApplicationPageWidth = rc.right; nApplicationPageHeight = rc.bottom; /* Update window position */ SetWindowPos(hDlg, NULL, 15, 30, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); /* Get handles to the controls */ hApplicationPageListCtrl = GetDlgItem(hDlg, IDC_APPLIST); hApplicationPageEndTaskButton = GetDlgItem(hDlg, IDC_ENDTASK); hApplicationPageSwitchToButton = GetDlgItem(hDlg, IDC_SWITCHTO); hApplicationPageNewTaskButton = GetDlgItem(hDlg, IDC_NEWTASK); SetWindowTextW(hApplicationPageListCtrl, L"Tasks"); /* Initialize the application page's controls */ column.mask = LVCF_TEXT|LVCF_WIDTH; LoadStringW(hInst, IDS_TAB_TASK, szTemp, 256); column.pszText = szTemp; column.cx = 250; (void)ListView_InsertColumn(hApplicationPageListCtrl, 0, &column); /* Add the "Task" column */ column.mask = LVCF_TEXT|LVCF_WIDTH; LoadStringW(hInst, IDS_TAB_STATUS, szTemp, 256); column.pszText = szTemp; column.cx = 95; (void)ListView_InsertColumn(hApplicationPageListCtrl, 1, &column); /* Add the "Status" column */ (void)ListView_SetImageList(hApplicationPageListCtrl, ImageList_Create(16, 16, GetSystemColorDepth()|ILC_MASK, 0, 1), LVSIL_SMALL); (void)ListView_SetImageList(hApplicationPageListCtrl, ImageList_Create(32, 32, GetSystemColorDepth()|ILC_MASK, 0, 1), LVSIL_NORMAL); UpdateApplicationListControlViewSetting(); /* Start our refresh thread */ #ifdef RUN_APPS_PAGE hApplicationThread = CreateThread(NULL, 0, ApplicationPageRefreshThread, NULL, 0, &dwApplicationThread); #endif /* Refresh page */ ApplicationPageUpdate(); return TRUE; case WM_DESTROY: /* Close refresh thread */ #ifdef RUN_APPS_PAGE EndLocalThread(&hApplicationThread, dwApplicationThread); #endif break; case WM_COMMAND: /* Handle the button clicks */ switch (LOWORD(wParam)) { case IDC_ENDTASK: ApplicationPage_OnEndTask(); break; case IDC_SWITCHTO: ApplicationPage_OnSwitchTo(); break; case IDC_NEWTASK: SendMessageW(hMainWnd, WM_COMMAND, MAKEWPARAM(ID_FILE_NEW, 0), 0); break; } break; case WM_SIZE: if (wParam == SIZE_MINIMIZED) return 0; cx = LOWORD(lParam); cy = HIWORD(lParam); nXDifference = cx - nApplicationPageWidth; nYDifference = cy - nApplicationPageHeight; nApplicationPageWidth = cx; nApplicationPageHeight = cy; /* Reposition the application page's controls */ GetWindowRect(hApplicationPageListCtrl, &rc); cx = (rc.right - rc.left) + nXDifference; cy = (rc.bottom - rc.top) + nYDifference; SetWindowPos(hApplicationPageListCtrl, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER); InvalidateRect(hApplicationPageListCtrl, NULL, TRUE); GetClientRect(hApplicationPageEndTaskButton, &rc); MapWindowPoints(hApplicationPageEndTaskButton, hDlg, (LPPOINT)(PRECT)(&rc), sizeof(RECT)/sizeof(POINT)); cx = rc.left + nXDifference; cy = rc.top + nYDifference; SetWindowPos(hApplicationPageEndTaskButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); InvalidateRect(hApplicationPageEndTaskButton, NULL, TRUE); GetClientRect(hApplicationPageSwitchToButton, &rc); MapWindowPoints(hApplicationPageSwitchToButton, hDlg, (LPPOINT)(PRECT)(&rc), sizeof(RECT)/sizeof(POINT)); cx = rc.left + nXDifference; cy = rc.top + nYDifference; SetWindowPos(hApplicationPageSwitchToButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); InvalidateRect(hApplicationPageSwitchToButton, NULL, TRUE); GetClientRect(hApplicationPageNewTaskButton, &rc); MapWindowPoints(hApplicationPageNewTaskButton, hDlg, (LPPOINT)(PRECT)(&rc), sizeof(RECT)/sizeof(POINT)); cx = rc.left + nXDifference; cy = rc.top + nYDifference; SetWindowPos(hApplicationPageNewTaskButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); InvalidateRect(hApplicationPageNewTaskButton, NULL, TRUE); break; case WM_NOTIFY: ApplicationPageOnNotify(wParam, lParam); break; case WM_KEYDOWN: if (wParam == VK_DELETE) ProcessPage_OnEndProcess(); break; } return 0; }
VOID UpdateApplicationsList(INT EnumType) { WCHAR szBuffer1[MAX_STR_LEN], szBuffer2[MAX_STR_LEN]; HICON hIcon; HIMAGELIST hImageListView; m_ListView->SendMessage(WM_SETREDRAW, FALSE, 0); if (EnumType == -1) EnumType = SelectedEnumType; if (IS_INSTALLED_ENUM(SelectedEnumType)) FreeInstalledAppList(); (VOID) ListView_DeleteAllItems(hListView); /* Create image list */ hImageListView = ImageList_Create(LISTVIEW_ICON_SIZE, LISTVIEW_ICON_SIZE, GetSystemColorDepth() | ILC_MASK, 0, 1); hIcon = (HICON) LoadImage(hInst, MAKEINTRESOURCE(IDI_MAIN), IMAGE_ICON, LISTVIEW_ICON_SIZE, LISTVIEW_ICON_SIZE, LR_CREATEDIBSECTION); ImageList_AddIcon(hImageListView, hIcon); DestroyIcon(hIcon); if (IS_INSTALLED_ENUM(EnumType)) { /* Enum installed applications and updates */ EnumInstalledApplications(EnumType, TRUE, s_EnumInstalledAppProc); EnumInstalledApplications(EnumType, FALSE, s_EnumInstalledAppProc); } else if (IS_AVAILABLE_ENUM(EnumType)) { /* Enum availabled applications */ EnumAvailableApplications(EnumType, s_EnumAvailableAppProc); } /* Set image list for ListView */ hImageListView = ListView_SetImageList(hListView, hImageListView, LVSIL_SMALL); /* Destroy old image list */ if (hImageListView) ImageList_Destroy(hImageListView); SelectedEnumType = EnumType; LoadStringW(hInst, IDS_APPS_COUNT, szBuffer2, _countof(szBuffer2)); StringCbPrintfW(szBuffer1, sizeof(szBuffer1), szBuffer2, ListView_GetItemCount(hListView)); SetStatusBarText(szBuffer1); SetWelcomeText(); /* set automatic column width for program names if the list is not empty */ if (ListView_GetItemCount(hListView) > 0) ListView_SetColumnWidth(hListView, 0, LVSCW_AUTOSIZE); SendMessage(hListView, WM_SETREDRAW, TRUE, 0); }