16,472
社区成员
发帖
与我相关
我的任务
分享
///////////////////////////////////////////////////////
//
CFileDialog fd(TRUE);
//注意:
fd.m_ofn.lpfnHook=DNHookProc;//="_AfxCommDlgProc" see"dlgcomm.cpp" <>NULL!
//UINT CALLBACK _AfxCommDlgProc(HWND hWnd,UINT message,
// WPARAM wParam,LPARAM lParam);
enum LISTVIEWCMD
{
ODM_VIEW_ICONS = 0x7029,
ODM_VIEW_LIST = 0x702b,
ODM_VIEW_DETAIL= 0x702c,
ODM_VIEW_THUMBS= 0x702d,
ODM_VIEW_TILES = 0x702e,
};
// for CFileDialog down load
UINT CALLBACK DNHookProc(HWND hDlg,UINT uMsg,WPARAM wPar,LPARAM lPar)
{ // hdlg is a child
HWND hWndParent;
CWinApp *pApp=AfxGetApp();
HICON hIcon;
HWND hw; // SHELLDll_defView
HWND hcw;// SysListView32
DWORD dwStyle;
LPOFNOTIFY lpon=0;
UINT Notify=0;
//
if (hDlg == NULL) return 0;
#ifdef _DEBUG
// from "_AfxCommDlgProc()" of the file "dlgcomm.cpp"
_AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
// =_AfxActivationWndProc(hwnd,uint,uint,long)
if (pThreadState->m_pAlternateWndInit != NULL) pThreadState->m_pAlternateWndInit = NULL;
#endif
//
hWndParent=GetParent(hDlg);// needed
switch (uMsg)
{
case WM_INITDIALOG://这时,SHELLDLL_DefView的窗口还不存在
hIcon=pApp->LoadIcon(IDI_ICONDN);
SendMessage(hWndParent,WM_SETICON,(WPARAM)0,(LPARAM)hIcon);
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
DestroyIcon(hIcon);
// ShowWindow(hDlg,SW_HIDE);
SetTimer(hDlg,1,10,0);
// PostMessage(hDlg,WM_USER+1,0,0);
break;
case WM_TIMER:
// SHELLDll_defView ,ID是lst2(值为0x0461,在dlgs.h中定义),
KillTimer(hDlg,1);
hw=GetDlgItem(hWndParent,0x0461);
SendMessage(hw, WM_COMMAND,ODM_VIEW_THUMBS,0);
break;
case WM_USER+1:
// SHELLDll_defView ,ID是lst2(值为0x0461,在dlgs.h中定义),
hw=GetDlgItem(hWndParent,0x0461);
SendMessage(hw, WM_COMMAND,ODM_VIEW_THUMBS,0);
ShowWindow(hDlg,SW_SHOW);
break;
case WM_NOTIFY:
lpon=(LPOFNOTIFY)lPar;
Notify=lpon->hdr.code;
if (Notify==CDN_TYPECHANGE ||
Notify==CDN_SELCHANGE )
{ // 列表控制不是对话框的直接子类,它是孙子类.
// 主对话框有一个子窗口,类的名字为 SHELLDLL_DefView。
hw=GetDlgItem(hWndParent,0x0461);// SHELLDll_defView
hcw=GetDlgItem(hw,1);// SysListView32 是 SHELLDLL_DefView 的孩子,ID为1。
dwStyle=GetWindowLong(hcw,GWL_STYLE);
// change multi-selection of ListView
if (lpon->lpOFN->nFilterIndex==4) // "dll"
{
dwStyle &= ~LVS_SINGLESEL;// Multi
}
else
{
dwStyle |= LVS_SINGLESEL;// Single
}
SetWindowLong(hcw,GWL_STYLE,dwStyle);
}
break;
}
return 0;
}