-
July 26th, 2004, 04:23 PM
#16
Sorry my mistake, use FindWindowEx. Its a childwindow and FindWindow only searches for Top-Level Windows.
Hope this helps,
Regards,
Usman.
-
July 26th, 2004, 04:44 PM
#17
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;
}
-
July 26th, 2004, 04:51 PM
#18
Try this...
Code:
::FindWindowEx(m_hWnd, NULL, "SysListView32", NULL);
Hope this helps.
Regards,
Usman.
-
July 26th, 2004, 05:10 PM
#19
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
-
July 27th, 2004, 02:33 AM
#20
Originally Posted by senkyoshi
Problem: i am trying to use FindWindow with class "SysListView32" but it isnt returning anything. any other way to get a reference to CListCtrl in the CFileDialog?
thanks
Have you already read this ( http://msdn.microsoft.com/msdnmag/issues/02/01/c/ ) article?
Paul DiLascia pointed out how you could do this:
............
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.........
-
July 27th, 2004, 09:46 AM
#21
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
Last edited by senkyoshi; July 27th, 2004 at 09:49 AM.
-
July 27th, 2004, 10:01 AM
#22
Once again:
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>....
Have you #included <dlgs.h>?
-
July 27th, 2004, 10:13 AM
#23
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
-
July 27th, 2004, 10:33 AM
#24
The problem seems to be the List Control is yet not created while OnInitDialog is being called...
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()
.........
-
July 27th, 2004, 10:52 AM
#25
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!
-
July 27th, 2004, 11:47 AM
#26
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
-
July 27th, 2004, 12:12 PM
#27
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);
Try this:
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);
-
July 27th, 2004, 12:37 PM
#28
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?
-
July 27th, 2004, 01:16 PM
#29
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
}
-
July 27th, 2004, 01:39 PM
#30
Yes, "Modified" is column(item) 3
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|