Developers Archive for July, 2007

Shell Programming Using C# (contd) For Creating an AutoCompleteSection

Shell Programming Using C# (contd) For Creating an AutoCompleteSection Tuesday, July 17th, 2007

For creating an Autocomplete Section

AutoComplete section deals with creating an application which enables the AutoComplete in ListBox as in Run Command and also in Combo Box as in Browser URL address bar.

The Application here gets the details which details has to be AutoCompleted in the listboxes and also it auto suggests. The AutoSuggest is to suggest you full string when you type partial string.

The AutoComplete gets the following parameters to complete the List Box and the combo box.

  • File System
  • URL History
  • Recent Used
  • Use Tab
  • Sys file
  • Sys Dirs

 

By checking one or all these parameters it executes the process and autocompletes the listbox .They have AutoSuggest on and off and along with AutoAppend on and off options to enable or disable Auto suggest and Auto Append.

All the above said parameters are being used to Autoappend and Autosuggest in the ListBox.

For Adding the Auto Complete files to the ComboBox the following parameters are added.

Multisources Like History, Recently visited , My Namespace,Custom List are used as the Parameters.

They need to have Autosuggeste and AutoAppend parameters checked and then they can enable to combo box to display the appended and auto suggested information.

The AutoComplete Process uses the following functions

  1. InterfaceAutoCompleteList
  2. InterfaceAutoCompleteList2
  3. InterfaceAutoComplete
  4. InterfaceAutoComplete2
  5. InterfaceObjectManager
  6. ShellAutoComplete.

 

[ComImport]

[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]

[Guid("470141A0-5186-11D2-BBB6-0060977B464C")]

public interface InterfaceAutoCompleteList

{

///

/// Sets the current autocomplete options.

///

[PreserveSig]

Int32 SetOptions(

UInt32 dwFlag); // New option flags. Use these flags to ask the client to include the names

// of the files and subfolders of the specified folders the next time the

// client's IEnumString interface is called.

///

/// Retrieves the current autocomplete options.

///

[PreserveSig]

Int32 GetOptions(

out UInt32 pdwFlag); // Pointer to a value that will hold the current option flag when the

// method returns.

}

This figure Shows the Parameters to be checked to AutoComplete the EditBox.

 

 

This figure shows the AutoCompleted Result, which shows autocompleted and autosuggested values.

 

 

This figure Shows the AutoCompleted Combo Box and the URL details which are shown once they select the combo Box.

 

Conclusion for Fourth Section

In this section we discussed about the Auto complete Process that can be accomplished using Shell.

Shell Programming Using C# (contd) To Create an application desktop tool bar

Shell Programming Using C# (contd) To Create an application desktop tool bar Tuesday, July 17th, 2007

To Create an application desktop tool bar 

This Section is also Shell concept implemented thing and the main functionality in this section is creating another tool bar to be displayed in the desktop. The tool bar is same as the TaskBar in desktop but it is displayed using the Shell concept. The UI has been created first and the section of the bar is displayed in the desktop.

The Desktop Application ToolBar is created in such a way that it is displayed in the appropriate place which is calculated by the OS. The Shell commands intereacts with the OS and the OS checks with the compatibility of displaying the tool bar in the desktop.

Then after displaying the Task Bar has three radio buttons to select on which area it has to be displayed. Like TOP,BOTTOM,LEFT,RIGHT according to the selection the tool bar is displayed.

To display the application tool bar the toolbar has to be registered. The registration is done by sending the message AppBarMessages.New. when this message is sent the following members of the APPBARDATA struct should be set. the hWnd should be set to our window handle, the uCallbackMessage should be set to a unique message id that the OS will use to communicate with our program.

We can set the AppBar Size and location and they are passed to OS which will check with other objects, to not to disturb their display in the desktop.

The Sample Code is attached for creating the Application Desktop ToolBar.

public class ApplicationDesktopToolbarDemo : Form

{

#region Enums

public enum AppBarMessagesDemo

{

///

/// Registers a new appbar and specifies the message identifier

/// that the system should use to send notification messages to

/// the appbar.

///

NewBar = 0x00000000,

///

/// Unregisters an appbar, removing the bar from the system's

/// internal list.

///

RemoveBar = 0x00000001,

///

/// Requests a size and screen position for an appbar.

///

QueryPosition = 0x00000002,

///

/// Sets the size and screen position of an appbar.

///

SetPosition = 0x00000003,

///

/// Retrieves the autohide and always-on-top states of the

/// Microsoft® Windows® taskbar.

///

GetStateOfBar = 0x00000004,

///

/// Retrieves the bounding rectangle of the Windows taskbar.

///

GetTaskBarPos = 0x00000005,

///

/// Notifies the system that an appbar has been activated.

///

ActivateBar = 0x00000006,

///

/// Retrieves the handle to the autohide appbar associated with

/// a particular edge of the screen.

///

GetAutoHideBar = 0x00000007,

///

/// Registers or unregisters an autohide appbar for an edge of

/// the screen.

///

SetAutoHideBar = 0x00000008,

///

/// Notifies the system when an appbar's position has changed.

///

WindowPosChanged = 0x00000009,

///

/// Sets the state of the appbar's autohide and always-on-top

/// attributes.

///

SetState = 0x0000000a

}

public enum AppBarNotificationsDemo

{

///

/// Notifies an appbar that the taskbar's autohide or

/// always-on-top state has changed—that is, the user has selected

/// or cleared the "Always on top" or "Auto hide" check box on the

/// taskbar's property sheet.

///

StateChangeofBar = 0x00000000,

///

/// Notifies an appbar when an event has occurred that may affect

/// the appbar's size and position. Events include changes in the

/// taskbar's size, position, and visibility state, as well as the

/// addition, removal, or resizing of another appbar on the same

/// side of the screen.

///

PosChanged = 0x00000001,

///

/// Notifies an appbar when a full-screen application is opening or

/// closing. This notification is sent in the form of an

/// application-defined message that is set by the ABM_NEW message.

///

FullScreenApp = 0x00000002,

///

/// Notifies an appbar that the user has selected the Cascade,

/// Tile Horizontally, or Tile Vertically command from the

/// taskbar's shortcut menu.

///

WindowArrange = 0x00000003

}

[Flags]

public enum AppBarStates

{

AutoHide = 0x00000001,

AlwaysOnTop = 0x00000002

}

public enum AppBarEdges

{

Left = 0,

Top = 1,

Right = 2,

Bottom = 3,

Float = 4

}

// Window Messages

public enum WM

{

ACTIVATE = 0x0006,

WINDOWPOSCHANGED = 0x0047,

NCHITTEST = 0x0084

}

public enum MousePositionCodes

{

HTERROR = (-2),

HTTRANSPARENT = (-1),

HTNOWHERE = 0,

HTCLIENT = 1,

HTCAPTION = 2,

HTSYSMENU = 3,

HTGROWBOX = 4,

HTSIZE = HTGROWBOX,

HTMENU = 5,

HTHSCROLL = 6,

HTVSCROLL = 7,

HTMINBUTTON = 8,

HTMAXBUTTON = 9,

HTLEFT = 10,

HTRIGHT = 11,

HTTOP = 12,

HTTOPLEFT = 13,

HTTOPRIGHT = 14,

HTBOTTOM = 15,

HTBOTTOMLEFT = 16,

HTBOTTOMRIGHT = 17,

HTBORDER = 18,

HTREDUCE = HTMINBUTTON,

HTZOOM = HTMAXBUTTON,

HTSIZEFIRST = HTLEFT,

HTSIZELAST = HTBOTTOMRIGHT,

HTOBJECT = 19,

HTCLOSE = 20,

HTHELP = 21

}

#endregion Enums

 

 

  

In this section the Application tool bar is been created using the ApplicationToolBarDemo function and the Bar is registered with the OS so as to display them in the desktop.

The Parameters are passed to the OS which processes the data parameters and sets the ToolBar in the Desktop window.

The Size and Postion of the Toolbar is sent to the OS which changes the display of the Toolbar on the Desktop.

By default the tool bar is displayed in the left corner and the Yahoo Button with the Timer control added in it.

The Toolbar demo has TOP, BOTTOM,LEFT,RIGHT radio buttons which when selected the Bar will be displayed in the appropriate places.

The Figure shows the display of the Bar on the desktop, which is placed in the left corner by default and then the other desktop controls are displayed next to it.

The shell commands passed the parameters to OS and then the bar is displayed in the Desktop without disturbing the other controls.

 

 

 

The Above figure Shows the Application Desktop ToolBar which is executed and displayed in the desktop. That has the timer added in them. Yahoo button is also there which when clicked the yahoo website will be opened.

The Yahoo button in this section implements the SectionSecond Shell Concept of file operations and opens IE for yahoo website.

 

Conclusion for Third Section

Using C# we can extend Shell application to create a Desktop application tool bar with timer and a Button.

 

 

 

Shell Programming Using C# (contd) Creating Shell Extended Application for File Operations

Shell Programming Using C# (contd) Creating Shell Extended Application for File Operations Tuesday, July 17th, 2007

Creating Shell Extended Application for File Operations 

Second Section deals with the shell concept programming towards creating file operation.The file operations enables the user to manage files using the Shell applications. User can launch any application in one click. They can open an image file copy files to other files, copy folders to other folders, move folders to othe folders,move files to other files, and they can add the specific file the recent list and also can clear the recent list.
In this section the shell concept includes a function used to create an application in which when a file is selected and opened opens the appropriate editor or launches the application.
For example:
When we select a bmp file and open it , it will automatically opens in the editor or launched in the applications like Image Viewer.
For doing these operation Shell needs some parameters passed from the UI to the Shell.The Parameters are Verbs like(Open , Edit , Delete , Copy , Move) along with file names.
To perform these operations we need to have a specific function which could take care of all the concepts and operations. So we create a Shell Execute Function to enable the File Operations.
The Shell Execute class is responsible for all the File Operations like open, edit, delete, move and copy. The function Shell Exexute would find which process has to be performed and when it needs to be called.
The Files specified will also be added to the recent list when we add the function to add the file to recent list using the Shell Programming.

public enum FileOperationsDem0{

FILE_MOVE = 0x0001, // Move the files specified in pFrom to the location specified in pTo.

FILE_COPY = 0x0002, // Copy the files specified in the pFrom member to the location specified

// in the pTo member.

FILE_DELETE = 0x0003, // Delete the files specified in pFrom.

FILE_RENAME = 0x0004 // Rename the file specified in pFrom. You cannot use this flag to rename

// multiple files with a single function call. Use FO_MOVE instead.

}

[Flags]

public enum ShellFileOperationFlags

{

FILE_MULTIDESTFILES = 0x0001, // The pTo member specifies multiple destination files (one for

// each source file) rather than one directory where all source

// files are to be deposited.

FILE_CONFIRMMOUSE = 0x0002, // Not currently used.

FILE_SILENT = 0x0004, // Do not display a progress dialog box.

FILE_RENAMEONCOLLISION = 0x0008, // Give the file being operated on a new name in a move, copy, or

// rename operation if a file with the target name already exists.

FILE_NOCONFIRMATION = 0x0010, // Respond with "Yes to All" for any dialog box that is displayed.

FILE_WANTMAPPINGHANDLE = 0x0020, // If FOF_RENAMEONCOLLISION is specified and any files were renamed,

// assign a name mapping object containing their old and new names

// to the hNameMappings member.

FILE_ALLOWUNDO = 0x0040, // Preserve Undo information, if possible. If pFrom does not

// contain fully qualified path and file names, this flag is ignored.

FILE_FILESONLY = 0x0080, // Perform the operation on files only if a wildcard file

// name (*.*) is specified.

FILE_SIMPLEPROGRESS = 0x0100, // Display a progress dialog box but do not show the file names.

FILE_NOCONFIRMMKDIR = 0x0200, // Do not confirm the creation of a new directory if the operation

// requires one to be created.

FILE_NOERRORUI = 0x0400, // Do not display a user interface if an error occurs.

FILE_NOCOPYSECURITYATTRIBS = 0x0800, // Do not copy the security attributes of the file.

FILE_NORECURSION = 0x1000, // Only operate in the local directory. Don't operate recursively

// into subdirectories.

FILE_NO_CONNECTED_ELEMENTS = 0x2000, // Do not move connected files as a group. Only move the

// specified files.

FILE_WANTNUKEWARNING = 0x4000, // Send a warning if a file is being destroyed during a delete

// operation rather than recycled. This flag partially

// overrides FOF_NOCONFIRMATION.

FILE_NORECURSEREPARSE = 0x8000 // Treat reparse points as objects, not containers.

}

 

  

The above figure shows the Operations that could be done using the Shell.

Open EXE:

This operation enables the file specified in the textbox to open. The Process is a shell based process which checks the files or folders and opens them. ShellExecParam function enables the process and opens the selected files. The Parameters are passed to the function and the process executes

Show BMP:

This operation enables the BMP or JPEG files to be opened in the Image Viewer. The ShellExecParam function enables the process and opens the selected image. The Parameter are passed to the function and executed.

This operation is same as Show BMP it opens the image in the editor enabling the editing of the images.The parameters are all passed to the function including file name.

Find in folder:

This operation enables the Find process in a specified foler. It displays the Search for the files Window and selects the specified file path in it.

Explore folder:

This Operation enalbes the exploring the folders specified. This Opens the entire folder and all the sub folders are displayed.

Copy , Move , Delete Files

The File names (Source and the Destination) are given for the Copy and Move operations. The Copy file copies entire file to another file having the backup of the source.

The Move File moves entire file to another without backup.

The Delete Files removes the specified file from the folder specified.

The Folders are also be used for Move, Copy , Delete Operations.

Add Recent Files

The Add recent files is the process of adding the Recently Opened files to the Recent Documents. It has the unique process to add the Recent files.

Clear Recent Files.This Process clears the recent files added.


This figure shows the Explore Foler option which opens the specified folder and all the sub folders in it are shown in the right pane.

The Figure 2.3 shows the file open process , in which specified file is opened and shown with the appropriate eidtor

Figure 2.4 shows the Image file opend in the Image Viewer.

Figure 2.5 shows the image files opened in appropriate file when the image file name is given.

Figure 2.6 shows the Find folder Process which opens the search window for the specified folder or directory. The process uses the Shell commands to display the results.

Conclusion for Second Section

In this section we discussed about the File Operations that can be done and customized using Shell in C#.

 


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.