Re: CListCtrl derived Class OnDestroy
- From: "Krish" <mohanakrishnan.giridharan@xxxxxxxxx>
- Date: 12 Jan 2007 02:36:30 -0800
As I mentioned earlier, the control is created at design time not at
runtime...
Thanks,
Krish
voidcoder wrote:
It is ok as well. So you mean that control
is created but OnCreate() is never called?
Very strange.
Could you post also the code where you
create the control.
Krish wrote:
Here it is
#if
!defined(AFX_CUSTOMLISTCONTROL_H__17CB1ADC_2CFE_41E8_B31B_3B657D7E53FD__INCLUDED_)
#define
AFX_CUSTOMLISTCONTROL_H__17CB1ADC_2CFE_41E8_B31B_3B657D7E53FD__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// CustomListControl.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CCustomListControl window
class CCustomListControl : public CListCtrl
{
// Construction
public:
CCustomListControl();
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCustomListControl)
//}}AFX_VIRTUAL
// Implementation
public:
void OnDestroy();
void LoadColumnState(CString strFileName);
void SaveColumnState(CString strFileName);
//void SetListParam(int nItem);
// void CleanListParam();
int GetNextSelectedItem (POSITION& pos ) const;
int SubItemHitTest(LPLVHITTESTINFO pInfo );
int GetNextItem(int nItem, int nFlags) const;
LISTCTRLPARAM *pListItemData;
void CallColumnClick(INT mColumn,INT mSortOrder,CString strFileName =
"", BOOL bFlag = FALSE);
void SetInitialColumn(INT mInitialColumn,INT mSortOrder);
void ReorderTaskList();
void DoSortTaskList(UINT uiSubItem, UINT uiColType);
void SetColumns(INT nColCount , CListCtrlColumnInfo arrColInfo[]);
void SetColumnHeaderIcon(UINT uiColCurrent, UINT uiColPrev, UINT
uiSortType);
void SetSubItemSelected(UINT uiSubItemSelected);
virtual ~CCustomListControl();
// Generated message map functions
protected:
//{{AFX_MSG(CCustomListControl)
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
WNDPROC m_pOriginalWndProc;
static LRESULT CALLBACK SubclassWindowProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam);
UINT m_dColCount;
CHeaderCtrl* pHeader;
CImageList *m_pImgListStatus;
BOOL SetTopIndex(int nItem);
INT SearchForItem(CString strItem, INT uiLen, INT nLow, INT nHigh);
INT SearchForNumber(CString strItem, INT uiLen, INT nLow, INT nHigh);
UINT m_uiTimerID;
CString m_szSearchString;
INT m_nSubItemSelected;
INT m_uiSubItemPrev;
enum TimerEvent { EVENT_LIST_CUSTOM_SEARCH = WM_USER };
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately
before the previous line.
#endif //
!defined(AFX_CUSTOMLISTCONTROL_H__17CB1ADC_2CFE_41E8_B31B_3B657D7E53FD__INCLUDED_)
Thanks,
Krish
voidcoder wrote:
Looks ok to me. Please also post your class definition.
Krish wrote:
Here it is
BEGIN_MESSAGE_MAP(CCustomListControl, CListCtrl)
//{{AFX_MSG_MAP(CCustomListControl)
ON_WM_CHAR()
ON_WM_TIMER()
ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnColumnclick)
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
Thanks,
Krish
voidcoder wrote:
Oha! Post your CCustomListCtrl message map here
BEGIN_MESSAGE_MAP
???
END_MESSAGE_MAP
Krish wrote:
No...WM_CREATE of the CCustomListCtrl is not called ...
In your code you have mention to subclass the proc in OnCreate()....but
the OnCreate is not getting called...
Pls advice me
Thanks,
Krish
voidcoder wrote:
It doesn't matter when or how you are creating it.
Once your list ctrl is created, the OnCreate() handler
will be called and the window proc hooked. Just give
it a try.
Krish wrote:
FYI... I am not creating the listctrl dynamically, so WM_CREATE will
never called so the subclass is not done...
Thanks,
Krish
voidcoder wrote:
Oh yes, that is what happens when typing quickly.Correct me if I am wrong
It is impossible because it is impossible. Once
you have subclassed the window:
m_pOriginalWndProc = (WNDPROC)SetWindowLong(m_hWnd,
GWL_WNDPROC, (LONG)SubclassWindowProc);
all the messages will be first routed to the
SubclassWindowProc(). Put a breakpoint into
SubclassWindowProc method and verify that
it is called for every list ctrl message.
Krish wrote:
Correct me if I am wrong
LRESULT CALLBACK CMyListCtrl::WindowProc(HWND hWnd, UINT uMsg, WPARAM
wParam, LPARAM lParam)
{
CMyListCtrl *pThis = (CMyListCtrl *)GetWindowLong(hWnd,
GWL_USERDATA);
if (uMsg == WM_DESTROY)
{
pThis->OnMyDestroyHandler();
}
return CallWindowProc(pThis->m_pOriginalWndProc, hWnd, uMsg,
wParam, lParam);
}
it shd be
LRESULT CALLBACK CMyListCtrl::SubclassWindowProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam)
{
CMyListCtrl *pThis = (CMyListCtrl *)GetWindowLong(hWnd,
GWL_USERDATA);
if (uMsg == WM_DESTROY)
{
pThis->OnMyDestroyHandler();
}
return CallWindowProc(pThis->m_pOriginalWndProc, hWnd, uMsg,
wParam, lParam);
}
if so even here WM_DESTROY is not getting fired...
voidcoder wrote:
Ops, some typos. Check this snippet instead:
class CMyListCtrl : public CListCtrl
{
...
private:
void OnMyDestroyHandler();
WNDPROC m_pOriginalWndProc;
static LRESULT CALLBACK SubclassWindowProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam);
...
};
int CMyListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CListCtrl::OnCreate(lpCreateStruct) == -1)
return -1;
SetWindowLong(m_hWnd, GWL_USERDATA, (LONG)this);
m_pOriginalWndProc = (WNDPROC)SetWindowLong(m_hWnd,
GWL_WNDPROC, (LONG)SubclassWindowProc);
return 0;
}
LRESULT CALLBACK CMyListCtrl::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
CMyListCtrl *pThis = (CMyListCtrl *)GetWindowLong(hWnd, GWL_USERDATA);
if (uMsg == WM_DESTROY)
{
pThis->OnMyDestroyHandler();
}
return CallWindowProc(pThis->m_pOriginalWndProc, hWnd, uMsg, wParam, lParam);
}
void CALLBACK CMyListCtrl::OnMyDestroyHandler()
{
Your destroy handling here
...
...
...
}
voidcoder wrote:
You can always subclass the list ctrl window procedure
to be independent of the MFC messaging issues and get
the destroy event on any parent. Something like this:
class CMyListCtrl : public CListCtrl
{
...
private:
void OnMyDestroyHandler();
WNDPROC m_pOriginalWndProc;
static LRESULT CALLBACK SubclassWindowProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam);
...
};
int CMyListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CListCtrl::OnCreate(lpCreateStruct) == -1)
return -1;
SetWindowLong(m_hWnd, GWL_USERDATA, (LONG)this);
m_pOriginalWndProc = (WNDPROC)SetWindowLong(m_hWnd,
GWL_WNDPROC, (LONG)SubclassWindowProc();
return 0;
}
LRESULT CALLBACK CMyListCtrl::WindowProc(HWND hWnd, UINT uMsg, WPARAM
wParam, LPARAM lParam)
{
CMyListCtrl *pThis = (CMyListCtrl *)SubclassWindowProc(hWnd,
GWL_USERDATA);
if (uMsg == WM_DESTROY)
{
pThis->OnMyDestroyHandler();
}
return CallWindowProc(pThis->m_pOriginalWndProc, hWnd, uMsg, wParam,
lParam);
}
void CALLBACK CMyListCtrl::OnMyDestroyHandler()
{
Your destroy handling here
...
...
...
}
Krish wrote:
Destructor is called but the problem is before that the HWND of the
control is NULL in case of a dialog whereas the HWND has a valid value
in case of a view.
I tried this kind of a setup
CCustomListControl::~CCustomListControl()
{
//For View
if(m_hWnd != NULL)
{
SaveColumnState(m_strFileName);
}
}
//For Dialog
void CCustomListControl::OnDestroy()
{
SaveColumnState(m_strFileName);
CListCtrl::OnDestroy();
// TODO: Add your message handler code here
}
I am overly concerned this will be true in all the cases.
Thanks,
Krish
voidcoder wrote:
Destructors (yes, not events, but still better
than nothing) should definitely work.
If you have some free time to play with it,
you may want to dig into MFC sources to find
what is going on there.
Krish wrote:
Hi,
PostNCDestroy is also not working on CCUstomList when it is on CView
... I am really confused what is the common destroy event which will
work both on CDialog and CView...
Thanks,
Mohan
On Jan 11, 12:54 pm, voidcoder <voidco...@xxxxxxxxx> wrote:
I have just looked through some old projects and can see
that I'm using OnPostNcDestroy() instead of OnDestroy()
in CView derived classes to perform cleanup. There should
be a reason for doing it this way, unfortunately I can't
recall. I'm sure WM_DESTROY can not be caught in CView
derived class itself, as well as in the child windows
(that is what you are seeing with your ClistCtrl).
It is probably doing something wrong with the message
maps.
Krish wrote:
hi,
Anyone faced similar issue please help me out.
Thanks,
Krish
Krish wrote:
Hi,
I have derived CCustomList from ClistCtrl, the OnDestroy event of
the
List is not getting fired when I place the list on a CView, but the
OnDestroy is called when the list is on a CDialog.
I want to save the state of the CListCtrl like the column order,
sort
order etc...
Is there any other place I can do these actions..
Anyhelp is appreciated..
Thanks,
Krish- Hide quoted text -- Show quoted text -
.
- Follow-Ups:
- Re: CListCtrl derived Class OnDestroy
- From: voidcoder
- Re: CListCtrl derived Class OnDestroy
- References:
- CListCtrl derived Class OnDestroy
- From: Krish
- Re: CListCtrl derived Class OnDestroy
- From: Krish
- Re: CListCtrl derived Class OnDestroy
- From: voidcoder
- Re: CListCtrl derived Class OnDestroy
- From: Krish
- Re: CListCtrl derived Class OnDestroy
- From: voidcoder
- Re: CListCtrl derived Class OnDestroy
- From: Krish
- Re: CListCtrl derived Class OnDestroy
- From: voidcoder
- Re: CListCtrl derived Class OnDestroy
- From: voidcoder
- Re: CListCtrl derived Class OnDestroy
- From: Krish
- Re: CListCtrl derived Class OnDestroy
- From: voidcoder
- Re: CListCtrl derived Class OnDestroy
- From: Krish
- Re: CListCtrl derived Class OnDestroy
- From: voidcoder
- Re: CListCtrl derived Class OnDestroy
- From: Krish
- Re: CListCtrl derived Class OnDestroy
- From: voidcoder
- Re: CListCtrl derived Class OnDestroy
- From: Krish
- Re: CListCtrl derived Class OnDestroy
- From: voidcoder
- Re: CListCtrl derived Class OnDestroy
- From: Krish
- Re: CListCtrl derived Class OnDestroy
- From: voidcoder
- CListCtrl derived Class OnDestroy
- Prev by Date: Re: CListCtrl derived Class OnDestroy
- Next by Date: Re: CListCtrl derived Class OnDestroy
- Previous by thread: Re: CListCtrl derived Class OnDestroy
- Next by thread: Re: CListCtrl derived Class OnDestroy
- Index(es):
Relevant Pages
|