默认情况下,打开对话框的文件列表的样式是列表样式,要实现一打开放大框就自动是大图标风格,需要在打开对话框显示在屏幕上以前,找到该文件列表控件(SysListView32)的句柄,然后改变其风格就可以了。
标准ListView控件有四种样式,分别如下:
LVS_ICON 0x0000 大图标样式
LVS_REPORT 0x0001 详细资料样式
LVS_SMALLICON 0x0002 小图标样式
LVS_LIST 0x0003 列表样式
以前ccrun曾在csdn回答过一位网友的问题,正好有一些代码,比较简单,ccrun就没有加注释。嘿嘿。
在Form上放置一个TButton,一个TOpenDialog。然后添加以下代码:
.h 文件中:
public: // User declarations
void __fastcall OpenDialogShow(TObject *Sender);
void __fastcall OpenDialogClose(TObject *Sender);
.cpp 文件中:
//---------------------------------------------------------------------------
FARPROC OldDlgOpenProc = NULL;
static LRESULT CALLBACK NewDlgOpenProc(
HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
//---------------------------------------------------------------------------
static LRESULT CALLBACK NewDlgOpenProc(
HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if(uMsg == WM_UPDATEUISTATE)
{
HWND hShell = FindWindowEx(GetParent(hWnd), NULL, "SHELLDLL_DefView", NULL);
HWND hListView = FindWindowEx(hShell, NULL, "SysListView32", NULL);
if(hListView)
{
SetWindowLong(hListView, GWL_STYLE,
GetWindowLong(hListView, GWL_STYLE) & 0xFFFFFFF0 LVS_ICON);
}
}
return CallWindowProc((FARPROC)OldDlgOpenProc, hWnd, uMsg, wParam, lParam);
}
//---------------------------------------------------------------------------
// 本文来自 http://www.ccrun.com
// 欢迎光临 C++ Builder 研究
// 作者: ccrun(老妖)
//---------------------------------------------------------------------------
__fastcall TfrmMain::TfrmMain(TComponent* Owner)
: TForm(Owner)
{
OpenDialog1->OnClose = OpenDialogClose;
OpenDialog1->OnShow = OpenDialogShow;
Button1->OnClick = Button1Click;
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::Button1Click(TObject *Sender)
{
OpenDialog1->Execute();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::OpenDialogShow(TObject *Sender)
{
OldDlgOpenProc = (FARPROC)SetWindowLong(
OpenDialog1->Handle, GWL_WNDPROC, (long)NewDlgOpenProc);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::OpenDialogClose(TObject *Sender)
{
SetWindowLong(OpenDialog1->Handle, GWL_WNDPROC, (long)OldDlgOpenProc);
}
//---------------------------------------------------------------------------