Dropdown in CListCtrl



  • Hallo Leute

    Ich habe hier etwas gefunden wie man DropDown in einem
    CLsitCtrl einbauen kann.
    http://www.codeproject.com/listctrl/CustomizedReportListCtrl.asp?df=100&forumid=30664&select=1707255&msg=1707255

    Ich versuche das gerade zu verstehen und habe dazu den
    Cource heruntergeladen . Wenn ich diesen jedoch kompiliere
    kommen foögende Fehlermeldungen:

    Kompilieren...
    InPlaceCombo.cpp
    c:\visual studio 2005\projects\listctrl\inplacecombo.h(63) : error C4430: Fehlender Typspezifizierer - int wird angenommen. 
    Hinweis: "default-int" wird von C++ nicht unterstützt.
    InPlaceEdit.cpp
    c:\visual studio 2005\projects\listctrl\inplaceedit.h(70) : error C4430: Fehlender Typspezifizierer - int wird angenommen. 
    Hinweis: "default-int" wird von C++ nicht unterstützt.
    c:\visual studio 2005\projects\listctrl\inplaceedit.cpp(47) : error C2440: 'static_cast': 'void (__thiscall CInPlaceEdit::* )(WPARAM,LPARAM)' 
    kann nicht in 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)' konvertiert werden
            Keine Funktion mit diesem Namen im Gültigkeitsbereich stimmt mit dem Zieltyp überein
    Code wird generiert...
    

    undsoweiter .

    Es wird ein Typspezifizierer vor Operator erwartet.
    Nun habe ich einen ganzen abend damit verbracht
    jedoch komme ich nicht weiter .
    Kann jemand helfen ??

    Danke im Voraus
    Gruß Linus



  • Zeig mal die Codezeilen, die dazugehören.
    Ich wollte diese Klassen auch nutzen und habe VIEL daran gebastelt - aber evtl. stimmt die Stelle noch. Bei mir kompilierts jedenfalls.



  • Ich hab den original source heruntergeladen
    und wollte es kompilieren
    klappt nicht .
    Ich denke es liegt daran , dass sich bei VS 2005
    etwas geändert hat .
    Irgendwo hab ich da auch etws gelesen bzgl überladen
    von Operatoren . Ich weis nur nicht mehr wo ?????

    Trotzdem hier der code der Header Datei wo einer der Fehler auftritt:

    /*******************************************************************************
    	Author						: Aravindan Premkumar
    	Unregistered Copyright 2003	: Aravindan Premkumar
    	All Rights Reserved
    
    	This piece of code does not have any registered copyright and is free to be 
    	used as necessary. The user is free to modify as per the requirements. As a
    	fellow developer, all that I expect and request for is to be given the 
    	credit for intially developing this reusable code by not removing my name as 
    	the author.
    *******************************************************************************/
    
    #if !defined(AFX_INPLACEEDIT_H__175AEDFF_731E_4721_8399_DE406A465861__INCLUDED_)
    #define AFX_INPLACEEDIT_H__175AEDFF_731E_4721_8399_DE406A465861__INCLUDED_
    
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    
    class CInPlaceEdit : public CEdit
    {
    
    public:
    
    // Implementation
    
    	// Returns the instance of the class
    	static CInPlaceEdit* GetInstance(); 
    
    	// Deletes the instance of the class
    	static void DeleteInstance(); 
    
    	// Creates the Windows edit control and attaches it to the object
    	// Shows the edit ctrl
    	BOOL ShowEditCtrl(DWORD dwStyle, const RECT& rCellRect, CWnd* pParentWnd, 
    					  UINT uiResourceID, int iRowIndex, int iColumnIndex,
    					  CString& strValidChars, CString& rstrCurSelection);
    
    // Overrides
    	// ClassWizard generated virtual function overrides
    	//{{AFX_VIRTUAL(CInPlaceEdit)
    	public:
    	virtual BOOL PreTranslateMessage(MSG* pMsg);
    	//}}AFX_VIRTUAL
    
    // Attributes
    
    protected:	
    	// Generated message map functions
    	//{{AFX_MSG(CInPlaceEdit)
    	afx_msg void OnKillFocus(CWnd* pNewWnd);
    	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
    	afx_msg void OnPaste(WPARAM wParam, LPARAM lParam);
    	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    	//}}AFX_MSG
    
    	DECLARE_MESSAGE_MAP()
    
    private:
    
    // Implementation
    
    	// Constructor
    	CInPlaceEdit();
    
    	// Hide the copy constructor and operator =
    	CInPlaceEdit (CInPlaceEdit&) {}
    
    	operator = (CInPlaceEdit) {}     // <=========Hier möchte er einen Typ wissen 
    
    	// Destructor
    	virtual ~CInPlaceEdit();
    
    // Attributes
    
    	// Index of the item in the list control
    	int m_iRowIndex;
    
    	// Index of the subitem in the list control
    	int m_iColumnIndex;
    
    	// To indicate whether ESC key was pressed
    	BOOL m_bESC;
    
    	// Valid characters
    	CString m_strValidChars;
    
    	// Singleton instance
    	static CInPlaceEdit* m_pInPlaceEdit;
    
    	// Previous string value in the edit control
    	CString m_strWindowText;
    };
    
    /////////////////////////////////////////////////////////////////////////////
    
    //{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
    
    #endif // !defined(AFX_INPLACEEDIT_H__175AEDFF_731E_4721_8399_DE406A465861__INCLUDED_)
    

    das gleiche Problem gibt es noch in einer zweiten Header-Datei

    Wäre schön wenn's klappen würde



  • Die Stelle kommt mir bekannt vor, ich glaube, da hab ich damals was angepasst.
    Kann dir den Code aber erst Morgen früh geben - komm jetzt nicht mehr ran.



  • Prima , warte gespannt 😃 😉



  • Hm, also wenn ich das mal geändert habe, dann war es eine Kopie. 🙄

    Aber ich hab in nem schlauen Buch was gefunden:

    Eine Zuweisung repräsentiert immer den zugewisenen Wert. Deshalb ist auch der Return-Wert von operator= eine Referenz und zwar eine Referenz auf das aktuelle Objekt.
    Damit hat operator= folgenden Prototyp:

    Klassenname& operator= (const Klassenname&);
    

    Quelle (S.161):
    OOP mit C++ | ISBN: 3898423328

    Daher sollte es mit diesem Code klappen:

    CInPlaceEdit& operator = (CInPlaceEdit&) {}
    

    🙂



  • Sorry für die späte Antwort.

    Genau das Zitat hatte ich irgendwo gesehen.
    Und es funktioniert . Danke.

    Bei einer weiteren Fehlermeldung habe ich dann

    afx_msg void OnPaste(WPARAM wParam, LPARAM lParam);
    

    durch

    afx_msg [b]LRESULT[/b] OnPaste(WPARAM wParam, LPARAM lParam);
    

    und entsprechend die Rückgabewerte von OnPaste geändert

    jetz läufts einwandfrei

    Danke für Deine Hilfe
    Gruß Linus



  • Dann poste doch mal die Info auf Codeproject. 😋



  • Quam schrieb:

    Dann poste doch mal die Info auf Codeproject. 😋

    Hab ich gemacht.

    Jetzt stehe ich aber vor dem Problem :

    Wie funktioniert das denn in meinem Projekt ???
    Die Dateien habe ich eingefügt .
    CListCtrl in CComboListCtrl geändert

    ON_MESSAGE.. per Hand (?) eingefügt
    mein source sieht jetzt so aus:

    // Dlg_Rights.cpp: Implementierungsdatei
    //
    
    #include "stdafx.h"
    #include "HSVerein.h"
    #include "Dlg_Rights.h"
    
    // CDlg_Rights-Dialogfeld
    
    IMPLEMENT_DYNAMIC(CDlg_Rights, CDialog)
    
    CDlg_Rights::CDlg_Rights(CWnd* pParent /*=NULL*/)
    	: CDialog(CDlg_Rights::IDD, pParent)
    	, m_iItemCount(0)
    {
    
    }
    
    CDlg_Rights::~CDlg_Rights()
    {
    }
    
    void CDlg_Rights::DoDataExchange(CDataExchange* pDX)
    {
    	CDialog::DoDataExchange(pDX);
    	DDX_Control(pDX, IDC_LIST1, m_ctrl_combolist);
    }
    
    BEGIN_MESSAGE_MAP(CDlg_Rights, CDialog)
    	ON_MESSAGE(WM_VALIDATE, OnEndLabelEditVariableCriteria)
    	ON_MESSAGE(WM_SET_ITEMS, PopulateComboList)
    END_MESSAGE_MAP()
    
    // CDlg_Rights-Meldungshandler
    
    BOOL CDlg_Rights::OnInitDialog()
    {
    	CDialog::OnInitDialog();
    
    	// TODO:  hier zusätzliche Initialisierung hinzufügen.
    	m_ctrl_combolist.InsertColumn(0, "User", LVCFMT_LEFT, 150);
    	m_ctrl_combolist.InsertColumn(1, "Titel1", LVCFMT_LEFT, 50);
    	m_ctrl_combolist.InsertColumn(2, "Titel2", LVCFMT_LEFT, 50);
    	m_ctrl_combolist.InsertColumn(3, "Titel3", LVCFMT_LEFT, 50);
    	m_ctrl_combolist.InsertColumn(4, "Titel4", LVCFMT_LEFT, 50);
    	m_ctrl_combolist.InsertColumn(5, "Titel5", LVCFMT_LEFT, 50);
    	m_ctrl_combolist.SetReadOnlyColumns(0);
    	m_ctrl_combolist.SetComboColumns(1);
    	m_ctrl_combolist.SetComboColumns(2);
    	m_ctrl_combolist.SetComboColumns(3);
    	m_ctrl_combolist.SetComboColumns(4);
    	m_ctrl_combolist.SetComboColumns(4);
    	m_ctrl_combolist.EnableVScroll(); 
    
    	m_ctrl_combolist.SetExtendedStyle(LVS_EX_FULLROWSELECT);
    
    //	SendMessage(WM_SET_ITEMS)  ?????
    
    	return TRUE;  // return TRUE unless you set the focus to a control
    	// AUSNAHME: OCX-Eigenschaftenseite muss FALSE zurückgeben.
    }
    
    LRESULT CDlg_Rights::OnEndLabelEditVariableCriteria(WPARAM wParam, LPARAM lParam) 
    {
    	LV_DISPINFO* pDispInfo = (LV_DISPINFO*)lParam;
    	// TODO: Add your control notification handler code here
    
    	if (wParam == IDC_LIST1)
    	{
    		// Update the item text with the new text
    		CString strUpdatedTxt = pDispInfo->item.pszText;  
    
    		// Validate the format of the new string for the edit columns
    		// If invalid then
    		// Set pResult to 1 
    		switch(pDispInfo->item.iSubItem)
    		{
    		case 0:
    		case 1:
    			break;
    		default:
    			{
    				if (!strUpdatedTxt.IsEmpty()) 
    				{
    					// Get the left most non numeral characters
    					// Get the remaining numerals
    					// If the left most part does not contain the mandatory conditions 
    					// Or the rest contains the mandatory conditions 
    					// Display an error and set focus back onto the control
    					int iFirstNumeralOccurrance = strUpdatedTxt.FindOneOf("0123456789.");
    					CString strNonNumerals = strUpdatedTxt.Left(iFirstNumeralOccurrance);
    					CString strNumerals = strUpdatedTxt.Mid(iFirstNumeralOccurrance);
    
    					strNonNumerals.TrimLeft(); 
    					strNonNumerals.TrimRight();
    					strNumerals.TrimLeft();
    					strNumerals.TrimRight();  
    
    					int iDecimalIndex = strNumerals.Find(".");
    
    					if ((-1 != iDecimalIndex) && (iDecimalIndex != (strNumerals.GetLength() - 1)))  
    					{
    						iDecimalIndex = strNumerals.Find(".", iDecimalIndex + 1);
    					}
    
    					// Check that the condition is either
    					// Not empty or "=" or "!=" or "<" or ">" or "<=" or ">="
    					// The Numerals do not contain 
    					// Space or more than 1 "." or any of the conditions
    					if (
    						(!strNonNumerals.IsEmpty()) || 
    						(-1 != strNumerals.Find(" ")) ||
    						(-1 != iDecimalIndex)
    						)
    					{
    						AfxMessageBox("Invalid text entered. The text will be reset"); 
    						m_ctrl_combolist.SetItemText(pDispInfo->item.iItem, pDispInfo->item.iSubItem, "");
    					}
    					return 0;
    				}
    			}
    			break;
    		}
    	}
    
    	return 1;
    }
    
    LRESULT CDlg_Rights::PopulateComboList(WPARAM wParam, LPARAM lParam)
    {
    	// Get the Combobox window pointer
    	CComboBox* pInPlaceCombo = static_cast<CComboBox*> (GetFocus());
    
    	// Get the inplace combbox top left
    	CRect obWindowRect;
    
    	pInPlaceCombo->GetWindowRect(&obWindowRect);
    
    	CPoint obInPlaceComboTopLeft(obWindowRect.TopLeft()); 
    
    	// Get the active list
    	// Get the control window rect
    	// If the inplace combobox top left is in the rect then
    	// The control is the active control
    	m_ctrl_combolist.GetWindowRect(&obWindowRect);
    
    	int iColIndex = wParam;
    
    	CStringList* pComboList = reinterpret_cast<CStringList*>(lParam);
    	pComboList->RemoveAll(); 
    
    	if (obWindowRect.PtInRect(obInPlaceComboTopLeft)) 
    	{
    		if (1 == iColIndex)
    		{
    			pComboList->AddTail("Item 1");
    			pComboList->AddTail("Item 2");
    			pComboList->AddTail("Item 3");
    		}
    		if (2 == iColIndex)
    		{
    			pComboList->AddTail("gut");
    			pComboList->AddTail("voll");
    			pComboList->AddTail("none");
    		}
    	}
    
    	return true;
    }
    

    Nun heisst es :

    The WM_SET_ITEMS message is posted using ::SendMessage() to the parent.
    

    Do wo und mit welchen Parametern sende ich diese Nachricht ??
    😕
    Vielleicht hat das ja mal jemand eingesetzt und kann mir helfen ?
    Gruß Linus


Anmelden zum Antworten