Application 1
The application is a MFC Dialog application whose UI is illustrated at the top of this article. The design-time UI is illustrated below:
To test this application, you have to do three things:
- Choose in the list, one of the objects.
- Optionally, choose one of the two options or both of them.
- Click on the button " GO TO -->!" in order to display the appropriate object.
The main procedure responsible for displaying the chosen object in the combo-box list corresponding to the click on the button labeled "GO TO -->!" is given below, and doesn't need any explanation for people comfortable with Microsoft C++:
void CExploreWinObjectsDlg::OnExploreWhat()
{
#define LIST_ITEMS_NUM 15
CString CLSIDs[LIST_ITEMS_NUM] =
{
_T("{20D04FE0-3AEA-1069-A2D8-08002B30309D}"),
CLSIDs[0] + CString("\\::{21EC2020-3AEA-1069-A2DD"
"-08002B30309D}"),
CLSIDs[1]+CString("\\::{2227A280-3AEA-1069-A2DE"
"-08002B30309D}"),
CLSIDs[1]+CString("\\::{D20EA4E1-3957-11d2-A40B"
"-0C5020524152}"),
CLSIDs[1]+CString("\\::{E211B736-43FD-11D1-"
"9EFB-0000F8757FCD}"),
CLSIDs[1]+CString("\\::{7007ACC7-3202-11D1-AAD2"
"-00805FC1270E}"),
CLSIDs[1]+CString("\\::{D20EA4E1-3957-11d2"
"-A40B-0C5020524153}"),
CLSIDs[1]+CString("\\::{D6277990-4C6A-11CF"
"-8D87-00AA0060F5BF}"),
CLSIDs[0]+CString("\\::{BDEADF00-C265-11D0"
"-BCED-00A0C90AB50F}"),
_T("{450D8FBA-AD25-11D0-98A8-0800361B1103}"),
_T("{645FF040-5081-101B-9F08-00AA002F954E}"),
_T("{208D2C60-3AEA-1069-A2D7-08002B30309D}"),
_T("{871C5380-42A0-1069-A2EA-08002B30309D}"),
_T("{1F4DE370-D627-11D1-BA4F-00A0C91EEDBA}"),
_T("{E17D4FC0-5564-11D1-83F2-00A0C90DC849}")
};
char Windir[MAX_PATH];
if (GetWindowsDirectory(Windir,MAX_PATH)>0)
{
int SelIndex =
SendDlgItemMessage(IDC_COMBO1, CB_GETCURSEL, 0, 0);
BOOL DoNotShowLeftPane=(BOOL)IsDlgButtonChecked(IDC_CHECK1);
BOOL StartExplAtRoot=(BOOL)IsDlgButtonChecked(IDC_CHECK2);
for (int i=0; i< LIST_ITEMS_NUM; i++) {
if (SelIndex==i) {
char cmdline[MAX_PATH];
char HowExplore[10];
char StartAtRoot[10];
wsprintf(HowExplore, "%s",
(DoNotShowLeftPane==TRUE)?"/N":"/E");
wsprintf(StartAtRoot, "%s",
(StartExplAtRoot==TRUE)?"/Root,":"");
wsprintf(cmdline,"%s\\Explorer.exe %s,%s::%s",
Windir, HowExplore, StartAtRoot, CLSIDs[i]);
DWORD ExitCode=0;
BOOL bRet=CreateProc("", cmdline, FALSE, 0,
TRUE, ExitCode);
break;
}
}
}
else
{
MessageBox("Error in GetWindowsDirectory() API!",
"",MB_OK|MB_ICONEXCLAMATION);}
}
Application 2
The second application is a VB 6 example using Internet Explorer Control whose UI is illustrated as the second figure at the top of this article. I want in this application to give another approach using Explorer objects different from the one used in VC++ sample application. The code is quite simple and makes use of one call to the Windows API GetClientRect
declared as:
Private Declare Function GetClientRect Lib "user32" (_
ByVal hwnd As Long, lpRect As rect) As Long
in order to resize the form. Note that in VB objects, dimensions are measured in Twips units, and since this API returns the window client rectangle in Pixels units, we have to convert these dimensions to Twips by using the Screen
object properties : TwipsPerPixelX
and TwipsPerPixelY
(see the event Form_Resize()
content). In order to display the Explorer objects, I have used the Internet Explorer method Naviagte2
with no optional parameters in the event handler cboObjects_Click()
. The complete code is given below:
OptionExplicit
Private Type rect
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetClientRect Lib "user32" _
(ByVal hwnd As Long, lpRect As rect) As Long
Dim objExpArray(0 To 14) As String
Private Sub cboObjects_Click()
WebBrowser1.Navigate2 objExpArray(cboObjects.ListIndex)
End Sub
Private Sub Form_Load()
objExpArray(0)= "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
objExpArray(1) = objExpArray(0) + _
"\::{21EC2020-3AEA-1069-A2DD-08002B30309D}"
objExpArray(2) = objExpArray(1) + _
"\::{2227A280-3AEA-1069-A2DE-08002B30309D}"
objExpArray(3) = objExpArray(1) + -
"\::{D20EA4E1-3957-11d2-A40B-0C5020524152}"
objExpArray(4) = objExpArray(1) + -
"\::{E211B736-43FD-11D1-9EFB-0000F8757FCD}"
objExpArray(5) = objExpArray(1) + _
"\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}"
objExpArray(6) = objExpArray(1) + _
"\::{D20EA4E1-3957-11d2-A40B-0C5020524153}"
objExpArray(7) = objExpArray(1) + _
"\::{D6277990-4C6A-11CF-8D87-00AA0060F5BF}"
objExpArray(8) = objExpArray(0) + _
"\::{BDEADF00-C265-11D0-BCED-00A0C90AB50F}"
objExpArray(9) = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}"
objExpArray(10)= "::{645FF040-5081-101B-9F08-00AA002F954E}"
objExpArray(11)= "::{208D2C60-3AEA-1069-A2D7-08002B30309D}"
objExpArray(12)= "::{871C5380-42A0-1069-A2EA-08002B30309D}"
objExpArray(13)= "::{1F4DE370-D627-11D1-BA4F-00A0C91EEDBA}"
objExpArray(14) = "::{E17D4FC0-5564-11D1-83F2-00A0C90DC849}"
cboObjects.ListIndex = 0
End Sub
Private Sub Form_Resize()
Dim CliRect As rect
If GetClientRect(Me.hwnd, CliRect) > 0 Then
Me.WebBrowser1.Move 0, Me.cboObjects.Height, _
CliRect.Right * Screen.TwipsPerPixelX, _
CliRect.Bottom * Screen.TwipsPerPixelY _
- Me.cboObjects.Height
End If
End Sub
Points of interest
This article has shown us how to launch Windows Explorer objects that are not ordinary ones like folders or files. The examples given here can be used in any code source whatever the programming or the script language used is, as long as it is used in the Windows platform.