#include <windows.h>
#include "resource\resource.h"
#pragma comment(lib,"COMCTL32.LIB");
#include <commctrl.h>
#include <stdio.h>
//==============Global Vatriabls===================
static HWND hList=NULL; // List View identifier
LVCOLUMN LvCol; // Make Coluom struct for ListView
LVITEM LvItem; // ListView Item struct
LV_DISPINFO lvd;
int iSelect=0;
int index=0;
int flag=0;
HWND hEdit;
bool escKey=0;
char tempstr[100]="";
TCHAR tchar;
MSG msg;
//===================================================
//======================Handles================================================//
HINSTANCE hInst; // main function handler
#define WIN32_LEAN_AND_MEAN // this will assume smaller exe
LRESULT ProcessCustomDraw (LPARAM lParam)
{
LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
switch(lplvcd->nmcd.dwDrawStage)
{
case CDDS_PREPAINT : //Before the paint cycle begins
//request notifications for individual listview items
return CDRF_NOTIFYITEMDRAW;
case CDDS_ITEMPREPAINT: //Before an item is drawn
{
return CDRF_NOTIFYSUBITEMDRAW;
}
break;
case CDDS_SUBITEM | CDDS_ITEMPREPAINT: //Before a subitem is drawn
{
switch(lplvcd->iSubItem)
{
case 0:
{
lplvcd->clrText = RGB(255,255,255);
lplvcd->clrTextBk = RGB(240,55,23);
return CDRF_NEWFONT;
}
break;
case 1:
{
lplvcd->clrText = RGB(255,255,0);
lplvcd->clrTextBk = RGB(0,0,0);
return CDRF_NEWFONT;
}
break;
case 2:
{
lplvcd->clrText = RGB(20,26,158);
lplvcd->clrTextBk = RGB(200,200,10);
return CDRF_NEWFONT;
}
break;
case 3:
{
lplvcd->clrText = RGB(12,15,46);
lplvcd->clrTextBk = RGB(200,200,200);
return CDRF_NEWFONT;
}
break;
case 4:
{
lplvcd->clrText = RGB(120,0,128);
lplvcd->clrTextBk = RGB(20,200,200);
return CDRF_NEWFONT;
}
break;
case 5:
{
lplvcd->clrText = RGB(255,255,255);
lplvcd->clrTextBk = RGB(0,0,150);
return CDRF_NEWFONT;
}
break;
}
}
}
return CDRF_DODEFAULT;
}
//================================About dialog window=============================//
BOOL CALLBACK DialogProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
// This Window Message will close the dialog //
//============================================//
case WM_CLOSE:
{
PostQuitMessage(0);
EndDialog(hWnd,0); // kill dialog
}
break;
case WM_NOTIFY:
{
switch(LOWORD(wParam))
{
case IDC_LIST:
LPNMLISTVIEW pnm = (LPNMLISTVIEW)lParam;
if(pnm->hdr.hwndFrom == hList &&pnm->hdr.code == NM_CUSTOMDRAW)
{
SetWindowLong(hWnd, DWL_MSGRESULT, (LONG)ProcessCustomDraw(lParam));
return TRUE;
}
if(((LPNMHDR)lParam)->code == NM_DBLCLK)
{
char Text[255]={0};
char Temp[255]={0};
char Temp1[255]={0};
int iSlected=0;
int j=0;
iSlected=SendMessage(hList,LVM_GETNEXTITEM,-1,LVNI_FOCUSED);
if(iSlected==-1)
{
MessageBox(hWnd,"No Items in ListView","Error",MB_OK|MB_ICONINFORMATION);
break;
}
memset(&LvItem,0,sizeof(LvItem));
LvItem.mask=LVIF_TEXT;
LvItem.iSubItem=0;
LvItem.pszText=Text;
LvItem.cchTextMax=256;
LvItem.iItem=iSlected;
SendMessage(hList,LVM_GETITEMTEXT, iSlected, (LPARAM)&LvItem);
sprintf(Temp1,Text);
for(j=1;j<=5;j++)
{
LvItem.iSubItem=j;
SendMessage(hList,LVM_GETITEMTEXT, iSlected, (LPARAM)&LvItem);
sprintf(Temp," %s",Text);
lstrcat(Temp1,Temp);
}
MessageBox(hWnd,Temp1,"test",MB_OK);
}
if(((LPNMHDR)lParam)->code == NM_CLICK)
{
iSelect=SendMessage(hList,LVM_GETNEXTITEM,-1,LVNI_FOCUSED);
if(iSelect==-1)
{
break;
}
index=iSelect;
flag=1;
}
if(((LPNMHDR)lParam)->code == LVN_BEGINLABELEDIT)
{
//Editing=1;
hEdit=ListView_GetEditControl(hList);
GetWindowText(hEdit, tempstr, sizeof(tempstr));
}
if(((LPNMHDR)lParam)->code == LVN_ENDLABELEDIT)
{
int iIndex;
char text[255]="";
tchar = (TCHAR)msg.wParam;
if(tchar == 0x1b)
escKey=1;
iIndex=SendMessage(hList,LVM_GETNEXTITEM,-1,LVNI_FOCUSED);
if(iIndex==-1)
break;
LvItem.iSubItem=0;
if(escKey==0)
{
LvItem.pszText=text;
GetWindowText(hEdit, text, sizeof(text));
SendMessage(hList,LVM_SETITEMTEXT,(WPARAM)iIndex,(LPARAM)&LvItem);
}
else{
LvItem.pszText=tempstr;
SendMessage(hList,LVM_SETITEMTEXT,(WPARAM)iIndex,(LPARAM)&LvItem);
escKey=0;
}
//Editing=0;
}
break;
}
}
case WM_PAINT:
{
return 0;
}
break;
// This Window Message is the heart of the dialog //
//================================================//
case WM_INITDIALOG:
{
int i;
char Temp[255];
LVBKIMAGE plvbki={0};
char url[]="C:\\a.jpg";
InitCommonControls();
hList=GetDlgItem(hWnd,IDC_LIST); // get the ID of the ListView
memset(&plvbki,0,sizeof(plvbki));
plvbki.ulFlags=LVBKIF_SOURCE_URL;
plvbki.pszImage=url;
plvbki.xOffsetPercent=40;
plvbki.yOffsetPercent=15;
OleInitialize(NULL);
SendMessage(hList,LVM_SETTEXTBKCOLOR, 0,(LPARAM)CLR_NONE);
SendMessage(hList,LVM_SETBKIMAGE,0,(LPARAM)(LPLVBKIMAGE)&plvbki);
SendMessage(hList,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_FULLROWSELECT); // Set style
SendMessageA(hWnd,WM_SETICON,(WPARAM) 1,(LPARAM) LoadIconA(hInst,MAKEINTRESOURCE(IDI_ICON1)));
// Here we put the info on the Coulom headers
// this is not data, only name of each header we like
memset(&LvCol,0,sizeof(LvCol)); // Reset Coluom
LvCol.mask=LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM; // Type of mask
LvCol.cx=0x28; // width between each coloum
LvCol.pszText="Item"; // First Header
LvCol.cx=0x42;
// Inserting Couloms as much as we want
SendMessage(hList,LVM_INSERTCOLUMN,0,(LPARAM)&LvCol); // Insert/Show the coloum
LvCol.pszText="Sub Item1";
评论1
最新资源