November 22, 2014
Hot Topics:

Programming Windows CE Shell User Interface Elements

  • July 10, 2003
  • By Nancy Nicolaisen
  • Send Email »
  • More Articles »

One of the key tasks of adapting Win32 code to the CE shell is learning how to make applications and documents visible to the user. In the SysMenuGadgets example below, you'll see how to add shortcuts to the HPC and HPC Pro desktop and how to add programs and documents to the Start menu.

Figure 1 - The SysMenuGadgets Example Running on an HPC 2000 Platform



Click here for larger image

You can see the full source code for the SysMenuGadgets program in code files linked to this example on the Developer.com website.

Adding Shortcuts to the Start Menu

The SysMenuGadgets Example collects information from the SysMenuGadgetsDlgProc() and modifies the shell elements accordingly when the user clicks the "Update Shell" button. The "Update Shell" button has the dialog control ID "IDOK", so it also dismisses the dialog immediately after it updates the shell. The rest of the example application behaves in familiar ways, so we'll restrict our attentions to SysMenuGadgetsDlgProc()'s handling of the IDOK command.

First we get the check state of the "Add Start Menu Item" control, and if it is checked, we create a Start Menu program shortcut by calling SHCreateShortcut():

hWndCheckbox = GetDlgItem(hWnd, IDC_ADD_START );
bChecked = SendMessage( hWndCheckbox, BM_GETCHECK,0,0 );
if( bChecked )
{
  if ( ! SHCreateShortcut( 
                  TEXT("\\Windows\\Programs\\HelloWorld.lnk"),
                  TEXT("\\Windows\\HelloWorld.exe")))
  { 
      MessageBox( hWnd, 
                  TEXT("Couldn't Create Shortcut"), 
                  TEXT("ERROR!"), MB_OK );
       return FALSE;
  }

The parameters to SHCreateShortcut(), in the order shown, are a null terminated string specifying the fully qualified name of the shortcut and a null terminated string specifying the fully qualified name of the shortcut's target. By creating the shortcut in the directory "\Windows\Programs", we automatically end up with a start menu shortcut for the program on the HPC and HPC Pro devices. If you want to have more flexibility in targeting, you can include the logic we used in the FindDirs example to retrieve the fully qualified path for the special folder "CSIDL_STARTMENU "

Removing a short cut is a straightforward matter, and we do this if the "Add StartMenu Item" control is unchecked:

else
{
  DeleteFile(TEXT("\\Windows\\Desktop\\HelloWorld.lnk") );
}

Just delete the link file created by SHCreateShortcut(), using the file's fully qualified, null terminated pathname.

Adding and Deleting Shortcuts Without Using the Start Menu

Here's how you create a shortcut to an application if you don't want it to show up on the start menu. This shortcut appears as an icon on the desktop, but it could appear in another location just as easily, also represented as an icon:

hWndCheckbox = GetDlgItem(hWnd,IDC_ADD_SHORTCUT );
bChecked = SendMessage( hWndCheckbox, BM_GETCHECK,0,0 );
if( bChecked )
{
  if ( ! SHCreateShortcut( 

TEXT("\\Windows\\Desktop\\HelloWorld.lnk"), 
                TEXT("\\Windows\\Programs\\HelloWorld.exe")))

Again, you delete this type of shortcut by calling DeleteFile() and passing the fully qualified, null terminated pathname of the link file.

Looking Ahead

In the next installment, we'll see how to add application icons to the most-recently-used list and how to add application icons to the task bar.

Source Code

Download source: Shell-Code.zip - 3kb

About the Author

Nancy Nicolaisen is a software engineer who has designed and implemented highly modular Windows CE products that include features such as full remote diagnostics, CE-side data compression, dynamically constructed user interface, automatic screen size detection, entry time data validation.

In addition to writing for Developer.com, she has written several books including Making Win 32 Applications Mobile.

# # #






Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Rocket Fuel