如何使用C ++ Winapi(而不是MFC)创建虚拟列表视图 [英] How do I create a Virtual Listview with C++ Winapi(not MFC)
问题描述
亲爱的所有成员,
我想用C ++ Winapi(不是MFC和表单设计师等)创建虚拟列表视图控件,但我不知道真的很了解它。我已经阅读了很多教程,但我没有找到任何解决方案。
我正在使用Dev C ++
我想使用基本Windows样式编程来创建虚拟列表
用户将行和列号放到2个编辑框中,然后按创建列表按钮
这只是我的样本,而不是完整的代码(如果你需要,我当然可以发送完整的代码)
Dear All Members,
I would like to create a virtual listview control with C++ Winapi(not MFC and form designer etc.), but I don't really understand it.I've read a very lot of tutorials but I didn't find any solution.
I'm using Dev C++
I would like using the "base Windows style programming" for create Virtual List
User put the row and coloumn number to 2 editbox and after push "Create list" button
This is only my sample, not the full code(if you need, of course I can send the full code)
//WINDOW FUNCTION PROTOTYPE
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
//WINMAIN
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
//Create the Window class and handle the message loop
}
//Window procedure
LRESULT CALLBACK WndProc(HWND Mainwindow, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_CREATE:
{
//Create button and 2 editbox
break;
}
case WM_COMMAND:
{
/*If user push Button, then program read two parameters from editboxes for rows and
coloumns and create ListView with LVS_REPORT | LVS_OWNERDATA flag
Setup item quantity: ListView_SetItemCount(ListView,rows*cols);
Create and fill Data matrix in memory:
char** matrix = new char*[rows];
for (x=0;x<rows;x++)
{
matrix[x] = new char[cols];
for (int y=0;y<cols;y++)
{
matrix[x][y]="A";
}
}
After that what should I do?Add only coloumns(LVCOLUMN structure) and handle/show
LVITEM structures in WM_NOTIFY?
*/
break;
}
case WM_NOTIFY:
{
//Use LVN_GETDISPINFO & LVN_ODCACHEHINT for showing only 20-30 item from data matrix
break;
}
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
default:
return DefWindowProc(Mainwindow, Message, wParam, lParam);
}
}
如果您有任何想法,请帮助我们:)
提前谢谢!
If you get any idea, please help meee:)
Thank you in advance!
推荐答案
使用虚拟列表 [ ^ ]实际上是基于MFC,但原理是一样的。
Using virtual lists[^] is actually based on MFC, but the principles are just the same.
文档怎么样:如何使用虚拟列表 - 视图控件 [ ^ ]?
列表视图窗口样式 LVS_OWNERDATA 指定虚拟列表视图控件。
有关此列表控件样式的详细信息,请参阅关于列表视图控件。
所以从关于列表视图控件开始
http://msdn.microsoft.com/en-us/library/windows/desktop/bb774735.aspx [ ^ ]
样式LVS_LIST指定列表视图。
The List-View Window Style LVS_OWNERDATA specifies a virtual list-view control.
For more information about this list control style, see "About List-View Controls".
So start with "About List-View Controls"
http://msdn.microsoft.com/en-us/library/windows/desktop/bb774735.aspx[^]
The style LVS_LIST specifies a list view.
1. include <commctrl.h></commctrl.h>
2. link with comctl32.lib
3. Sample (Report)
#include <commctrl.h>
...
InitCommonControls();
hwndList = CreateWindow(WC_LISTVIEW, "",
WS_VISIBLE|WS_BORDER|WS_CHILD | LVS_REPORT | LVS_EDITLABELS,
10, 10, 300, 100,
hWnd, (HMENU)ID_LIST, hInst, 0); </commctrl.h>
(参见:http://www.willemer.de/informatik/windows/winlistv.htm - 德语)
4.创建一个专栏
(see: http://www.willemer.de/informatik/windows/winlistv.htm - german)
4. Create a single column
int CreateColumn(HWND hwndLV, int iCol, char *Text, int iBreite)
{
LVCOLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvc.fmt = LVCFMT_LEFT;
lvc.cx = iBreite;
lvc.pszText = Text;
lvc.iSubItem = iCol;
return ListView_InsertColumn(hwndLV, iCol, &lvc);
}
5.插入一行
5. Insert a single line
int CreateItem(HWND hwndList, char *Text)
{
LVITEM lvi = {0};
lvi.mask = LVIF_TEXT;
lvi.pszText = Text;
return ListView_InsertItem(hwndList, &lvi);
}
这篇关于如何使用C ++ Winapi(而不是MFC)创建虚拟列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!