-
December 12th, 2014, 11:29 AM
#1
ListView extended styles not showing
The gridlines are not appearing on my ListView.
What did I miss?
Code:
#include <windows.h>
#include <commctrl.h>
#include <string>
#include <iostream>
using namespace std;
#pragma comment(lib,"User32.lib")
#pragma comment(lib,"ole32.lib")
#pragma comment(lib,"comctl32.lib")
#pragma comment(lib,"Gdi32.lib")
#define ID_LISTVIEW 667
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
static char sClassName[] = "MyClass";
static HINSTANCE g_hInst = NULL;
/// GLOBALS
static HWND hListView;
LVCOLUMN lvc = {0};
LVITEM lvi = {0};
int r;
int CreateListView(HWND hParent)
{
hListView=
CreateWindowEx(0,WC_LISTVIEW,
NULL,
WS_CHILD | WS_VISIBLE |
LVS_REPORT | LVS_EDITLABELS,
220,
10,
500,
300,
hParent,
(HMENU)ID_LISTVIEW,
g_hInst,
NULL);
ListView_SetExtendedListViewStyle(hListView,
LVS_EX_FULLROWSELECT |
LVS_EX_BORDERSELECT |
LVS_EX_GRIDLINES);
lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH | LVCF_FMT;
lvc.fmt = LVCFMT_LEFT;
/* Add columns to the list-view (first column contains check box). */
lvc.iSubItem = 0;
lvc.cx = 100;
lvc.pszText = TEXT("Name");
ListView_InsertColumn(hListView, 1, &lvc);
lvc.iSubItem = 1;
lvc.cx = 70;
lvc.pszText = TEXT("Episodes");
ListView_InsertColumn(hListView, 2, &lvc);
lvc.iSubItem = 2;
lvc.cx = 150;
lvc.pszText = TEXT("Any Good?");
ListView_InsertColumn(hListView, 3, &lvc);
/* Add some rows. item=rows */
for(int i=0; i<93; i++)
{
lvi.iItem = i;
ListView_InsertItem(hListView, &lvi);
ListView_SetItemText(hListView, i, 0, TEXT("Friends"));
ListView_SetItemText(hListView, i, 1, TEXT("500"));
ListView_SetItemText(hListView, i, 2, TEXT("Alright"));
}
return 0;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam)
{
switch(Message)
{
case WM_CREATE:
/// ///// LISTVIEW ////////////////
r=CreateListView(hwnd);
if(r)
{
return 0;
}
return 0;
case WM_CLOSE:
DestroyWindow(hwnd);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,Message,wParam,lParam);
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
LPSTR lpCmdLine,int nCmdShow)
{
WNDCLASSEX WndClass;
HWND hwnd;
MSG Msg;
g_hInst = hInstance;
WndClass.cbSize = sizeof(WNDCLASSEX);
WndClass.style = NULL;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL,IDC_ARROW);
WndClass.hbrBackground =(HBRUSH)(COLOR_WINDOW+1);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = sClassName;
WndClass.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
if(!RegisterClassEx(&WndClass))
{
MessageBox(0,"Error Registering Class!","Error!",MB_ICONSTOP | MB_OK);
return 0;
}
hwnd = CreateWindowEx(WS_EX_STATICEDGE,
sClassName,
"Tutorial",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
820,440,
NULL,NULL,hInstance,NULL);
if(hwnd == NULL)
{
MessageBox(0,"Error Creating Window!","Error!",MB_ICONSTOP | MB_OK);
return 0;
}
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
-
December 12th, 2014, 11:41 AM
#2
Re: ListView extended styles not showing
Originally Posted by MasterDucky
The gridlines are not appearing on my ListView.
And other extended styles? Do bothe LVS_EX_BORDERSELECT and LVS_EX_GRIDLINES "work"?
Victor Nijegorodov
-
December 12th, 2014, 12:01 PM
#3
Re: ListView extended styles not showing
LVS_EX_FULLROWSELECT and LVS_EX_BORDERSELECT is working.
-
December 12th, 2014, 12:04 PM
#4
Re: ListView extended styles not showing
Originally Posted by MasterDucky
LVS_EX_FULLROWSELECT and LVS_EX_BORDERSELECT is working.
Then, perhaps, your current themes do show the gridlines very bad? Try another theme or, better the classic style!
Victor Nijegorodov
-
December 12th, 2014, 12:38 PM
#5
Re: ListView extended styles not showing
You're right Victor, my theme was the problem!
-
December 12th, 2014, 12:45 PM
#6
Re: ListView extended styles not showing
Originally Posted by MasterDucky
You're right Victor, my theme was the problem!
Well, you are not the first!
And it is the reason I always use the old good classic style!
Victor Nijegorodov
-
December 12th, 2014, 04:38 PM
#7
Re: ListView extended styles not showing
Originally Posted by VictorN
Well, you are not the first!
And it is the reason I always use the old good classic style!
My problem is always that I have no style.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|