Chinaunix首页 | 论坛 | 博客
  • 博客访问: 845893
  • 博文数量: 756
  • 博客积分: 40000
  • 博客等级: 大将
  • 技术积分: 4980
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 14:40
文章分类

全部博文(756)

文章存档

2011年(1)

2008年(755)

我的朋友

分类:

2008-10-13 16:09:08

列表控制在哪里?

MyDlg.h
////////////////////////////////////////////////////////////////
// MSDN Magazine — March 2004
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
// Compiles with Visual Studio .NET on Windows XP. Tab size=3.
//
// My open dialog — customized to set default view mode.
//
class CMyOpenDlg : public CFileDialog {
public:
   CMyOpenDlg();

protected:
   CListCtrl m_wndList;          // list view showing files and folders

   enum { ID_LISTVIEW = lst2 };

   // reverse-engineered command codes for SHELLDLL_DefView
   enum LISTVIEWCMD
   {  ODM_VIEW_ICONS = 0x7029,
      ODM_VIEW_LIST  = 0x702b,
      ODM_VIEW_DETAIL= 0x702c,
      ODM_VIEW_THUMBS= 0x702d,
      ODM_VIEW_TILES = 0x702e,
   };

   virtual BOOL OnInitDialog();         // handle init dialog
   virtual void OnInitDone();           // handle CDN_INITDONE
   afx_msg LRESULT OnPostInit(WPARAM wp, LPARAM lp); // the REAL 
                                                     // initialization

   BOOL SetListView(LISTVIEWCMD cmd);

   DECLARE_DYNAMIC(CMyOpenDlg)
   DECLARE_MESSAGE_MAP()
};
MyDlg.cpp
////////////////////////////////////////////////////////////////
// MSDN Magazine — March 2004
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
// Compiles with Visual Studio .NET on Windows XP. Tab size=3.
//
#include "StdAfx.h"
#include "MyDlg.h"
#include "Resource.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

// self-initialization message posted
const MYWM_POSTINIT = WM_USER+1;

IMPLEMENT_DYNAMIC(CMyOpenDlg, CFileDialog)
BEGIN_MESSAGE_MAP(CMyOpenDlg, CFileDialog)
   ON_MESSAGE(MYWM_POSTINIT, OnPostInit)
END_MESSAGE_MAP()

////////////////
// ctor
//
CMyOpenDlg::CMyOpenDlg() : CFileDialog(TRUE)
{
   m_ofn.lpstrTitle = _T("Select a file or folder");
}

//////////////////
// Handle WM_INITDIALOG: shows that list view still not created yet.
//
BOOL CMyOpenDlg::OnInitDialog()
{
   TRACE(_T("CMyOpenDlg::OnInitDialog, hwnd=%p\n"), m_hWnd);
   CFileDialog::OnInitDialog();
   SetListView(ODM_VIEW_DETAIL); // this will fail
   PostMessage(MYWM_POSTINIT,0,0);
   return TRUE;
}

//////////////////
// Handle CDN_INITDONE: shows that list view still not created yet.
//
void CMyOpenDlg::OnInitDone()
{
   TRACE(_T("CMyOpenDlg::OnInitDone\n"));
   CFileDialog::OnInitDone();
   SetListView(ODM_VIEW_DETAIL); // this will fail
}

//////////////////
// Handle MYWN_POSTINIT: finally, the list view is created.
//
LRESULT CMyOpenDlg::OnPostInit(WPARAM wp, LPARAM lp)
{
   TRACE(_T("CMyOpenDlg::OnPostInit\n"));
   SetListView(ODM_VIEW_DETAIL); // this will succeed
   return 0;
}

//////////////////
// Change the list view to desired mode if the view exists.
// Display TRACE diagnostics either way.
//
BOOL CMyOpenDlg::SetListView(LISTVIEWCMD cmd)
{
   TRACE(_T("CMyOpenDlg::SetListView: "));

   // note that real dialog is my parent, not me
   CWnd* pshell = GetParent()->GetDlgItem(lst2);
   if (pshell) {
      TRACE(_T("hwnd=%p.\n"), m_wndList.GetSafeHwnd());
      pshell->SendMessage(WM_COMMAND, cmd);
      return TRUE;
   }
   TRACE(_T("failed.\n"),m_wndList.GetSafeHwnd());
   return FALSE;
}



Command ID (WPARAM) List View Mode
0x7029 Icons
0x702B List
0x702C Details
0x702D Thumbnails
0x702E Tiles


--------------------next---------------------

阅读(605) | 评论(0) | 转发(0) |
0

上一篇:Figures

下一篇:Figures

给主人留下些什么吧!~~