Need some help with my own ClistCtrl derived class

Hello,
I main class is called CWaageDialog, and I have a subclass MousOverLístCtrl_WaageDialog
for my ClistCtrl.

in my subclass I have the following function:OnNcCalcSize
I have a member value in CWaageDialog m_Angeklickt.
How can I get access of this m_Angeklickt in my subclass?
500 points with a solution.
Thank you.
Best regards,
Thomas

void CMouseOverListCtrl_Waage::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
{
	if(CWaageDialog::m_Angeklickt==true)------>will not work
	{
        ModifyStyle(WS_HSCROLL,0);
	    ModifyStyle(WS_VSCROLL,0);
	}

	CListCtrl::OnNcCalcSize(bCalcValidRects, lpncsp);
}

Open in new window

Thomas StockbrueggerAsked:
Who is Participating?
 
AndyAinscowFreelance programmer / ConsultantCommented:
OK wee put an extra level ob brackets in

 if(  ( (CWaageDialog*)(GetParent()) )->m_Angeklickt==true)
0
 
Julian HansenCommented:
Why are you accessing m_Angeklickt statically - that only works for constants as there is no instantiated instance of the class to store the variable?

Somewhere you need to maintain a reference to the CWaageDialog class and then access the m_Angeklickt variable through that.
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
If it is subclassed then you should require the following:
if(m_Angeklickt==true)
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
AndyAinscowFreelance programmer / ConsultantCommented:
ps.   How can I get access of this m_Angeklickt in my subclass?
I hope you mean the compiler gives an error at
if(CWaageDialog::m_Angeklickt==true)
or do you mean your code runs BUT doesn't do what you expect?
0
 
Thomas StockbrueggerAuthor Commented:
if(CWaageDialog::m_Angeklickt==true)
yes ... this is an error

If it is subclassed then you should require the following:
if(m_Angeklickt==true)
will not work, I tried that.... (nicht deklarierter Bezeichner)


I did the folowing:
in CWaageDialog.cpp and CWaageDialog.h
#include CMouseOverListCtrl_Waage.h;


in CWaageDialog.h
//CListCtrl m_List1;
CMouseOverListCtrl_Waage m_List1;  //now the new class
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
You might need to explain more.
What is this variable m_Angeklickt and what relationship does it have to the custom list control ?  (Is it a member of another class for example and used to control the behaviour of all list controls in your app?).
0
 
Thomas StockbrueggerAuthor Commented:
m_Angeklickt is a member of CWaageDialog
CWaageDialog.h
bool m_Angeklickt;

in CWaageDialog when I click on a subitem from the list control I will set m_Angeklickt to true.
The main class is called CWaageDialog, and I have a subclass MousOverLístCtrl_WaageDialog
for my ClistCtrl.
In the subclass I try to remove the scrollbar if m_Angeklickt is true
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
So your listcontrol is a CWaageDialog type of variable?
0
 
Julian HansenCommented:
Can you post the declaration of CWaageDialog and MouseOverListCtrl_WaageDialog.

Somewhere you are missing a reference back to CWaageDialog and the information you have posted is not sufficient for us to see where that is (or isn't as the case may be).
0
 
Thomas StockbrueggerAuthor Commented:
WaageDialog.h
-----------------
#pragma once
#include "afxcmn.h"
#include "auftraege.h"
#include "AuftragsHistory.h"
#include "afxwin.h"
#include "MouseOverListCtrl_Waage.h"

// CWaageDialog-Dialogfeld

class CWaageDialog : public CDialog
{
	DECLARE_DYNAMIC(CWaageDialog)

public:
	CWaageDialog(CWnd* pParent = NULL);   // Standardkonstruktor
	virtual ~CWaageDialog();

// Dialogfelddaten
	enum { IDD = IDD_DIALOG_WAAGE };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV-Unterstützung

	DECLARE_MESSAGE_MAP()
 
	
public:
	afx_msg void OnOK();
	afx_msg void OnBnClickedOk();
protected:
	virtual void PostNcDestroy();
public:
	afx_msg void OnCancel();
	afx_msg void OnBnClickedCancel();
	afx_msg void OnClose();
	virtual BOOL OnInitDialog();


    //---------- neue Klasse für Waagedaten Textdatei Listenelement ------
    CMouseOverListCtrl_Waage m_List1;
	//CListCtrl m_List1;
  
    //----------------------------------------------------------
	
	afx_msg void OnNMClickList2(NMHDR *pNMHDR, LRESULT *pResult);
	 
	bool m_Angeklickt;
};






 CMouseOverListCtrl_Waage.h
----------------------------

#pragma once

class CMouseOverListCtrl_Waage : public CListCtrl
{
	DECLARE_DYNAMIC(CMouseOverListCtrl_Waage)

public:
	CMouseOverListCtrl_Waage();
	virtual ~CMouseOverListCtrl_Waage();

protected:
	DECLARE_MESSAGE_MAP()
public:
 
	afx_msg void OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp);

	 
	
};




// MouseOverListCtrl_Waage.cpp : Implementierungsdatei

#include "stdafx.h"
#include "Stockbruegger.h"
#include "MouseOverListCtrl_Waage.h"
#include ".\mouseoverlistctrl_waage.h"

IMPLEMENT_DYNAMIC(CMouseOverListCtrl_Waage, CListCtrl)
CMouseOverListCtrl_Waage::CMouseOverListCtrl_Waage()
{
}

CMouseOverListCtrl_Waage::~CMouseOverListCtrl_Waage()
{
}


BEGIN_MESSAGE_MAP(CMouseOverListCtrl_Waage, CListCtrl)
 
	ON_WM_NCCALCSIZE()
END_MESSAGE_MAP()



//########################################################################
void CMouseOverListCtrl_Waage::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
{
	if(m_Angeklickt==true)
	{

          ModifyStyle(WS_HSCROLL,0);
	    ModifyStyle(WS_VSCROLL,0);
	}

	CListCtrl::OnNcCalcSize(bCalcValidRects, lpncsp);
}
//########################################################################

Open in new window

0
 
Thomas StockbrueggerAuthor Commented:
I even don´t know if I do the right thing with subclassing.
When I click on a subitem of my listcontrol in OnNMClickList() I would like to have no scrollbar horz and vert.
0
 
Julian HansenCommented:
Ok you have subclassed a ListCtrl but your CWaageDialog is a Dialog class - nowhere have you linked the two - the members of CWaageDialog are not going to be accessible from the CMouseOverListCtrl_Waage class unless you expressly link them through a member variable

Somewhere in your initialisation code you need to do something like

m_List1.setDialog(this);

create the setDialog member function in CMouseOverListCtrl_Waage and store the passed Dialog in a local member
CWaageDialog m_parent;

Then in your OnNMClickList you access the m_Angeklickt like so

m_parent.m_Angeklickt == true
0
 
Thomas StockbrueggerAuthor Commented:
can you give me some more info

where should I place this in .h or in .cpp ?
m_List1.setDialog(this);

How should the setDialog function has to look like in  CMouseOverListCtrl_Waage ?
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
Does this do what you require?

if((CWaageDialog*)(GetParent())->m_Angeklickt==true)
0
 
Julian HansenCommented:
In your CMouseOverListCtrl_Waage.h file

lass CMouseOverListCtrl_Waage : public CListCtrl
{
  CWaageDialog * m_parent ;
  void setParent(CWaageDialog  * parent);

}

In your .cpp file

CMouseOverListCtro_Waage::setParent(CWaageDialog * parent)
{
    m_parent = parent;
}

Then in your CWaageDialog constructor
..
   m_List1.setDialog(this);

And finally in

void CMouseOverListCtrl_Waage::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
{
	if(m_parent->m_Angeklickt==true)  // Change this
	{
        ModifyStyle(WS_HSCROLL,0);
	    ModifyStyle(WS_VSCROLL,0);
	}

	CListCtrl::OnNcCalcSize(bCalcValidRects, lpncsp);
}

Open in new window

I have no means of testing the code but that is the basic idea of what you need to do.
0
 
Thomas StockbrueggerAuthor Commented:
if((CWaageDialog*)(GetParent())->m_Angeklickt==true)  
code is not correct
also CWaageDialog nicht deklarisierter Bezeichner
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
You would need an
#include "WaageDlg.h"  //or whatever it is called
in the .cpp file for the custom list control.


<What I am doing is using the implicit parent/child relationship of a dialog to the controls it contains rather than an explicit relationship between two classes which JulianH is suggesting - a general technique.>
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
Don't bother responding to this comment:-

Just an aside - Have a think about setting one variable in the parent dialog when any (of the many?) subitem in the list control is clicked.  Is that really what you want?

For me it sounds wierd, but then I don't know what subitem is being clicked.
0
 
Thomas StockbrueggerAuthor Commented:
Hi Andy,
I still get the error

Kompilieren...
MouseOverListCtrl_Waage.cpp
d:\Eigene Dateien\Visual Studio Projects\Stockbruegger-SQL_VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\MouseOverListCtrl_Waage.cpp(41) : error C2039: 'm_Angeklickt': Ist kein Element von 'CWnd'
        c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\afxwin.h(1913): Siehe Deklaration von 'CWnd'

Das Build-Protokoll wurde unter "file://d:\Eigene Dateien\Visual Studio Projects\Stockbruegger-SQL_VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\Debug\BuildLog.htm" gespeichert.
Stockbruegger - 1 Fehler, 0 Warnung(en)



void CMouseOverListCtrl_Waage::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
{
      
       if((CWaageDialog*)(GetParent())->m_Angeklickt==true)       {
          ModifyStyle(WS_HSCROLL,0);
        ModifyStyle(WS_VSCROLL,0);
       }
      

      CListCtrl::OnNcCalcSize(bCalcValidRects, lpncsp);
}


// MouseOverListCtrl_Waage.cpp : Implementierungsdatei
//

#include "stdafx.h"
#include "Stockbruegger.h"
#include "MouseOverListCtrl_Waage.h"
#include ".\mouseoverlistctrl_waage.h"
#include "WaageDialog.h"<----------------------------------- I have encluded the .h file
0
 
Thomas StockbrueggerAuthor Commented:
Just an aside - Have a think about setting one variable in the parent dialog when any (of the many?) subitem in the list control is clicked.  Is that really what you want?

For me it sounds wierd, but then I don't know what subitem is being clicked.

Hi Andy,
look at my other open question from yeserday
Need some help with scrollbar (listcontrol)I just want to try to get rid of these effects.
0
 
Thomas StockbrueggerAuthor Commented:
yes the code works....give you responce tomorrow...right now I can not get access to the data of my listcontrol....the data is coming out of an server closed for today (schon Feierabend im Betrieb) Thanks Thomas
0
 
Thomas StockbrueggerAuthor Commented:
I hope it works and I can remove the scrollbars...schönen Feierabend
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
Danke, gleichfalls.
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
A thought about this question and your other question.

IF I understand you only require this removal of the scrollbars for when you display the edit box to edit a cell in the grid.  So why go this complex way of having a variable in the dialog and attempting to access it from the listcontrol.  When you show/create the edit box remove the scrollbars at the start of that routine.  When you hide/destroy the editbox then you reshow the scrollbars at the end of that routine.
0
 
Thomas StockbrueggerAuthor Commented:
Hello,
if(  ( (CWaageDialog*)(GetParent()) )->m_Angeklickt==true)  no error but will not do the work.
I guess I am missing something here:

void CMouseOverListCtrl_Waage::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
{
	
	 if( ((CWaageDialog*)(GetParent()))->m_Angeklickt==true)
	 {
                  ModifyStyle(WS_HSCROLL,0);
	  ModifyStyle(WS_VSCROLL,0);
	 }
	 

	CListCtrl::OnNcCalcSize(bCalcValidRects, lpncsp);
}


void CWaageDialog::OnNMClickList2(NMHDR *pNMHDR, LRESULT *pResult)
{
	  
	   m_Angeklickt=true;	   
	    int n_Zeile1 = m_List1.GetNextItem(-1,LVNI_SELECTED);
	   int Anzahl = m_List1.GetItemCount();

Open in new window



Where is the bug? What did I wrong. It looks that the m_Angeklickt is not recognized at all.
Please help, thanks
When I remove  if( ((CWaageDialog*)(GetParent()))->m_Angeklickt==true)
I will get the result... no scrollbars....but I would like to get this result if the user clicks on the subitem of the ListControl in OnNMClickList2.
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
You mean the following does work (hide the scrollbars when you click the list control):

void CMouseOverListCtrl_Waage::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
{
	
//	 if( ((CWaageDialog*)(GetParent()))->m_Angeklickt==true)
	 {
                  ModifyStyle(WS_HSCROLL,0);
	  ModifyStyle(WS_VSCROLL,0);
	 }
	 

	CListCtrl::OnNcCalcSize(bCalcValidRects, lpncsp);
}

Open in new window

0
 
Thomas StockbrueggerAuthor Commented:
it should look like thisugly effect if you click on the white barm_List1.ShowScrollBar(SB_BOTH,FALSE)Good Morning Andy,
because with
m_List1.ModifyStyle(NULL, LVS_NOSCROLL);
m_List1.ShowScrollBar(SB_BOTH,FALSE)

I will remove the scrollbar in  OnNMClickList2 but where the Horz bar was it is now white and if I click there the data shows up...perhaps I need to resize the ListCtrl, take a look at the hardcopies
0
 
Thomas StockbrueggerAuthor Commented:
You mean the following does work (hide the scrollbars when you click the list control):

if( ((CWaageDialog*)(GetParent()))->m_Angeklickt==true)
 yes  if I remove the code with m_Angeklickt
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
Do you have the following anywhere:
m_Angeklickt=false

Put a breakpoint on that line, then run your app - maybe the value is being reset before you think it should be.
0
 
Thomas StockbrueggerAuthor Commented:
I removed it, now is nowhere in my code false....but same result...will not work
0
 
Thomas StockbrueggerAuthor Commented:
void CMouseOverListCtrl_Waage::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
{
Andy,
when I use breakpoints on this functions, I will get a stop when the program starts and when it is stops(exit). But I got not stop when I click on a subitems in  void OnNMClickList2(NMHDR *pNMHDR, LRESULT *pResult);
that is the reason the m_Angeklickt is not working.
How can I fix this?
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
I suspected that was the case, but didn't know for certain what you did in other functions.


When you show/create the edit box remove the scrollbars at the start of that routine.  When you hide/destroy the editbox then you reshow the scrollbars at the end of that routine.
0
 
Thomas StockbrueggerAuthor Commented:
Andy, beside the OnNcCalcSize here is the complete code that I use for this.
I got the code from http://www.codeproject.com/Articles/1124/Editing-Sub-Items-in-List-Control
#######################################################################################
void CWaageDialog::OnNMClickList2(NMHDR *pNMHDR, LRESULT *pResult)
{
     m_Angeklickt=true;

    int n_Zeile1 = m_List1.GetNextItem(-1,LVNI_SELECTED);
    int Anzahl = m_List1.GetItemCount();
 
    RECT rect;
    row=0;
    col=0;
   
   m_List1.Invalidate();
     
      
    //--------- ermittele angeklicktes subitem -------------
    HWND hWnd1 =  ::GetDlgItem (m_hWnd,IDC_LIST2);
    LPNMITEMACTIVATE pNMIA = (LPNMITEMACTIVATE) pNMHDR;
    row=pNMIA->iItem;
    col=pNMIA->iSubItem;

    CString str = m_List1.GetItemText(row, col);
   //-----------------------------------------------------
   if (row==-1)
   {
      *pResult = 0;
      return;
  }
  //------------------------------------------------------
//IDC_EDIT99 einblenden
if(col>0 && col<8 )GetDlgItem(IDC_EDIT99)->EnableWindow(TRUE);//aktivieren
//only columns 1 to 7

 
//................................................................
if(col>0 && col<8)
 

    RECT rect1,rect2;
    // this macro is used to retrieve the Rectanle of the selected SubItem
    ListView_GetSubItemRect(hWnd1,pNMIA->iItem,pNMIA->iSubItem,LVIR_BOUNDS,&rect);

    //Get the Rectange of the listControl
    ::GetWindowRect(pNMIA->hdr.hwndFrom,&rect1);

    //--------------------------
   GetClientRect(&rect2);
   ClientToScreen(&rect2);

   int x= rect1.left-rect2.left;
   int y= rect1.top-rect2.top;
   //--------------------------
       
    if(row != -1)
    ::SetWindowPos(::GetDlgItem(m_hWnd,IDC_EDIT99),
    HWND_TOP,x+rect.left+6,y+rect.top+2,rect.right-rect.left-5,rect.bottom-rect.top-1,NULL);
      
    ::ShowWindow(::GetDlgItem(m_hWnd,IDC_EDIT99),SW_SHOW);
      
   //Draw a Rectangle around the SubItem
   HDC hDC=::GetDC(pNMIA->hdr.hwndFrom);
   ::Rectangle(hDC,rect.left,rect.top-1,rect.right,rect.bottom);
   ::ReleaseDC(pNMIA->hdr.hwndFrom,hDC);


    //Set the listItem text in the EditBox
    ::SetWindowText(::GetDlgItem(m_hWnd,IDC_EDIT99),str);
      
 //--------------- Setze Focus auf IDC_EDIT99 --------------------------
    CWnd *pFocus = GetDlgItem(IDC_EDIT99);
    pFocus->SetFocus();
    CEdit* pEdt =((CEdit*)GetDlgItem(IDC_EDIT99));
    ASSERT(pEdt);
    int nPos=-1;
   pEdt->SetSel(0,nPos);
    //----------------------------------------------------------------------
                              
}
 
    *pResult = 0;
      
}
//#####################################################################

BOOL CWaageDialog::PreTranslateMessage(MSG* pMsg)
{
    if(pMsg->message==WM_KEYDOWN)
      {
            if(pMsg->wParam==VK_RETURN)
            {
                  //-------- Ermittle welches Element den Focus hat --------
                  CWnd *pFocus = NULL;
                  pFocus = GetFocus();
                  if(pFocus==NULL)return FALSE;
                  //--------------------------------------------------------

                  //------------- Welches Element hat den Focus ------------
                  int nID = pFocus->GetDlgCtrlID();

                          
                  switch(nID)
                  {  
            //____________________________________________________________

                                case IDC_EDIT99:
                              {
                                    
                                  pFocus = GetDlgItem(IDC_EDIT_AUFTRAG_SUCHEN); // setze Focus auf
                                  pFocus->SetFocus();
                                  //-------------------------------------------
                                  CEdit* pEdt =((CEdit*)GetDlgItem(IDC_EDIT99));
                                  ASSERT(pEdt);
                                                                                    int nPos=-1;
                                   pEdt->SetSel(0,nPos);
                                  //-------------------------------------------
                                 CString str;
                                  GetDlgItemText(IDC_EDIT99,str);
                        
                                   m_List1.Invalidate();
                                   m_List1.UpdateWindow();
                              
                                            m_List1.SetItemText(row,col,str);//int row int col Membervariablen
                                    m_List1.EnableWindow(true);
                               }
                                    
                              //------------------------------------------
                              break;
                              }
           //___________________________________________________________________

                        default:
                         
                            break;
                  }
                  return 0;
            }
      }

      return CDialog::PreTranslateMessage(pMsg);
}
//############################################################
0
 
Thomas StockbrueggerAuthor Commented:
even we got no solution, I will close this case and get you the points for helping me.
I will use the Editbox outside from the List Control...so it dosen´t matter if the user scrolls
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.