Dimensions of Image in Delphi

uses Vcl.Graphics;

var
  pict: TPicture;
begin
  pict := TPicture.Create;
  try
    pict.LoadFromFile(imagefile);
    Height:=pict.Height;
    Width:=pict.Width;
  finally
    pict.Free;
  end;
end;
Advertisements

How to create Self-Signed Code Signing Certificate

Install Windows SDK for Windows 7

cmd with Admin Priviliges

cd C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin

makecert -r -pe -n “CN=My CA” -ss CA -sr CurrentUser -a sha256 -cy authority -sky signature -sv MyCA.pvk MyCA.cer

certutil -user -addstore Root MyCA.cer

makecert -pe -n “CN=My SPC” -a sha256 -cy end -sky signature -ic MyCA.cer -iv MyCA.pvk -sv MySPC.pvk MySPC.cer

pvk2pfx -pvk MySPC.pvk -spc MySPC.cer -pfx MySPC.pfx

signtool sign /v /f MySPC.pfx /t http://timestamp.url MyExecutable.exe

Timestamp URLs:
http://timestamp.verisign.com/scripts/timstamp.dll
http://timestamp.globalsign.com/scripts/timstamp.dll
http://timestamp.comodoca.com/authenticode

Delphi HttpResponse Error Solution

Error: No mapping for the Unicode character exists in the target multi-byte code page

var
HttpClient: THttpClient;
HttpResponse: IHttpResponse;
begin
HttpClient := THTTPClient.Create;
try
HttpResponse := HttpClient.Get(AURL);
//Result := HttpResponse.ContentAsString();
Result := HttpResponse.ContentAsString(TEncoding.ANSI);
finally
HttpClient.Free;
end;
end;

Delphi Elevated Application Drag & Drop

Dragging & dropping files (Explorer) to elevated application:

procedure SetDragAndDropOnSystemsWIthUAC(Wnd : HWND; IsEnabled : boolean);
type
  TChangeWindowMessageFilter = function(Msg : Cardinal; Action : Word) : Bool; stdcall;
const
  Msg_Add = 1;
  WM_COPYGLOBALDATA = $49;
var
  DllHandle : THandle;
  ChangeWindowMessageFilter : TChangeWindowMessageFilter;
begin
  DllHandle := LoadLibrary('user32.dll');
  if DllHandle > 0 then
  begin
    ChangeWindowMessageFilter := GetProcAddress(DllHandle, 'ChangeWindowMessageFilter');
    if Assigned(ChangeWindowMessageFilter) then
    begin
      DragAcceptFiles(Wnd, IsEnabled);
      ChangeWindowMessageFilter(WM_DROPFILES, Msg_Add);
      ChangeWindowMessageFilter(WM_COPYGLOBALDATA, Msg_Add);
    end;
  end;
end;