Docsity

Windows Common Controls - Window Programming - Lecture Slides, Slides of Windows Programming

Partial preview of the text

Download Windows Common Controls - Window Programming - Lecture Slides and more Slides Windows Programming in PDF only on Docsity!

LL e c te c t u ru r ee

Review of Last Lecture

  • Common dialog: choose colour
  • Modeless and Modal dialogs
  • Listbox
  • Edit, radio, static, WM_CTLCOLORSTATIC
  • Tab stop, Tab order, Groups of controls
  • Control Notification Messages

Windows Common Controls

  • Weren’t there in Win3.
  • Implemented in Comctl32.dll
  • Library versions: IE and before IE shipments
  • Effect of library versions
  • InitCommonControls(void); registers the common control window classes

InitCommoncontrolsEx()

typedef struct tagINITCOMMONCONTROLSEX {

DWORD dwSize; DWORD dwICC;

} INITCOMMONCONTROLSEX;

Valid values for the dwICC parameter:

ICC_DATE_CLASSES : Date-Time picker control class

contd…

Figure –List View control

Today’s Goals

  • ListView common control
  • Description of the control’s appearance and the application
  • Image List

ImageList

  • An image list is a collection of images of the same size, each of which can be referred to by its index.
  • InitCommonControls needs to be called before image lists can be used

ImageList_Create

HIMAGELIST ImageList_Create( int cx, // width int cy, // height UINT flags, ILC_COLOR4 , ILC_MASK int cInitial, Number of images that the image list initially contains

int cGrow This parameter represents the number of new images that the resized image list can contain );

ImageList_ReplaceIcon( )

int ImageList_ReplaceIcon(

HIMAGELIST himl, int i, Index of the image to replace. If i is -1, the function appends the image to the end of the list. HICON hicon bitmap+mask );

Screen-shot of Example Application

Creating a ListView control

We Created a window with WNDCLASS wc

#define ID_LISTVIEW 5 hWndListView = CreateWindow(WC_LISTVIEW, "Window Name", WS_TABSTOP | WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_AUTOARRANGE | LVS_REPORT, 10, 10, 350, 280, hWndMain, (HMENU)ID_LISTVIEW, hInstance, NULL);

if(!hWndListView) return 1;

Creating imglist

hLarge = ImageList_Create(GetSystemMetrics(SM_CXICO N), GetSystemMetrics(SM_CYICON), ILC_MASK, 1, 1); hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMI CON), GetSystemMetrics(SM_CYSMICON), ILC_MASK, 1, 1); hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON_FOLDER)); ImageList_AddIcon(hLarge, hIcon); ImageList_AddIcon(hSmall, hIcon); hIcon = LoadIcon(…, MAKEINTRESOURCE(IDI_ICON_FILE))

Add image list

ListView_SetImageList(hWndListVi ew, hLarge, LVSIL_NORMAL);

ListView_SetImageList(hWndListVi ew, hSmall, LVSIL_SMALL);

HIMAGELIST ListView_SetImageList( HWND hwnd, HIMAGELIST himl, int iImageList type of Image List: LVSIL_NORMAL | LVSIL_SMALL | LVSIL_STATE Docsity.com

Add coloumns to listview

lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;

lvc.cx = COL_WIDTH;

for(i=0; i<3; ++i) { lvc.iSubItem = i; lvc.fmt = alignments[i]; lvc.pszText = columnHeadings[i]; if(ListView_InsertColumn(hWndListView,i,&lvc)==-1) return 1; }