home *** CD-ROM | disk | FTP | other *** search
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
-
- #include <shellapi.hpp>
- #include "UndocForm.h"
-
- typedef BOOL (CALLBACK* PICKICONDLGPROC)(HWND, LPSTR, DWORD, LPDWORD);
-
- HMODULE ShellLib;
- PICKICONDLGPROC PickIconDlg;
-
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- // Get a handle to SHELL32.DLL library
- ShellLib = LoadLibrary ("SHELL32.DLL");
- if (ShellLib == 0) MessageBox (0, "SHELL32.DLL not found", "Ooops!", MB_OK); else {
- // Now get a pointer to the Icon Picker dialog proc
- PickIconDlg = (PICKICONDLGPROC) GetProcAddress (ShellLib, MAKEINTRESOURCE (62));
- if (PickIconDlg == 0) MessageBox (0, "PickIconDlg routine not found", "Ooops!", MB_OK);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormDestroy(TObject *Sender)
- {
- if (ShellLib != 0) FreeLibrary (ShellLib);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::PickerClick(TObject *Sender)
- {
- AnsiString S;
- DWORD iconIndex;
- char szFileName [256];
-
- if (PickIconDlg != 0) {
- GetModuleFileName (ShellLib, szFileName, sizeof (szFileName));
- if (PickIconDlg (Handle, szFileName, sizeof (szFileName), &iconIndex)) {
- Image->Picture->Icon->Handle = ExtractIcon (HInstance, szFileName, iconIndex);
- Label1->Caption = "Icon selected: " + StrPas (szFileName) + " (index=" + IntToStr (iconIndex) + ")";
- }
- }
- }
- //---------------------------------------------------------------------------
-