Home

Microsoft Windows Built-In Dialog Boxes: Change Icon

   

Description

Microsoft Windows XP introduced a dialog box that allows a user to select an icon, from any necessary reason. To make this available in your application, you can call the PickIconDlg() function of the Shlobj.h header file. The syntax of this function is:

int PickIconDlg(
  __in     HWND hwnd,
  __inout  LPWSTR pszIconPath,
  __in     UINT cchIconPath,
  __inout  int *piIconIndex
);

Here is an example of calling it:

//---------------------------------------------------------------------------

#include <vcl.h>
#include <shlobj.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    int Index = 1;
    int Result = 0;

    Result = PickIconDlg(Handle,
     			 L"C:\\Exercise\\Graphics\\icons",
     			 255,
     			 &Index);
}
//---------------------------------------------------------------------------

When calling this function, if there is no icon in the path you provided, an empty dialog box would display. If there are icons in the specified path, they would appear in the dialog box. Consider the following example:

//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	int Index  = 0;
	int Result = 0;
	WCHAR Path[MAX_PATH] = L"C:\\Windows\\System32\\shell32.dll";

	Result = PickIconDlg(NULL, Path, MAX_PATH, &Index);
}
//---------------------------------------------------------------------------

This would produce:

Change Icon

 

 

 
 

Home Copyright © 2010-2016, FunctionX