pickicon.c
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 6k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. //
  2. //  PickIcon.C
  3. //
  4. //  Copyright (C) Microsoft, 1994,1995 All Rights Reserved.
  5. //
  6. //  History:
  7. //  ral 6/23/94 - First pass
  8. //  3/20/95  [stevecat] - NT port & real clean up, unicode, etc.
  9. //
  10. //
  11. #include "priv.h"
  12. #include "appwiz.h"
  13. //
  14. //  BUGBUG -- Size?
  15. //
  16. #define MAX_ICONS   75
  17. //
  18. //  Adds icons to the list box.
  19. //
  20. void PutIconsInList(HWND hLB, LPWIZDATA lpwd)
  21. {
  22.     HICON   rgIcons[MAX_ICONS];
  23.     int     iTempIcon;
  24.     int     cIcons;
  25.     HCURSOR hcurOld = SetCursor(LoadCursor(NULL, IDC_WAIT));
  26.     RECT    rc;
  27.     int     cy;
  28.     ListBox_SetColumnWidth(hLB, g_cxIcon+12);
  29.     //
  30.     // compute the height of the listbox based on icon dimensions
  31.     //
  32.     GetWindowRect(hLB, &rc);
  33.     cy = g_cyIcon + GetSystemMetrics(SM_CYHSCROLL) + GetSystemMetrics(SM_CYEDGE) * 3;
  34.     SetWindowPos(hLB, NULL, 0, 0, rc.right-rc.left, rc.bottom-rc.top,
  35.                          SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
  36.     ListBox_ResetContent(hLB);
  37.     SendMessage(hLB, WM_SETREDRAW, FALSE, 0L);
  38. #ifdef DEBUG
  39.     {
  40.     //
  41.     //  This is necessary for Unicode (i.e. NT) builds because the shell32
  42.     //  library does not support ShellMessageBoxA and W versions.
  43.     //
  44. #ifdef UNICODE
  45.     TCHAR szTemp[MAX_PATH];
  46.     MultiByteToWideChar(CP_ACP, 0, lpwd->PropPrg.achIconFile, -1, szTemp, ARRAYSIZE(szTemp));
  47.     WIZERROR(szTemp);
  48. #else
  49.     WIZERROR(lpwd->PropPrg.achIconFile);
  50. #endif
  51.     }
  52. #endif  //  DEBUG
  53.     cIcons = (int)ExtractIconExA(lpwd->PropPrg.achIconFile, 0, rgIcons, NULL, MAX_ICONS);
  54.     for (iTempIcon = 0; iTempIcon < cIcons; iTempIcon++)
  55.     {
  56.         ListBox_AddString(hLB, rgIcons[iTempIcon]);
  57.     }
  58.     ListBox_SetCurSel(hLB, 0);
  59.     SendMessage(hLB, WM_SETREDRAW, TRUE, 0L);
  60.     InvalidateRect(hLB, NULL, TRUE);
  61.     SetCursor(hcurOld);
  62. }
  63. //
  64. //
  65. //
  66. void PickIconInitDlg(HWND hDlg, LPARAM lParam)
  67. {
  68.     LPPROPSHEETPAGE lpp = (LPPROPSHEETPAGE)lParam;
  69.     LPWIZDATA lpwd = InitWizSheet(hDlg, lParam, 0);
  70.     PutIconsInList(GetDlgItem(hDlg, IDC_ICONLIST), lpwd);
  71. }
  72. //
  73. //  Returns TRUE if a vaild icon is selected.
  74. //
  75. BOOL PickIconNextPressed(LPWIZDATA lpwd)
  76. {
  77.     int iIconIndex = ListBox_GetCurSel(GetDlgItem(lpwd->hwnd, IDC_ICONLIST));
  78.     lpwd->PropPrg.wIconIndex = (WORD)iIconIndex;
  79.     return(iIconIndex != LB_ERR);
  80. }
  81. //
  82. //
  83. //
  84. BOOL_PTR CALLBACK PickIconDlgProc(HWND hDlg, UINT message , WPARAM wParam, LPARAM lParam)
  85. {
  86.     NMHDR FAR *lpnm;
  87.     LPPROPSHEETPAGE lpp = (LPPROPSHEETPAGE)(GetWindowLongPtr(hDlg, DWLP_USER));
  88.     LPWIZDATA lpwd = lpp ? (LPWIZDATA)lpp->lParam : NULL;
  89.     switch(message)
  90.     {
  91.         case WM_NOTIFY:
  92.             lpnm = (NMHDR FAR *)lParam;
  93.             switch(lpnm->code)
  94.             {
  95.             case PSN_SETACTIVE:
  96.                     //
  97.                     // If PIFMGR has assigned an icon for this app then
  98.                     // we'll skip it.  This condition only happens when
  99.                     // creating a shortcut to a single MS-DOS session.
  100.                     //
  101.                     if (lpwd->dwFlags & WDFLAG_APPKNOWN)
  102.                     {
  103.                         SetDlgMsgResult(hDlg, WM_NOTIFY, -1);
  104.                     }
  105.                     else
  106.                     {
  107.                         lpwd->hwnd = hDlg;
  108.                         PropSheet_SetWizButtons(GetParent(hDlg),
  109.                                                (lpwd->dwFlags & WDFLAG_SINGLEAPP) ?
  110.                                                 PSWIZB_BACK | PSWIZB_NEXT :
  111.                                                 PSWIZB_BACK | PSWIZB_FINISH);
  112.                     }
  113.                     break;
  114.                 case PSN_WIZNEXT:
  115.                     if (!PickIconNextPressed(lpwd))
  116.                     {
  117.                         SetDlgMsgResult(hDlg, WM_NOTIFY, -1);
  118.                     }
  119.                     break;
  120.                 case PSN_WIZFINISH:
  121.                     if (!(PickIconNextPressed(lpwd) && CreateLink(lpwd)))
  122.                     {
  123.                         SetDlgMsgResult(hDlg, WM_NOTIFY, -1);
  124.                     }
  125.                     break;
  126.                 case PSN_RESET:
  127.                     CleanUpWizData(lpwd);
  128.                     break;
  129.                 default:
  130.                     return FALSE;
  131.             }
  132.             break;
  133.         case WM_INITDIALOG:
  134.             PickIconInitDlg(hDlg, lParam);
  135.             break;
  136.         case WM_COMMAND:
  137.             if ((GET_WM_COMMAND_ID(wParam, lParam) == IDC_ICONLIST) &&
  138.                 ((GET_WM_COMMAND_CMD(wParam, lParam) == LBN_DBLCLK)))
  139.             {
  140.                 PropSheet_PressButton(GetParent(hDlg),
  141.                                       (lpwd->dwFlags & WDFLAG_SINGLEAPP) ?
  142.                                                  PSBTN_NEXT : PSBTN_FINISH);
  143.             }
  144.             break;
  145.         //
  146.         // owner draw messages for icon listbox
  147.         //
  148.         case WM_DRAWITEM:
  149.             #define lpdi ((DRAWITEMSTRUCT FAR *)lParam)
  150.             if (lpdi->itemState & ODS_SELECTED)
  151.                 SetBkColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT));
  152.             else
  153.                 SetBkColor(lpdi->hDC, GetSysColor(COLOR_WINDOW));
  154.             //
  155.             // repaint the selection state
  156.             //
  157.             ExtTextOut(lpdi->hDC, 0, 0, ETO_OPAQUE, &lpdi->rcItem, NULL, 0, NULL);
  158.             //
  159.             // draw the icon
  160.             //
  161.             if ((int)lpdi->itemID >= 0)
  162.               DrawIcon(lpdi->hDC, (lpdi->rcItem.left + lpdi->rcItem.right - g_cxIcon) / 2,
  163.                                   (lpdi->rcItem.bottom + lpdi->rcItem.top - g_cyIcon) / 2, (HICON)lpdi->itemData);
  164.             // InflateRect(&lpdi->rcItem, -1, -1);
  165.             //
  166.             // if it has the focus, draw the focus
  167.             //
  168.             if (lpdi->itemState & ODS_FOCUS)
  169.                 DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
  170.             #undef lpdi
  171.             break;
  172.         case WM_MEASUREITEM:
  173.             #define lpmi ((MEASUREITEMSTRUCT FAR *)lParam)
  174.             lpmi->itemWidth = g_cxIcon + 12;
  175.             lpmi->itemHeight = g_cyIcon + 4;
  176.             #undef lpmi
  177.             break;
  178.         case WM_DELETEITEM:
  179.             #define lpdi ((DELETEITEMSTRUCT FAR *)lParam)
  180.             DestroyIcon((HICON)lpdi->itemData);
  181.             #undef lpdi
  182.             break;
  183.         default:
  184.             return FALSE;
  185.     }
  186.     return TRUE;
  187. }