cfiledialog没定义1st1标识符
cfiledialog没有定义1st1标识符
在CFiledialog中重载OnInitDialog希望获取Listctrl控件来设置其显示方式为大图标。
但是提示说没有定义这个1st1标识符
error C2065: “lst1”: 未声明的标识符
------解决方案--------------------
要把Hook打开
------解决方案--------------------
初始化时:
CFileDialog fd(TRUE);
fd.m_ofn.lpstrTitle="Down Load File";
fd.m_ofn.lpstrInitialDir=strcat(drive,dir);
fd.m_ofn.lpstrFile=strcat(fname,ext);
fd.m_ofn.lpstrFilter="Any file(*.*)\0*.*\0ARC file (*.arc)\0*.arc\0BMP file (*.bmp)\0*.bmp\0DLL file (*.dll)\0*.dll\0";
if (stricmp(ext,".arc")==0) fd.m_ofn.nFilterIndex=2;
else if (stricmp(ext,".bmp")==0) fd.m_ofn.nFilterIndex=3;
else if (stricmp(ext,".dll")==0) fd.m_ofn.nFilterIndex=4;
else fd.m_ofn.nFilterIndex=1;
fd.m_ofn.Flags|=OFN_FILEMUSTEXIST;
fd.m_ofn.Flags|=OFN_ALLOWMULTISELECT;// must
fd.m_ofn.Flags|=OFN_EXPLORER; // default by Afx
// fd.m_ofn.Flags|=OFN_ENABLEHOOK;// default by Afx
fd.m_ofn.lpfnHook=DNHookProc;//="_AfxCommDlgProc" see"dlgcomm.cpp" <>NULL!
hook程序如下:
在CFiledialog中重载OnInitDialog希望获取Listctrl控件来设置其显示方式为大图标。
但是提示说没有定义这个1st1标识符
- C/C++ code
BOOL CMyFileSel::OnInitDialog() { CFileDialog::OnInitDialog(); CWnd* pWnd = GetDlgItem(lst1); if(pWnd) BOOL flag = pWnd->ModifyStyle(LVS_TYPEMASK, LVS_ICON & LVS_TYPEMASK); return TRUE; }
error C2065: “lst1”: 未声明的标识符
------解决方案--------------------
要把Hook打开
------解决方案--------------------
初始化时:
CFileDialog fd(TRUE);
fd.m_ofn.lpstrTitle="Down Load File";
fd.m_ofn.lpstrInitialDir=strcat(drive,dir);
fd.m_ofn.lpstrFile=strcat(fname,ext);
fd.m_ofn.lpstrFilter="Any file(*.*)\0*.*\0ARC file (*.arc)\0*.arc\0BMP file (*.bmp)\0*.bmp\0DLL file (*.dll)\0*.dll\0";
if (stricmp(ext,".arc")==0) fd.m_ofn.nFilterIndex=2;
else if (stricmp(ext,".bmp")==0) fd.m_ofn.nFilterIndex=3;
else if (stricmp(ext,".dll")==0) fd.m_ofn.nFilterIndex=4;
else fd.m_ofn.nFilterIndex=1;
fd.m_ofn.Flags|=OFN_FILEMUSTEXIST;
fd.m_ofn.Flags|=OFN_ALLOWMULTISELECT;// must
fd.m_ofn.Flags|=OFN_EXPLORER; // default by Afx
// fd.m_ofn.Flags|=OFN_ENABLEHOOK;// default by Afx
fd.m_ofn.lpfnHook=DNHookProc;//="_AfxCommDlgProc" see"dlgcomm.cpp" <>NULL!
hook程序如下:
- C/C++ code
/////////////////////////////////////////////////////// // for CFileDialog down load // in debug version there is an error : ASSERT(m_p...==NULL) 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; // if (hDlg == NULL) return 0; // from "_AfxCommDlgProc()" of the file "dlgcomm.cpp" _AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); if (pThreadState->m_pAlternateWndInit != NULL) // not pThreadState->m_pAlternateWndInit->SubclassWindow(hWnd); pThreadState->m_pAlternateWndInit = NULL; // hWndParent=GetParent(hDlg);// needed switch (uMsg) { case WM_INITDIALOG: 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); break; case WM_NOTIFY: LPOFNOTIFY lpon=(LPOFNOTIFY)lPar; UINT Notify=lpon->hdr.code; if (Notify==CDN_TYPECHANGE || Notify==CDN_SELCHANGE ) { // after window shown hw=GetDlgItem(hWndParent,0x0461);// SHELLDll_defView hcw=GetDlgItem(hw,1);// SysListView32 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); } if (Notify==CDN_FOLDERCHANGE) { HWND hLv=GetDlgItem(hWndParent,0x0461);//lst1 if(hLv) SendMessage(hLv,WM_COMMAND,0x7029,0);//ODM_WIEW_ICONS } break; } return 0; }