When writing programs, sometimes in order to save effort or for other purposes, we often want to borrow the system's dialog box. So, how can we call the system dialog box? A friend calls the "Open With" dialog box in VB like this:
winexec(PChar('rundll32shell32,OpenAs_RunDLL'+FilePath),SW_SHOWDEFAULT);
This code is implemented by running rundll32.exe and letting it call the resources in shell32.dll. The method is feasible, but there are many novices like me who don’t understand how to call the precious resources in shell32.dll. How should we do it?
Here's how I called it:
1. Call the system “About” dialog box:
First add SHellApi to uses,
Then write the following code:
PRocedureTForm1.Button1Click(Sender:TObject);
var
shellapp:variant;
begin
ShellAboutW(0,'Timerv1.03','kedyCopyright',1);
end;
I won't go into details about the other steps. After running, click the button and the standard WINDOWS About dialog box will pop up. The dialog box is titled "About Timerv1.03". As you can see, I used the ShellAboutW function in the program. This function is described in MSDN2003 like this:
ShellAboutFunction
DisplaysaShellAboutdialogbox.
Syntax
intShellAbout(HWNDhWnd,
LPCTSTRszApp,
LPCTSTRszOtherStuff,
HICONhIcon
);
Parameters
wx
[in]Windowhandletoaparentwindow.ThisparametercanbeNULL.
szApp
[in]Pointertoanull-terminatedstringcontainingtextthatwillbedisplayedinthe
titlebaroftheShellAboutdialogboxandonthefirstlineofthedialogboxafterthe
text"Microsoft".Ifthetextcontainsaseparator(#)dividingitintotwoparts,the
functiondisplaysthefirstpartinthetitlebarandthesecondpartonthefirstline
afterthetext"Microsoft".
szOtherStuff
[in]Pointertoanull-terminatedstringcontainingtextthatwillbedisplayedinthe
dialogboxaftertheversionandcopyrightinformation.
hIcon
[in]Iconthatthefunctiondisplaysinthedialogbox.IfthisparameterisNULL,the
functiondisplaystheMicrosoft®Windows®orMicrosoftWindowsNT®icon.
I don’t think you need me to translate what it means. It’s best to see these things by yourself.
2. Call the shutdown dialog box
We only need to change the begin part of the code to
begin
shellapp:=CreateOleObject('Shell.application');
shellapp.ShutDownWindows;
end;
Other parts remain unchanged. Run and click the button and we can see the standard system shutdown dialog box.
In fact, this is still the WindowsAPI function shutdownwindows called.
This part uses two functions in the method of Windows shellapplication. Other functions of method include:
BrowseForFolder, CascadeWindows, ControlPanelItem, EjectPC, Explore, FileRun, FindComputer, FindFiles, Help, MinimizeAll, NameSpace, Open, RefreshMenu, SetTime, TileHorizontally, TileVertically, TrayProperties, UndoMinimizeALL. I've only learned to use a few of these functions. For details, please check the content about shellobject in MSDN.
What I want to say most is that you must use MSDN to learn programs under windows. I am really amazed by the resources in this library. You can take a look and I think you will think so too.