TaskManager
Here's a simple application to function like the Windows Task Manager...
AI
Résumé par IA: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Code source
Sub cmdExit_Click ()
Unload Me ' Get me out of here!
Set activate = Nothing ' Kill Form reference for good measure
End Sub
Sub cmdRefresh_Click ()
FindAllApps ' Update list of tasks
End Sub
Sub cmdSwitch_Click ()
Dim hWnd As Long ' handle to window
Dim x As Long ' work area
Dim lngWW As Long ' Window Style bits
If lstApp.ListIndex < 0 Then Beep: Exit Sub
' Get window handle from listbox array
hWnd = lstApp.ItemData(lstApp.ListIndex)
' Get style bits for window
lngWW = GetWindowLong(hWnd, GWL_STYLE)
' If minimized do a restore
If lngWW And WS_MINIMIZE Then
x = ShowWindow(hWnd, SW_RESTORE)
End If
' Move window to top of z-order/activate; no move/resize
x = SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, _
SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW)
End Sub
Sub FindAllApps ()
Dim hwCurr As Long
Dim intLen As Long
Dim strTitle As String
' process all top-level windows in master window list
lstApp.Clear
hwCurr = GetWindow(Me.hWnd, GW_HWNDFIRST) ' get first window
Do While hwCurr ' repeat for all windows
If hwCurr <> Me.hWnd And TaskWindow(hwCurr) Then
intLen = GetWindowTextLength(hwCurr) + 1 ' Get length
strTitle = Space$(intLen) ' Get caption
intLen = GetWindowText(hwCurr, strTitle, intLen)
If intLen > 0 Then ' If we have anything, add it
lstApp.AddItem strTitle
' and let's save the window handle in the itemdata array
lstApp.ItemData(lstApp.NewIndex) = hwCurr
End If
End If
hwCurr = GetWindow(hwCurr, GW_HWNDNEXT)
Loop
End Sub
Sub Form_Load ()
IsTask = WS_VISIBLE Or WS_BORDER ' Define bits for normal task
FindAllApps ' Update list
End Sub
Sub Form_Paint ()
FindAllApps ' Update List
End Sub
Sub Label1_Click ()
FindAllApps ' Update list
End Sub
Sub lstApp_DblClick ()
cmdSwitch.Value = True
End Sub
Function TaskWindow (hwCurr As Long) As Long
Dim lngStyle As Long
lngStyle = GetWindowLong(hwCurr, GWL_STYLE)
If (lngStyle And IsTask) = IsTask Then TaskWindow = True
End Function
<font face="Verdana" size="2">
<div align="center"><b>Extending The Browse For Folder Dialog Class</b></div>
<p>This code is simpily extending the Browse For Folder Dialog class that was on posted on PSC by Chris Andersen. After using his code, I was interested in knowing if there was any additional options available aside from just being able to set the title. I consulted the MSDN and this is what I came up with.
The above screen shot is showing the Browse For Folder dialog with StartLocation set to "MyDocuments" and Style set to "BrowseForEverything"</p>
<p><b>.StartLocation</b><br>
<hr width="100%" size="1" color="#000000">
The directory in which the browse dialog will start at. (duh) I haven't found a way to specifiy a certain path, like C:\PSC or something of that nature, but there are a number of members that we can use. They are:
<ul>
<li>Desktop</li>
<li>Favorites</li>
<li>MyComputer</li>
<li>MyDocuments</li>
<li>MyPictures</li>
<li>NetAndDialUpConnections</li>
<li>NetworkNeighborhood</li>
<li>Printers</li>
<li>Recent</li>
<li>SendTo</li>
<li>StartMenu</li>
<li>Templates</li>
</ul>
<p><b>.Style</b><br>
<hr width="100%" size="1" color="#000000">
They style of the browse dialog. We have a few different options to choose from.
<ul>
<li>BrowseForComputer</li>
<li>BrowseForEverything</li>
<li>BrowseForPrinter</li>
<li>RestrictToDomain</li>
<li>RestrictToFilesystem</li>
<li>RestrictToSubfolders</li>
<li>ShowTextBox</li>
</ul>
</p>
<p><b>The Code</b><br>
<hr width="100%" size="1" color="#000000">
Here's an example of how to use the above methods in the Browse For Folder dialog.
<pre><font size="2">
using System;
using System.Windows.Forms;
using System.Windows.Forms.Design;
public class BrowseForFolder : FolderNameEditor
{
FolderNameEditor.FolderBrowser bDialog;
public BrowseForFolder()
{
bDialog = new FolderNameEditor.FolderBrowser();
}
public string browseDialog(string sTitle)
{
bDialog.Description = sTitle;<font color="green">
bDialog.StartLocation = FolderNameEditor.FolderBrowserFolder.MyComputer;
bDialog.Style = FolderNameEditor.FolderBrowserStyles.RestrictToDomain;</font>
bDialog.ShowDialog();
return bDialog.DirectoryPath;
}
~BrowseForFolder()
{
bDialog.Dispose();
}
}
</font></pre>
</p>
<p><b>Useage:</b><br>
<hr width="100%" size="1" color="#000000">
To use this class, make sure you <b>add a reference to System.Design.DLL</b>. Call the class like so:
<pre><font size="2">
BrowseForFolder myDialog = new BrowseForFolder();
MessageBox.Show(myDialog.browseDialog("Dialog Title Goes Here");
</pre>
It's pretty simple. Thanks again to Chris Anderson for the original code.
Commentaires originaux (3)
Récupéré via Wayback Machine