Recent

Author Topic: Changing/Overlay Dock Icon  (Read 4965 times)

rajivsoft

  • New Member
  • *
  • Posts: 48
Changing/Overlay Dock Icon
« on: March 21, 2011, 01:06:35 pm »
After some headache i'd digget out how to programmatically change dock icon:
Code: Pascal  [Select]
  1. uses
  2.   ... MacOSAll ...
  3.  
  4.  
  5. procedure TFrm_Main.FormCreate(Sender: TObject);
  6. begin
  7.   ...
  8.   FResPath := TrimFilename(ExtractFilePath(Application.ExeName) + PathDelim + 'Resource');
  9.   ...
  10. end;
  11.  
  12. procedure TFrm_Main.SomeEventWhenOverlay(SomeVar: Integer);
  13. var
  14.   temp_ImagePath: String;
  15.   temp_CGDataProvider: CGDataProviderRef;
  16.   temp_Float32Ptr: Float32Ptr;
  17.   temp_CGImage: CGImageRef;
  18.   temp_CGContext: CGContextRef;
  19. begin
  20.   temp_ImagePath := TrimFilename(FResPath + PathDelim + 'Image' + PathDelim + 'overlay_image.png'); // image must be same size as icon, if not, will be deformed
  21.   if (FileExists(temp_ImagePath)) then
  22.   begin
  23.     temp_CGDataProvider := CGDataProviderCreateWithFilename(PChar(temp_ImagePath));
  24.     temp_Float32Ptr := nil;
  25.     temp_CGImage := CGImageCreateWithPNGDataProvider(temp_CGDataProvider, temp_Float32Ptr, 1, kCGRenderingIntentDefault);
  26.     CGDataProviderRelease(temp_CGDataProvider);
  27.     // Draw image
  28.     temp_CGContext := BeginCGContextForApplicationDockTile;
  29.     //SetApplicationDockTileImage(temp_CGImage);
  30.     OverlayApplicationDockTileImage(temp_CGImage);
  31.     CGImageRelease(temp_CGImage);
  32.     EndCGContextForApplicationDockTile(temp_CGContext);
  33.   end;  
  34. end;
  35.  
  36. procedure TFrm_Main.SomeOtherEventWhenRestore();
  37. begin
  38.   //This will not work if you use SetApplicationDockTileImage
  39.   RestoreApplicationDockTileImage;
  40. end;
  41.