2025-11-28 00:35:46 +09:00

119 lines
3.2 KiB
C++

/*************************************************************************************************
* Description: Declarations for the custom list control.
*
* See EntryPoint.cpp for a full description of this sample.
*
*
* Copyright (C) Microsoft Corporation. All rights reserved.
*
* This source code is intended only as a supplement to Microsoft
* Development Tools and/or on-line documentation. See these other
* materials for detailed information regarding Microsoft code samples.
*
* THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
* KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
* PARTICULAR PURPOSE.
*
*************************************************************************************************/
#pragma once
#pragma warning (disable : 4244) // Disable bogus warning for SetWindowLongPtr
#include <windows.h>
#include <uxtheme.h>
#include <vssym32.h>
#include <stdio.h>
#include <stdlib.h>
#include <ole2.h>
#include <UIAutomation.h>
#include "resource.h"
#include <deque>
using namespace std;
#include <assert.h>
enum ContactStatus
{
Status_Offline,
Status_Online
};
// Custom message type for adding new contacts.
#define CUSTOMLB_ADDITEM WM_USER + 1
// Custom message type for removing contacts.
#define CUSTOMLB_REMOVEITEM WM_USER + 2
// Iterator type for list of items.
#define LISTITERATOR std::deque<CustomListItem*>::iterator
void RegisterListControl(HINSTANCE hInstance);
LRESULT CALLBACK ControlWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
HFONT GetFont(HWND hwnd, LONG height);
// Forward declarations.
class CustomListItem;
class ListProvider;
class ListItemProvider;
// CustomList control class -- the list box itself.
//
class CustomListControl
{
public:
// For simplicity, declare some properties as constants.
static const int MaxItems = 10;
// Height of list item.
static const int ItemHeight = 15;
// Dimensions of image that signifies item status.
static const int ImageWidth = 10;
static const int ImageHeight = 10;
private:
bool m_hasFocus;
int m_selectedIndex;
HWND m_controlHwnd;
deque<CustomListItem*> m_itemCollection;
ListProvider* m_pListProvider;
public:
CustomListControl(HWND hwnd);
virtual ~CustomListControl();
ListProvider* GetListProvider();
int IndexFromY(int y);
void SelectItem(int index);
int GetSelectedIndex();
bool GetIsFocused();
void SetIsFocused(bool isFocused);
bool AddItem(ContactStatus status, PCWSTR name);
LISTITERATOR GetItemAt(int index);
bool RemoveSelected();
int GetCount();
int CreateUniqueId();
HWND GetHwnd();
};
// CustomListItem control class -- an item in the list.
//
class CustomListItem
{
private:
int m_Id;
WCHAR* m_name;
ContactStatus m_status;
ListItemProvider* m_pListItemProvider;
CustomListControl* m_pOwnerControl;
public:
CustomListItem(CustomListControl* owner, int id, PCWSTR name);
virtual ~CustomListItem();
int GetItemIndex();
CustomListControl* GetOwnerList();
ListItemProvider* GetListItemProvider();
ContactStatus GetStatus();
void SetStatus(ContactStatus status);
WCHAR* GetName();
int GetId();
};