Cross-Platform Mobile App Development Tools

Advertisements

Famous Software Developed by Delphi

  • IcoFX
  • Skype
  • Nero Burning Rom
  • Kingsoft Office
  • KM Player
  • Panda Antivirus
  • Ultra ISO
  • GoldWave
  • Age of Wonders (game)
  • FL Studio
  • Total Commander
  • Macromedia Dreamweaver
  • Inno Setup
  • InstallAware
  • Partition Magic
  • PhpED

Disable Windows Shortcuts in Delphi Application

This code disables:

  • Ctrl+Esc (show start menu)
  • Alt+Tab (task switch)
  • Alt+Esc (task switch)
  • Win (show start menu)
  • Win+Tab (3D task switch)
  • Win+D, Win+M, Win+Space, Win+Arrows, Win+P, Win+U, Win+E, Win+F, Win+Digit
function LowLevelKeyboardProc(nCode: integer; wParam: WPARAM; lParam: LPARAM):
LRESULT; stdcall;
type
PKBDLLHOOKSTRUCT = ^TKBDLLHOOKSTRUCT;
TKBDLLHOOKSTRUCT = record
vkCode: cardinal;
scanCode: cardinal;
flags: cardinal;
time: cardinal;
dwExtraInfo: Cardinal;
end;
PKeyboardLowLevelHookStruct = ^TKeyboardLowLevelHookStruct;
TKeyboardLowLevelHookStruct = TKBDLLHOOKSTRUCT;
const
LLKHF_ALTDOWN = $20;
var
hs: PKeyboardLowLevelHookStruct;
ctrlDown: boolean;
begin
if nCode = HC_ACTION then
begin
hs := PKeyboardLowLevelHookStruct(lParam); ctrlDown := GetAsyncKeyState(VK_CONTROL) and $8000 <> 0; if (hs^.vkCode = VK_ESCAPE) and ctrlDown then Exit(1); if (hs^.vkCode = VK_TAB) and ((hs^.flags and LLKHF_ALTDOWN) <> 0) then Exit(1); if (hs^.vkCode = VK_ESCAPE) and ((hs^.flags and LLKHF_ALTDOWN) <> 0) then Exit(1); if (hs^.vkCode = VK_LWIN) or (hs^.vkCode = VK_RWIN) then Exit(1);
end;
result := CallNextHookEx(0, nCode, wParam, lParam);
end;

procedure TForm1.FormShow(Sender: TObject);
begin
SetWindowsHookEx(WH_KEYBOARD_LL, @LowLevelKeyboardProc, 0, 0);
end;

Windows Service Application Tips

From Vista, Service applications run on different session, not on user’s session.

  • If Shellexecute something, it won’t be visible to user, but it will work background.
  • If Beep, it won’t be heard.

You need the main form. It is not visible though. Change its DisplayName property. It is the Service’s DisplayName.

Use TBrowseForFolder the right way

Wrong way: (If user clicks CANCEL, it still accepts the value)

var
MyBrowse: TBrowseForFolder;
begin
MyBrowse:=TBrowseForFolder.Create(nil);
try
MyBrowse.BrowseOptionsEx:=[bifeAllowMultiselect];
MyBrowse.Caption:='Select folder:';
MyBrowse.Folder:=lastfolder;
if MyBrowse.Execute then
begin
if trim(MyBrowse.Folder)<>'' then
begin
lastfolder:=MyBrowse.Folder;
ListBox1.Items.Add(MyBrowse.Folder);
end;
end;
finally
MyBrowse.Free;
end;
end;

Correct way:

procedure TForm1.Button1Click(Sender: TObject);
begin
MyBrowse:=TBrowseForFolder.Create(nil);
try
MyBrowse.BrowseOptionsEx:=[bifeAllowMultiselect];
MyBrowse.Caption:='Select folder:';
MyBrowse.Folder:=lastfolder;
MyBrowse.OnAccept:=BrowseForFolderOnAccept;
MyBrowse.Execute;
finally
MyBrowse.Free;
end;
end;

procedure TForm1.BrowseForFolderOnAccept(Sender: TObject);
begin
if trim(MyBrowse.Folder)<>'' then
begin
lastfolder:=MyBrowse.Folder;
ListBox1.Items.Add(MyBrowse.Folder);
end;
end;

Uses Vcl.StdActns