📄 listview.c
字号:
/***********************************************************************
THIS CODE AND INFORMATION IS 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.
Copyright(c) 1999 Microsoft Corporation. All Rights Reserved.
MODULE:
ListView.c
ABSTRACT:
This Windows CE application shows how to register list view and
header control classes, and create a list view control.
***********************************************************************/
#ifndef STRICT
#define STRICT
#endif
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include "resource.h"
#define ITEM_COUNT 100 // Limit of number of items in the list view
#define ID_LISTVIEW 2000 // Identifier of the list view control
HINSTANCE g_hInst; // Handle to the application instance
HWND g_hwndCB = NULL; // Handle to the commandbar
HWND g_hwndLV = NULL; // Handle to the list view control
HWND g_hwndMain = NULL; // Handle to the application main window
TCHAR g_szTitle[80]; // Main window name
TCHAR g_szClassName[80]; // Main window class name
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK AboutDialogProc (HWND, UINT, WPARAM, LPARAM);
HWND CreateListView (HINSTANCE hInstance, HWND hwndParent);
BOOL InitListView (HWND hwndListView);
void UpdateMenu (HWND, HMENU);
void SwitchView (HWND, DWORD);
void ResizeListView (HWND, HWND);
LRESULT ListViewNotify (HWND, LPARAM);
/***********************************************************************
FUNCTION:
InitApplication
PURPOSE:
Initializes and registers a windows class.
***********************************************************************/
BOOL InitApplication (HINSTANCE hInstance)
{
WNDCLASS wndclass;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = (WNDPROC) WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_MAINICON));
wndclass.hInstance = hInstance;
wndclass.hCursor = NULL;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = g_szClassName;
return RegisterClass (&wndclass);
}
/***********************************************************************
FUNCTION:
InitInstance
PURPOSE:
Creates and displays the main window.
***********************************************************************/
BOOL InitInstance (HINSTANCE hInstance, int nCmdShow)
{
g_hInst = hInstance;
g_hwndMain = CreateWindow (
g_szClassName, // Registered class name
g_szTitle, // Application window name
WS_VISIBLE, // Window style
0, // Horizontal position of the window
0, // Vertical position of the window
CW_USEDEFAULT, // Window width
CW_USEDEFAULT, // Window height
NULL, // Handle to the parent window
NULL, // Handle to the menu identifier
hInstance, // Handle to the application instance
NULL); // Pointer to the window-creation data
// If it failed to create the window, return FALSE.
if (!g_hwndMain)
return FALSE;
ShowWindow (g_hwndMain, nCmdShow);
UpdateWindow (g_hwndMain);
return TRUE;
}
/***********************************************************************
FUNCTION:
WinMain
PURPOSE:
Called by the system as the initial entry point for this Windows
CE-based application.
***********************************************************************/
int WINAPI WinMain (
HINSTANCE hInstance, // Handle to the current instance
HINSTANCE hPrevInstance, // Handle to the previous instance
LPWSTR lpCmdLine, // Pointer to the command line
int nCmdShow) // Show state of the window
{
MSG msg;
// Load the window and window class name strings.
LoadString (hInstance, IDS_TITLE, g_szTitle,
sizeof (g_szTitle) / sizeof (TCHAR));
LoadString (hInstance, IDS_CLASSNAME, g_szClassName,
sizeof (g_szClassName) / sizeof (TCHAR));
if (!hPrevInstance)
{
if (!InitApplication (hInstance))
return 0;
}
if (!InitInstance (hInstance, nCmdShow))
return 0;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
/***********************************************************************
FUNCTION:
WndProc
PURPOSE:
Processes messages sent to the main window.
***********************************************************************/
LRESULT CALLBACK WndProc (HWND hwnd, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
switch (uMsg)
{
case WM_CREATE:
// Create the command bar and insert the menu.
g_hwndCB = CommandBar_Create (g_hInst, hwnd, 1);
CommandBar_InsertMenubar (g_hwndCB, g_hInst, IDM_MAIN_MENU, 0);
CommandBar_AddAdornments (g_hwndCB, 0, 0);
// Create the list view control.
g_hwndLV = CreateListView (g_hInst, hwnd);
// Initialize the list view control.
InitListView (g_hwndLV);
return 0;
case WM_NOTIFY:
return ListViewNotify (hwnd, lParam);
case WM_SIZE:
ResizeListView (g_hwndLV, hwnd);
return 0;
case WM_INITMENUPOPUP:
UpdateMenu (g_hwndLV, CommandBar_GetMenu (g_hwndCB, 0));
break;
case WM_COMMAND:
switch (GET_WM_COMMAND_ID (wParam, lParam))
{
case IDM_LARGE_ICONS:
SwitchView (g_hwndLV, LVS_ICON);
return 0;
case IDM_SMALL_ICONS:
SwitchView (g_hwndLV, LVS_SMALLICON);
return 0;
case IDM_LIST:
SwitchView (g_hwndLV, LVS_LIST);
return 0;
case IDM_REPORT:
SwitchView (g_hwndLV, LVS_REPORT);
return 0;
case IDM_EXIT:
SendMessage (hwnd, WM_CLOSE, 0, 0);
return 0;
case IDM_ABOUT:
DialogBox (g_hInst, MAKEINTRESOURCE(IDD_ABOUT), hwnd,
AboutDialogProc);
return 0;
}
break;
case WM_CLOSE:
CommandBar_Destroy (g_hwndCB);
DestroyWindow (hwnd);
return 0;
case WM_DESTROY:
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd, uMsg, wParam, lParam);
}
/***********************************************************************
FUNCTION:
AboutDialogProc
PURPOSE:
Processes messages sent to the About dialog box window.
***********************************************************************/
BOOL CALLBACK AboutDialogProc (
HWND hwndDlg, // Handle to the dialog box
UINT uMsg, // Message
WPARAM wParam, // First message parameter
LPARAM lParam) // Second message parameter
{
switch (uMsg)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch (LOWORD (wParam))
{
case IDOK:
EndDialog (hwndDlg, IDOK);
return TRUE;
case IDCANCEL:
EndDialog (hwndDlg, IDCANCEL);
return TRUE;
}
break;
}
return FALSE;
}
/***********************************************************************
FUNCTION:
CreateListView
PURPOSE:
Registers list view and header control classes, and creates a list
view control.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -