Results 1 to 8 of 8

Thread: Type Cast Error

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    Question Type Cast Error

    This is the error I get with the ListView_SortItems() macro:
    Code:
    Compiling...
    CListView.cpp
    C:\Documents and Settings\youngwe\Desktop\ListViewold\ListView\ListView\CListView.cpp(87) : error C2440: 'type cast' : cannot convert from '' to 'int (__stdcall *)(long,long,long)'
            None of the functions with this name in scope match the target type
    Error executing cl.exe.
    Code:
    // CListView.h
    
    #ifndef __CLISTVIEW_H__
    #define __CLISTVIEW_H__
    
    
    
    #include <windows.h>
    #include <commctrl.h>
    
    
    class CListView
    {
    protected:
    	bool bSortAscend;
    	int nColumns;
    	int nLastCol;
    	LVCOLUMN lvColumn;
    	LVITEM lvItem;
    	LVITEM lvFindItem;
    	LVFINDINFO lvFindInfo;
    	NMLISTVIEW *nmListView;
    	HWND hWndListView;
    	INITCOMMONCONTROLSEX initCommCtls;
    
    public:
    	CListView();
    	void SetHwnd(HWND& hWnd, int nIDDlgItem);
    	void SetColumns(int nCount, int nSize[], char* szText[]);
    	void InsertRow(char* szText[]);
    	void SortItems(LPARAM lParam);
    	INT CALLBACK CompareString(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
    
    };
    
    
    #endif // __CLISTVIEW_H__
    Code:
    // CListView.cpp
    
    #include "CListView.h"
    
    
    CListView::CListView()
    {
    	initCommCtls.dwICC = ICC_LISTVIEW_CLASSES;
    	initCommCtls.dwSize = sizeof(INITCOMMONCONTROLSEX);
    	InitCommonControlsEx(&initCommCtls);
    	
    	lvColumn.mask = LVCF_TEXT | LVCF_WIDTH;
    	lvItem.mask = LVIF_TEXT | LVIF_PARAM;
    	lvItem.iSubItem = 0;
    	
    	nColumns = 0;
    	bSortAscend = false;
    	
    }
    
    
    void CListView::SetHwnd(HWND& hWnd, int nIDDlgItem)
    {
    	hWndListView = GetDlgItem(hWnd, nIDDlgItem);
    }
    
    
    void CListView::SetColumns(int nCount, int nSize[], char* szText[])
    {
    	nColumns = nCount;
    	
    	for(int i = 0; i < nCount; i++)
    	{
    		lvColumn.cx = nSize[i];
    		lvColumn.pszText = szText[i];
    		ListView_InsertColumn(hWndListView, i, &lvColumn);
    	}
    	
    	
    }
    
    
    
    void CListView::InsertRow(char* szText[])
    {
    	int nCount = ListView_GetItemCount(hWndListView);
    
    	lvItem.iItem = lvItem.lParam = nCount;
    	lvItem.pszText = szText[0];
    
    	ListView_InsertItem(hWndListView, &lvItem);
    	
    	for(int i = 1; i < nColumns; i++)
    	{
    		ListView_SetItemText(hWndListView, nCount, i, szText[i]);
    	}
    }
    
    
    void CListView::SortItems(LPARAM lParam)
    {
    	
    	nmListView = (LPNMLISTVIEW)lParam;
    	
    	if(nmListView->hdr.code == LVN_COLUMNCLICK)
    	{		
    		
    		if(nLastCol != nmListView->iSubItem)
    		{
    			bSortAscend = false;
    		}
    		
    		
    		ListView_SortItems(nmListView->hdr.hwndFrom, 
    /*problems here ------>*/ (PFNLVCOMPARE)CompareString, nmListView->iSubItem);
    
    		
    		if(bSortAscend)
    		{
    			bSortAscend = false;
    		}
    		else
    		{
    			bSortAscend = true;
    		}
    		
    	}
    	
    }
    
    
    
    
    INT CALLBACK CListView::CompareString(LPARAM lParam1, LPARAM lParam2, 
    								   LPARAM lParamSort)
    {
    	
    	char szText1[32];
    	char szText2[32];
    	int iIndex;
    	
    	lvFindInfo.lParam = lParam1;
    	iIndex = ListView_FindItem(hWndListView, -1, &lvFindInfo);
    	ListView_GetItemText(hWndListView, iIndex, (INT)lParamSort, (LPTSTR)szText1, 16);
    	
    	lvFindInfo.lParam = lParam2;
    	iIndex = ListView_FindItem(hWndListView, -1, &lvFindInfo);
    	ListView_GetItemText(hWndListView, iIndex, (INT)lParamSort, (LPTSTR)szText2, 16);
    	
    	if(bSortAscend)
    	{
    		return -strcmp(szText1, szText2);
    	}
    	else
    	{
    		return strcmp(szText1, szText2);
    	}	
    	
    	return 0;
    
    }
    Code:
    // main.cpp
    
    #include "CListView.h"
    #include "resource.h"
    
    
    CListView cList;
    
    
    BOOL CALLBACK DialogProc(HWND hWnd, UINT uMsg, 
    						 WPARAM wParam, LPARAM lParam)
    {
    	
    	switch(uMsg)
    	{
    	case WM_INITDIALOG:
    		{
    
    			cList.SetHwnd(hWnd, IDC_LIST1);
    
    			char* szText[3] = {"Column 1", "Column 2", "Column 3"};
    			int nSize[3] = {100, 75, 75};
    
    			cList.SetColumns(3, nSize, szText);
    
    			szText[0] = "aaaaxkkjlj";
    			szText[1] = "04/24/2002";
    			szText[2] = "99";
    
    			cList.InsertRow(szText);
    			
    			szText[0] = "edkkljkjk";
    			szText[1] = "10/18/2002";
    			szText[2] = "11";
    
    			cList.InsertRow(szText);
    
    			szText[0] = "kjdkdjdkdj";
    			szText[1] = "07/29/1977";
    			szText[2] = "22";
    
    			cList.InsertRow(szText);
    
    
    			ShowWindow(hWnd, SW_SHOW);
    			break;
    		}
    	case WM_CLOSE:
    		{
    			PostQuitMessage(0);
    			break;
    		}
    	case WM_NOTIFY:
    		{
    			cList.SortItems(lParam);
    			
    			break;
    		}
    
    	default:
    		{
    			return FALSE;
    		}
    	}
    	
    	return FALSE;
    }
    
    
    
    INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
    				   LPSTR lpszArgument, INT iCmdShow)
    {
    	
    	MSG msg;
    	HWND hWndDialog;
    	
    	hWndDialog = CreateDialog(hInstance, (LPCTSTR)IDD_DIALOG1, NULL, (DLGPROC)DialogProc);
    	
    	while(GetMessage(&msg, NULL, 0, 0))
    	{
    		if(!IsDialogMessage(hWndDialog, &msg))
    		{
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
    	}
    	
    	return msg.wParam;
    	
    }
    What is going on here?
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width