我想实现当在目录窗口或资源管理器中选中文件时,得到此文件的文件名.我用HOOK CALLWNDPROC拦截LVN_ITEMCHANGED,然后用SendMessage发送了LVM_GETITEMTEXT来得到LIST VIEW中的文本,可这只能得到文件名,却得不到文件路径,有什么办法可得到选中文件的文件路径?
还有,我在钩子函数加了一条MessageBox,用来显示得到的文件名,可每次我在资源管理器中选中文件,MessageBox都会弹出三次,前两次显示上次选中的文件名,第三次显示本次选中的文件名,这是为什么?
还有,我在钩子函数加了一条MessageBox,用来显示得到的文件名,可每次我在资源管理器中选中文件,MessageBox都会弹出三次,前两次显示上次选中的文件名,第三次显示本次选中的文件名,这是为什么?
解决方案 »
- 默认按钮和焦点按钮的老问题!
- vc++打印,怎样实现多份打印啊,已经费了我一天的时间啦
- COleDateTime时间控件的初始化
- 如何利用循环和存储过程向SQL中插入数据?
- CListCtrl中,某列需要显示一副完整的图片的问题
- 急!!!在VC6.0应用程序中嵌入Visio 11.0 Drawing Control 后如何在该控件中打开Visio文件???
- C++ 对话框小作业,各位有会的,帮帮我吧,初学者很痛苦
- 高分求教!各位大大请进!!!好茶伺候!
- 句柄
- 请问如何改变光标的颜色?我已经把光标改为十字丝光标了
- 设置CEditView字体的问题,在线等,散分
- 请帮忙看看:工具条中怎样实现类似ie工具条中左边是图右边为文字的效果(文字多少按纽款也就不同)。或者怎样使工具条上的按钮具有不同宽
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
if(pNMLV->uNewState==0 && pNMLV->uOldState==1)
{
...
}
二。取得了文件名,再调用GetFullPathName不就行了么?
还有reinterpret_cast <LPNMLISTVIEW >这是什么意思?是取指针么?
2.在钩子函数里你用的是什么钩子呢?
顺便问一下,CSDN的BLOG怎么用?为什么总是提示必须输入正文,可我已经输入了?
NMLISTVIEW Structure--------------------------------------------------------------------------------Contains information about a list-view notification message. This structure is the same as the NM_LISTVIEW structure but has been renamed to fit standard naming conventions. Syntaxtypedef struct tagNMLISTVIEW {
NMHDR hdr;
int iItem;
int iSubItem;
UINT uNewState;
UINT uOldState;
UINT uChanged;
POINT ptAction;
LPARAM lParam;
} NMLISTVIEW, *LPNMLISTVIEW;
Membershdr
NMHDR structure that contains information about this notification message.
iItem
Identifies the list-view item, or -1 if not used.
iSubItem
Identifies the subitem, or zero if none.
uNewState
New item state. This member is zero for notification messages that do not use it.
uOldState
Old item state. This member is zero for notification messages that do not use it.
uChanged
Set of flags that indicate the item attributes that have changed. This member is zero for notifications that do not use it. Otherwise, it can have the same values as the mask member of the LVITEM structure.
ptAction
POINT structure that indicates the location at which the event occurred. This member is undefined for notification messages that do not use it.
lParam
Application-defined value of the item. This member is undefined for notification messages that do not use it.
Structure InformationMinimum DLL Version comctl32.dll version 4.70 or later
Header commctrl.h
Minimum operating systems Windows 2000, Windows NT 4.0 with Internet Explorer 3.0, Windows 98, Windows 95 with Internet Explorer 3.0
--------------------------------------------------------------------------------© 2003 Microsoft Corporation. All rights reserved
MSDN中只有E文的。
/*************************************************************************BmpDlg.h header fileCBmpDialog: A bitmap open dialog with preview.
by The GremlinCompatibility: Visual C++ 4.0 and up.**************************************************************************/#ifndef _BMPDIALOG_H_
#define _BMPDIALOG_H_
// CBmpDialog dialogclass CBmpDialog : public CFileDialog
{
DECLARE_DYNAMIC(CBmpDialog)public:
CBmpDialog(BOOL bOpenFileDialog = TRUE, // TRUE for FileOpen, FALSE for FileSaveAs. Who would want a save with preview?
LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
LPCTSTR lpszFilter = NULL,
CWnd* pParentWnd = NULL); static BOOL m_showpreview; // Store this variable in the registry if you want the "Show Preview" setting to be persistent static HBITMAP hpreview;protected:
//{{AFX_MSG(CBmpDialog)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
#endif
//
// BmpDlg.cpp : implementation file
//
// ************************************************************************************#include "stdafx.h"
#include "BmpDlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif// In order to ease use, these values have been hard coded in bmpdlg.rc
// This avoids the need for another header file.#define IDC_PREVIEW (5000)
#define IDC_PREVIEWBTN (5001)
#define IDC_WIDTH (5002)
#define IDC_HEIGHT (5003)
#define IDC_DEPTH (5004)
#define IDC_FSIZE (5005)
#define IDC_SHOWPREVIEW (5006)HBITMAP CBmpDialog::hpreview = NULL;
BOOL CBmpDialog::m_showpreview = TRUE;// Proprietary Hook function for open dialogUINT APIENTRY OFNHookProc( HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam )
{
LPDRAWITEMSTRUCT lpdis;
BITMAP bm;
LPNMHDR pnmh;
char filename[1024],str[255];
int height,height2,width,width2;
NMHDR nmh;
switch (uiMsg)
{
case WM_COMMAND:
if (LOWORD(wParam) == IDC_SHOWPREVIEW)
{
CBmpDialog::m_showpreview = IsDlgButtonChecked(hdlg,IDC_SHOWPREVIEW); if (!CBmpDialog::m_showpreview)
{
if (CBmpDialog::hpreview)
DeleteObject(CBmpDialog::hpreview); CBmpDialog::hpreview = NULL; HWND wnd = GetDlgItem(hdlg,IDC_PREVIEWBTN); InvalidateRect(wnd,NULL,TRUE); SetDlgItemText(hdlg,IDC_WIDTH,"");
SetDlgItemText(hdlg,IDC_HEIGHT,"");
SetDlgItemText(hdlg,IDC_DEPTH,"");
SetDlgItemText(hdlg,IDC_FSIZE,""); }
else
{
nmh.code = CDN_SELCHANGE; OFNHookProc(hdlg, WM_NOTIFY, 0, (LPARAM)&nmh);
}
} break; case WM_DRAWITEM: if (CBmpDialog::hpreview)
{
lpdis = (LPDRAWITEMSTRUCT)lParam;
GetObject(CBmpDialog::hpreview,sizeof(BITMAP),&bm); CPoint size(bm.bmWidth,bm.bmHeight);
HDC dcmem = CreateCompatibleDC(lpdis->hDC);
HBITMAP old = (HBITMAP)SelectObject(dcmem,CBmpDialog::hpreview); if (bm.bmWidth > bm.bmHeight)
{ height = lpdis->rcItem.bottom - lpdis->rcItem.top; float ratio = (float)bm.bmHeight/(float)bm.bmWidth;
lpdis->rcItem.bottom = (long) (lpdis->rcItem.top + (lpdis->rcItem.right-lpdis->rcItem.left)*ratio); height2 = (height - (lpdis->rcItem.bottom - lpdis->rcItem.top))/2; lpdis->rcItem.top += height2;
lpdis->rcItem.bottom += height2; }
else
{ width = lpdis->rcItem.right - lpdis->rcItem.left; float ratio = (float)bm.bmWidth/(float)bm.bmHeight;
lpdis->rcItem.right = (long) (lpdis->rcItem.left + (lpdis->rcItem.bottom-lpdis->rcItem.top)*ratio); width2 = (width - (lpdis->rcItem.right - lpdis->rcItem.left))/2; lpdis->rcItem.left += width2;
lpdis->rcItem.right += width2; }
StretchBlt(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top,lpdis->rcItem.right-lpdis->rcItem.left,lpdis->rcItem.bottom-lpdis->rcItem.top,dcmem,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY); SelectObject(dcmem,old); DeleteDC(dcmem);
} break; case WM_NOTIFY:
pnmh = (LPNMHDR) lParam;
{
if (CBmpDialog::hpreview)
DeleteObject(CBmpDialog::hpreview); // This avoids an assert _AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
pThreadState->m_pAlternateWndInit = NULL;
return 0;
}
if (pnmh->code == CDN_INITDONE)
{
if (CBmpDialog::hpreview)
DeleteObject(CBmpDialog::hpreview); CheckDlgButton(hdlg,IDC_SHOWPREVIEW,CBmpDialog::m_showpreview);
return 0;
} if (pnmh->code == CDN_SELCHANGE)
{ if (!IsDlgButtonChecked(hdlg,IDC_SHOWPREVIEW))
{
if (CBmpDialog::hpreview)
DeleteObject(CBmpDialog::hpreview); CBmpDialog::hpreview = NULL; return 0;
}
SendMessage(GetParent(hdlg),CDM_GETFILEPATH ,1024,(LPARAM)filename); if (CBmpDialog::hpreview)
DeleteObject(CBmpDialog::hpreview);
CBmpDialog::hpreview = (HBITMAP)LoadImage(AfxGetInstanceHandle(),filename,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION); HWND wnd = GetDlgItem(hdlg,IDC_PREVIEWBTN); InvalidateRect(wnd,NULL,TRUE); if (CBmpDialog::hpreview)
{
GetObject(CBmpDialog::hpreview,sizeof(BITMAP),&bm);
wsprintf(str,"Width: %d pixels",bm.bmWidth);
SetDlgItemText(hdlg,IDC_WIDTH,str); wsprintf(str,"Height: %d pixels",bm.bmHeight);
SetDlgItemText(hdlg,IDC_HEIGHT,str);
switch (bm.bmBitsPixel)
{
case 1:
SetDlgItemText(hdlg,IDC_DEPTH,"Colors: 2 (monocromatic)");
break;
case 4:
SetDlgItemText(hdlg,IDC_DEPTH,"Colors: 16");
break; case 8:
SetDlgItemText(hdlg,IDC_DEPTH,"Colors: 256");
break; case 16:
SetDlgItemText(hdlg,IDC_DEPTH,"Colors: 65,536");
break;
case 24:
SetDlgItemText(hdlg,IDC_DEPTH,"Colors: 16 millions");
break; default:
SetDlgItemText(hdlg,IDC_DEPTH,""); } OFSTRUCT o; HFILE f = OpenFile(filename,&o,OF_READ); wsprintf(str,"Size: %ld Kb",GetFileSize((HANDLE)f,NULL)/1024); SetDlgItemText(hdlg,IDC_FSIZE,str);
_lclose(f);
}
else
{
SetDlgItemText(hdlg,IDC_WIDTH,"");
SetDlgItemText(hdlg,IDC_HEIGHT,"");
SetDlgItemText(hdlg,IDC_DEPTH,"");
SetDlgItemText(hdlg,IDC_FSIZE,"");
}
} }
return 0;
}/////////////////////////////////////////////////////////////////////////////
// CBmpDialogIMPLEMENT_DYNAMIC(CBmpDialog, CFileDialog)CBmpDialog::CBmpDialog(BOOL bOpenFileDialog, LPCTSTR lpszDefExt, LPCTSTR lpszFileName,
DWORD dwFlags, LPCTSTR lpszFilter, CWnd* pParentWnd) :
CFileDialog(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd)
{ m_ofn.lpstrFilter = "Bitmaps (*.bmp)\0*.bmp\0"\
"All Files (*.*)\0*.*\0\0"; m_ofn.Flags |= (OFN_HIDEREADONLY |OFN_ENABLEHOOK| OFN_EXPLORER |OFN_ENABLETEMPLATE); m_ofn.hInstance = AfxGetInstanceHandle();
m_ofn.lpTemplateName = MAKEINTRESOURCE(IDC_PREVIEW);
m_ofn.lpfnHook = OFNHookProc;
}
BEGIN_MESSAGE_MAP(CBmpDialog, CFileDialog)
//{{AFX_MSG_MAP(CBmpDialog)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()