Sorry my mistake, use FindWindowEx. Its a childwindow and FindWindow only searches for Top-Level Windows.
Hope this helps,
Regards,
Usman.
Printable View
Sorry my mistake, use FindWindowEx. Its a childwindow and FindWindow only searches for Top-Level Windows.
Hope this helps,
Regards,
Usman.
I'm still having problems. here is what i am doing.
BOOL CMyFileDialog::OnInitDialog() // Override
{
...
CFileDialog::OnInitDialog();
// Get a pointer to the original dialog box.
CWnd *wndDlg = GetParent();
CListView *pListView = (CListView *)FindWindowEx(wndDlg->m_hWnd,m_hWnd,"SysListView32", NULL);
...
return true;
}
Try this...
Hope this helps.Code:::FindWindowEx(m_hWnd, NULL, "SysListView32", NULL);
Regards,
Usman.
Ok, that didnt seem to work either. Here is what I did.
HWND hWnd = ::FindWindowEx(m_hWnd, NULL, "SysListView32", NULL);
CListCtrl * pListCtrl = (CListCtrl *)FromHandle(hWnd);
the first line set hWnd to 0x00000000. the second line I use to get a pointer to the object and that isnt working because the hWnd handle is bad. anything else you can think of? thanks so much for your time and help
Have you already read this ( http://msdn.microsoft.com/msdnmag/issues/02/01/c/ ) article?Quote:
Originally Posted by senkyoshi
Paul DiLascia pointed out how you could do this:Quote:
............
Many of the common dialogs have controls with documented IDs like stc1 for a static text control and lst1 for a listbox; these symbols are #defined in <dlgs.h>. You might think the list control would be lst1, but spelunking with Spy (see Figure 1) reveals that the list control is actually contained in another window of class, SHELLDLL_DefView. The SHELLDLL_DefView window has ID lst2; the list control inside it has child ID 1. So to get the list control, you can write:
// from your CFileDialog derivate
CListCtrl* plc = (CListCtrl*)GetParent()->
GetDlgItem(lst2)->GetDlgItem(1);
Remember, when you customize the open file dialog, your CFileDialog is actually a child of the real dialog, which explains why you must use GetParent. (For details see my article "Give Your Applications the Hot New Interface Look with Cool Menu Buttons" in the January 1998 issue of MSJ.) The cast to CListCtrl* works as per the usual MFC trick, because CListControl has neither data members nor virtual functions; it's a pure wrapper class. (Since GetDlgItem returns a pointer to a temporary CWnd, not a CListCtrl, downcasting would normally be a major booboo.)
Once you have a pointer to the list control, you can do whatever you like—within reason.........
Thanks VictorN! When I compile
CListCtrl* plc = (CListCtrl*)GetParent()->GetDlgItem(lst2)->GetDlgItem(1);
it says: error C2065: 'lst2' : undeclared identifier
do you know why this is happening? do I need to add it or the library it is in?
thanks
...nevermind. I had to include <dlgs.h>. I thought that I had already added it
Once again:Have you #included <dlgs.h>?Quote:
Many of the common dialogs have controls with documented IDs like stc1 for a static text control and lst1 for a listbox; these symbols are #defined in <dlgs.h>....
Yes, I actually saw that and it works fine now.
But now, compiling works fine but when I run it and when it gets to that line I get an Unhandled Exception (MFC42D) 0x00000005 Access Violation. Here is my code:
BOOL CMyFileDialog::OnInitDialog() // Override
{
CFileDialog::OnInitDialog();
// Get a pointer to the original dialog box.
CWnd *wndDlg = GetParent();
if ( wndDlg != NULL ) {
wndDlg->PostMessage(WM_COMMAND, 40964, NULL);
}
CListCtrl* plc = (CListCtrl*)wndDlg->GetDlgItem(lst2)->GetDlgItem(1);
return true;
}
any ideas?
thanks
The problem seems to be the List Control is yet not created while OnInitDialog is being called... :confused:
Post user defined Message to your dialog and try to retrieve list control pointer in the handler of this message:Code:// .cpp
#define MY_MESSAGE (WM_APP + 1)
.......
BEGIN_MESSAGE_MAP(CMyFileDialog, CDialog)
//{{AFX_MSG_MAP(CMyFileDialog)
..............
//}}AFX_MSG_MAP
ON_MESSAGE(MY_MESSAGE, OnMyMessage)
END_MESSAGE_MAP()
.........
BOOL CMyFileDialog::OnInitDialog() // Override
{
CFileDialog::OnInitDialog();
// Get a pointer to the original dialog box.
CWnd *wndDlg = GetParent();
if ( wndDlg != NULL ) {
wndDlg->PostMessage(WM_COMMAND, 40964, NULL);
}
PostMessage(MY_MESSAGE);
return true;
}
LRESULT CMyFileDialog::OnMyMessage(WPARAM, LPARAM)
{
ListCtrl* plc = (CListCtrl*)GetParent()->GetDlgItem(lst2)->GetDlgItem(1);
return 0;
}
..........
.........
// .h
//{{AFX_MSG(CMyFileDialog)
..............
//}}AFX_MSG
afx_msg LRESULT OnMyMessage(WPARAM, LPARAM);
DECLARE_MESSAGE_MAP()
.........
senkyoshi!
Take a look at this article: List View Mode, SetForegroundWindow, and Class Protection
PS:
however (in contrary to the author of this article), you should newer use (WM_USER + < n >) as ID for the user defined messages in MFC aoolications. Use (WM_APP + < n >) instead!
Wonderful!
things are working great now. Now on to another problem. On page one of this post usman999_1 says to use
SendMessage(GetParent(hHeaderCtrl), WM_NOTIFY, NULL, (LPARAM)&NMHeader);
to get the list to be sorted by the desired column. however, SendMessage only takes 3 parameters.
So this is what I try and my program crashes when it tries the SendMessage line.
LRESULT CMyFileDialog::OnMyMessage(WPARAM, LPARAM)
{
CListCtrl* plc = (CListCtrl*)GetParent()->GetDlgItem(lst2)->GetDlgItem(1);
CHeaderCtrl *pHCtrl = plc->GetHeaderCtrl();
HWND hHeaderCtrl = pHCtrl->m_hWnd;
NMHDR pNMHDR;
pNMHDR.hwndFrom = hHeaderCtrl;
pNMHDR.idFrom = pHCtrl->GetDlgCtrlID();
NMHEADER * NMHeader;
NMHeader->hdr = pNMHDR;
NMHeader->iItem = 3;
NMHeader->iButton = 0;
SendMessage(WM_NOTIFY, NULL, (LPARAM)&NMHeader);
return 0;
}
Can you see where I am having a problem?
thanks
Try this:Quote:
HWND hHeaderCtrl = pHCtrl->m_hWnd;
NMHDR pNMHDR;
pNMHDR.hwndFrom = hHeaderCtrl;
pNMHDR.idFrom = pHCtrl->GetDlgCtrlID();
NMHEADER * NMHeader;
NMHeader->hdr = pNMHDR;
NMHeader->iItem = 3;
NMHeader->iButton = 0;
SendMessage(WM_NOTIFY, NULL, (LPARAM)&NMHeader);
Code:HWND hHeaderCtrl = pHCtrl->m_hWnd;
NMHDR nmHDR;
nmHDR.hwndFrom = hHeaderCtrl;
nmHDR.idFrom = pHCtrl->GetDlgCtrlID();
NMHEADER NMHeader;
NMHeader.hdr = nmHDR;
NMHeader.iItem = 3;
NMHeader.iButton = 0;
SendMessage(WM_NOTIFY, NULL, (LPARAM)&NMHeader);
OK, it isn't crashing anymore but nothing is happening. The following line:
NMHeader->iItem = 3;
should be telling it to click the Modified area correct (since it is zero based and we have Name, size, type, Modified) Well, nothing is being clicked. Am I missing something in the code I last posted?
Try to check if the header with the text "Modified" is the item 3:Code:HDITEM hdi;
TCHAR lpBuffer[256];
hdi.mask = HDI_TEXT;
hdi.pszText = lpBuffer;
hdi.cchTextMax = 256;
bool bFound = false;
for (int iCol = 0; i < pHCtrl->GetItemCount(); iCol++)
{
pHCtrl->GetItem(iCol, &hdi);
if (strcmp(hdi.pszText, _T("Modified") == 0)
{
bFound = true;
break;
}
}
if(bFound)
{
// now iCol - item number
// send your message
}
Yes, "Modified" is column(item) 3