Прочитал статью:
http://msdn.microsoft.com/en-us/library/bb774736(VS.85).aspx
проникся. Попытался создать Extended Tiles. Вроде создал, но отображается только содержимое первой колонки(а должно быть и всех остальных серенькими).
Потом попробывал просто LV_VIEW_TILE создать, тоже не появляются. Хотя когда создаешь постой проект в VS Windows Forms и кидаешь листбокс на него, то все нормально отображается. Но вот досада, я компилирую с помощью mingw и хочу писать в простых WinApi. Только не советуйте сменить компилятор, при компиляции этого же кода в MS VS все точно так же.
#define UNICODE
#include <Windows.h>
#include <commctrl.h>
HWND hwnd;
WCHAR *AppTitle = L"ListView DEMO";
LRESULT CALLBACK WindowProc(HWND hwnd, UINT, WPARAM wparam, LPARAM lparam);
HINSTANCE hInst;
VOID SetView(HWND hWndListView, DWORD dwView)
{
// Retrieve the current window style.
DWORD dwStyle = GetWindowLong(hWndListView, GWL_STYLE);
// Only set the window style if the view bits have changed.
if ((dwStyle & LVS_TYPEMASK) != dwView)
{
SetWindowLong(hWndListView,
GWL_STYLE,
(dwStyle & ~LVS_TYPEMASK) | dwView);
}
}
int fInsertListViewItem(HWND hwndListView, long lLin,
long lCol, int iSubItemYesNo, WCHAR* text)
{
/*********************
* Local declarations *
*********************/
// LVITEM struct (see MSDN for content):
LVITEMW lvi;
// RECT struct, used in column width and WM_PAINT jobs:
RECT rect;
// Enter the client area of the ListView into
// the RECT structure:
GetClientRect(hwndListView, &rect);
// Value to be returned after the function tried to insert
// an item / subitem:
int iResult;
// Initialize the LVITEM struct (see LVIF_xxx reference in MSDN):
memset(&lvi, 0, sizeof(lvi));
// Minimum mask value for this job:
lvi.mask = LVIF_TEXT | LVIF_IMAGE ;
lvi.state = 0;
lvi.stateMask = 0;
// Point to the right address:
lvi.pszText = text;
// Nota bene: you might want to check lLin and lCol values first
lvi.iItem = lLin;
lvi.iImage = lLin;
lvi.iSubItem = lCol;
switch(iSubItemYesNo)
{
case 0:
// Send LVM_INSERTITEM message if you want to
// insert an item (returns -1 if it fails):
if (SendMessageW((HWND) hwndListView,
(UINT) LVM_INSERTITEMW, (WPARAM) 0, (LPARAM) &lvi) == -1)
iResult = 0; else iResult = 1;
break;
case 1:
// Send LVM_SETITEM message if you want to insert
// a subitem (returns FALSE if it fails):
if (SendMessageW((HWND) hwndListView,
(UINT) LVM_SETITEMW, (WPARAM) 0, (LPARAM) &lvi) == FALSE)
iResult = 0; else iResult = 1;
break;
default:
return(0);
break;
}
// Paints (updates) the client area of the ListView control:
InvalidateRect(hwndListView, &rect, TRUE) ;
// Returns either 1 (OK) or 0 (failed to insert an item / subitem):
return(iResult);
}
int fInsertListViewColumn(HWND hwndListView, long lCol,
int iPercent, WCHAR* text)
{
/*********************
* Local declarations *
*********************/
// LVCOLUMN struct (see MSDN for content):
LVCOLUMNW lvcolumn;
// RECT struct, used in column width and
// WM_PAINT jobs:
RECT rect;
// Enter the client area of the ListView
//into the RECT structure:
GetClientRect(hwndListView, &rect);
// Value to be returned after the function tried
// to insert a column:
int iResult;
/*************************
* Minimum error checking *
*************************/
// iPercent adjustement before display, e.g.:
iPercent = iPercent > 10 ? min(iPercent, 90) : 10;
// Column width, with 'rect.right' the x-coordinate of
// the lower-right corner of the RECT:
int iWidth = (int) (rect.right * (iPercent / 100.0));
// Initialize the LVCOLUMN struct (see LVCF_xxx and
// LVCFMT_xxx values in MSDN):
memset(&lvcolumn, 0, sizeof(lvcolumn));
// Necessary mask values for this job:
lvcolumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
// Left-align the text:
lvcolumn.fmt = LVCFMT_LEFT;
// Point to the right address:
lvcolumn.pszText = text;
// Nota bene: you might want to check lCol value first
lvcolumn.iSubItem = lCol;
// Set column width:
lvcolumn.cx = iWidth;
// SendMessage returns the number (zero based) of the
// column inserted,
// or -1 if it fails:
if (SendMessageW((HWND) hwndListView, (UINT) LVM_INSERTCOLUMNW,
(WPARAM) (int) lCol, (LPARAM) &lvcolumn) == -1)
iResult = 0; else iResult = 1;
// Paints (updates) the client area of the ListView control:
InvalidateRect(hwndListView, &rect, TRUE);
// Returns either 1 (OK) or 0 (failed to insert column - e.g.,
// lCol too big):
return(iResult);
}
int WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR args, int nCmdShow)
{
hInst = hInstance;
INITCOMMONCONTROLSEX initCC = { sizeof(INITCOMMONCONTROLSEX) };
initCC.dwICC = ICC_STANDARD_CLASSES;
InitCommonControlsEx(&initCC);
WNDCLASS wc;
MSG msg;
InitCommonControls();
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
wc.lpszMenuName = NULL;
wc.lpszClassName = AppTitle;
if (!RegisterClass(&wc))
return 0;
hwnd = CreateWindowEx( WS_EX_ACCEPTFILES,AppTitle, AppTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 500,NULL, NULL, hInst, NULL);
if(!hwnd)
return 0;
RECT rcl;
GetClientRect (hwnd, &rcl);
HWND hWndListView = CreateWindowEx(0,WC_LISTVIEW,
L"",
WS_VISIBLE | WS_CHILDWINDOW ,
0,
0,
rcl.right - rcl.left,
rcl.bottom - rcl.top,
hwnd,
NULL,
(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
NULL);
fInsertListViewColumn(hWndListView, 0, 30,L"First");
fInsertListViewColumn(hWndListView, 1, 30,L"Second");
fInsertListViewItem(hWndListView, 0, 0, 0, L"Hello");
fInsertListViewItem(hWndListView, 0, 1, 1, L"World");
fInsertListViewItem(hWndListView, 1, 0, 0, L"1Hello");
fInsertListViewItem(hWndListView, 1, 1, 1, L"1World1");
SetView(hWndListView, LV_VIEW_TILE);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while( GetMessage(&msg, NULL, 0, 0)>0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wparam, lparam);
}
return 0;
}
Заранее спасибо за помощь