Click to See Complete Forum and Search --> : listview problem


jo-the-ripper
February 15th, 2007, 12:44 PM
Hi. I hav some problems with my listview. All works great...but the if i use the ListView_HitTest the DragQueryFile doesn't work corectly anymore.


#include <Windows.h>
#include <StdIO.h>
#include <commctrl.h>
#pragma comment(lib,"Comctl32.lib")
#include "resource.h"

HWND hwnd, hwndLV1;
static PrevWndProcList;


LVITEM LvItem1 = {0};
LVCOLUMN lvColumn1;
LVCOLUMN lvColumn2;
LVCOLUMN lvColumn3;

static int n = 0;

HINSTANCE g_hInst;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ListWndProc(HWND, UINT, WPARAM, LPARAM);

int Create2ColItem(HWND hwndLV1, char *Text1, char *Text2, char *Text3, int iItem)
{
//MessageBox (NULL, n,0, MB_ICONERROR) ;
LVITEM LvItem = {0};


if(iItem==-1)
{
iItem=SendMessage(hwndLV1,LVM_GETITEMCOUNT,0,0);
}

LvItem.iItem = (iItem+1);
//LvItem.iSubItem=0;

LvItem.mask = LVIF_TEXT;
LvItem.pszText = Text1;
ListView_InsertItem(hwndLV1, &LvItem);

return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance,
PSTR szCmdLine, int iCmdShow)
{
InitCommonControls();
static TCHAR szAppName[] = TEXT("LeWi-Player");
MSG msg;
g_hInst=hInstance;

WNDCLASS wndclass;

wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = 0;
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)COLOR_WINDOW;
wndclass.lpszClassName = szAppName;
wndclass.lpszMenuName = NULL;

RegisterClass(&wndclass);

wndclass.lpfnWndProc = ListWndProc;

RegisterClass(&wndclass);

hwnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,szAppName, TEXT("LeWi-Player"), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
350, 300,
NULL, NULL, hInstance, NULL);

ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);

DragAcceptFiles (hwndLV1, true);

while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return msg.lParam;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{

switch (message)
{

case WM_CREATE:
{
hwndLV1 = CreateWindowEx(0, WC_LISTVIEW,"ListView",WS_VISIBLE | WS_CHILD | WS_BORDER |WS_VSCROLL| LVS_REPORT,
0,0,350,300,
hwnd,NULL,g_hInst,NULL);

PrevWndProcList = SetWindowLong (hwndLV1, GWL_WNDPROC, (LONG)ListWndProc);

ListView_SetExtendedListViewStyle(hwndLV1,LVS_EX_FULLROWSELECT);

lvColumn1.mask = LVCF_TEXT|LVCF_WIDTH;
lvColumn1.cx = 50;
lvColumn1.pszText = "col1";
ListView_InsertColumn(hwndLV1,0,&lvColumn1);

lvColumn2.mask = LVCF_TEXT|LVCF_WIDTH;
lvColumn2.cx = 50;
lvColumn2.pszText = "col2";
ListView_InsertColumn(hwndLV1,1,&lvColumn2);

lvColumn3.mask = LVCF_TEXT|LVCF_WIDTH;
lvColumn3.cx = 50;
lvColumn3.pszText = "col3";
ListView_InsertColumn(hwndLV1,2,&lvColumn3);



return 0;
}

case WM_SIZE:
{
MoveWindow(hwndLV1, 1, 1,LOWORD(lParam)-1, HIWORD(lParam) - 1, TRUE);
return 0;
}


case WM_DESTROY:
PostQuitMessage (0);
return 0;
}

return DefWindowProc (hwnd, message, wParam, lParam);
}

LRESULT CALLBACK ListWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DROPFILES:
{
char ProzentBuf2[12];
HDROP query = (HDROP) wParam;
POINT pt;
char c[512];
int index1 = 0;

int count = DragQueryFile(query, 0xFFFFFFFF, 0, 0 );

while ( n < count )
{



DragQueryFile(query, n, c, 512);
DragQueryPoint (query, &pt);

index1 = ListView_HitTest(hwndLV1, &pt);

Create2ColItem(hwnd, c, "", "", index1);
n++;
}

DragFinish (query);

return 0;
}
}

return CallWindowProc ((WNDPROC) PrevWndProcList, hwnd, message, wParam, lParam);
}

kkez
February 15th, 2007, 02:20 PM
Please use [/code] at the end and [code] at the beginning of the code. It's impossible to read unformatted code.