home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 May / PCP163A.iso / handson / files / copycpp.exe / UndocForm.cpp next >
Encoding:
C/C++ Source or Header  |  2000-02-07  |  2.0 KB  |  54 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include <shellapi.hpp>
  6. #include "UndocForm.h"
  7.  
  8. typedef BOOL (CALLBACK* PICKICONDLGPROC)(HWND, LPSTR, DWORD, LPDWORD);
  9.  
  10. HMODULE ShellLib;
  11. PICKICONDLGPROC PickIconDlg;
  12.  
  13. //---------------------------------------------------------------------------
  14. #pragma package(smart_init)
  15. #pragma resource "*.dfm"
  16. TForm1 *Form1;
  17. //---------------------------------------------------------------------------
  18. __fastcall TForm1::TForm1(TComponent* Owner)
  19.     : TForm(Owner)
  20. {
  21. }
  22. //---------------------------------------------------------------------------
  23. void __fastcall TForm1::FormCreate(TObject *Sender)
  24. {
  25.     // Get a handle to SHELL32.DLL library
  26.     ShellLib = LoadLibrary ("SHELL32.DLL");
  27.     if (ShellLib == 0) MessageBox (0, "SHELL32.DLL not found", "Ooops!", MB_OK); else {
  28.         // Now get a pointer to the Icon Picker dialog proc
  29.         PickIconDlg = (PICKICONDLGPROC) GetProcAddress (ShellLib, MAKEINTRESOURCE (62));
  30.         if (PickIconDlg == 0) MessageBox (0, "PickIconDlg routine not found", "Ooops!", MB_OK);
  31.     }
  32. }
  33. //---------------------------------------------------------------------------
  34. void __fastcall TForm1::FormDestroy(TObject *Sender)
  35. {
  36.     if (ShellLib != 0) FreeLibrary (ShellLib);
  37. }
  38. //---------------------------------------------------------------------------
  39. void __fastcall TForm1::PickerClick(TObject *Sender)
  40. {
  41.     AnsiString S;
  42.     DWORD iconIndex;
  43.     char szFileName [256];
  44.  
  45.     if (PickIconDlg != 0) {
  46.         GetModuleFileName (ShellLib, szFileName, sizeof (szFileName));
  47.         if (PickIconDlg (Handle, szFileName, sizeof (szFileName), &iconIndex)) {
  48.             Image->Picture->Icon->Handle = ExtractIcon (HInstance, szFileName, iconIndex);
  49.             Label1->Caption = "Icon selected: " + StrPas (szFileName) + " (index=" + IntToStr (iconIndex) + ")";
  50.         }
  51.     }
  52. }
  53. //---------------------------------------------------------------------------
  54.