1 http://www.delphi-tipps.de/ 2 http://www.dsdt.info/tipps/ 3 http://www.umnicom.de/Software/Delphi/TipsUndTricks/TipsUndTricks.html 4 http://www.delphipraxis.net/code_library.html 5 http://www.ensacom.de/ 6 7 ################################################################################################### 8 eigene Form mit Schatten anzeigen (WinXP) 9 10 protected 11 procedure CreateParams(var Params: TCreateParams); 12 override; 13 14 15 16 17 18 procedure TForm1.CreateParams(var Params: TCreateParams); 19 const 20 CS_DROPSHADOW = $00020000; 21 begin 22 inherited; 23 Params.WindowClass.Style := Params.WindowClass.Style or CS_DROPSHADOW; 24 end; 25 26 ################################################################################################### 27 Url des aktiven Browserfensters erfahren 28 29 uses ddeman; 30 function GetActiveBrowsersURL(Service: string): String; 31 var 32 ClDDE: TDDEClientConv; 33 zwi:PChar; 34 begin 35 Result:= ''; 36 ClDDE:= TDDEClientConv.Create(nil); 37 with ClDDE do 38 begin 39 SetLink(Service,'WWW_GetWindowInfo'); 40 zwi:= RequestData('0xFFFFFFFF'); 41 Result:= StrPas(zwi); 42 StrDispose(zwi); 43 CloseLink; 44 end; 45 ClDDE.Free; 46 end; 47 48 ################################################################################################### 49 50 ...die eingegebenen URLs vom Internet Explorer auslesen? 51 52 uses registry; 53 54 procedure ShowTypedUrls(Urls: TStrings); 55 var 56 Reg: TRegistry; 57 S: TStringList; 58 i: Integer; 59 begin 60 Reg := TRegistry.Create; 61 try 62 Reg.RootKey := HKEY_CURRENT_USER; 63 if Reg.OpenKey('Software\Microsoft\Internet Explorer\TypedURLs', False) then 64 begin 65 S := TStringList.Create; 66 try 67 reg.GetValueNames(S); 68 for i := 0 to S.Count - 1 do 69 begin 70 Urls.Add(reg.ReadString(S.Strings[i])); 71 end; 72 finally 73 S.Free; 74 end; 75 Reg.CloseKey; 76 end; 77 finally 78 Reg.Free; 79 end; 80 end; 81 82 procedure TForm1.Button1Click(Sender: TObject); 83 begin 84 ShowTypedUrls(ListBox1.Items); 85 end; 86 87 ################################################################################################### 88 Netzwerk verbunden? 89 90 function IsNetworkConnected: Boolean; 91 begin 92 if GetSystemMetrics(SM_NETWORK) AND $01 = $01 then 93 Result := True 94 else 95 Result := False; 96 end; 97 98 ################################################################################################### 99 Computernamen des eigenen Rechners ermitteln 100 101 function GetComputerName: String; 102 var 103 Len: DWORD; 104 begin 105 Len:=MAX_COMPUTERNAME_LENGTH+1; 106 SetLength(Result,Len); 107 if Windows.GetComputerName(PChar(Result), Len) then 108 SetLength(Result,Len) 109 else 110 RaiseLastOSError; 111 end; 112 113 ################################################################################################### 114 Benutzernamen ermitteln 115 116 function GetUsername: String; 117 var 118 Buffer: array[0..255] of Char; 119 Size: DWord; 120 begin 121 Size := SizeOf(Buffer); 122 if not Windows.GetUserName(Buffer, Size) then 123 RaiseLastOSError; //RaiseLastWin32Error; {Bis D5}; 124 SetString(Result, Buffer, Size - 1); 125 end; 126 127 ################################################################################################### 128 ...eine Form nicht vergrößerbar aber verschiebbar machen? 129 130 private 131 procedure WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo); message WM_GETMINMAXINFO; 132 end; 133 134 135 implementation 136 137 procedure TForm1.WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo); 138 begin 139 inherited; 140 with Msg.MinMaxInfo^ do 141 begin 142 ptMinTrackSize.x := Form1.Width; 143 ptMaxTrackSize.x := Form1.Width; 144 ptMinTrackSize.y := Form1.Height; 145 ptMaxTrackSize.y := Form1.Height; 146 end; 147 end; 148 149 ################################################################################################### 150 ...verhindern, dass eine Form bewegt werden kann? 151 152 private 153 procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST; 154 155 procedure TForm1.WMNCHitTest(var Message: TWMNCHitTest); 156 begin 157 inherited; 158 159 with Message do 160 begin 161 if Result = HTCAPTION then 162 Result := HTNOWHERE; 163 end; 164 end; 165 166 ################################################################################################### 167 ...die Titelleiste ausblenden? 168 169 procedure TForm1.HideTitlebar; 170 var 171 Style: Longint; 172 begin 173 if BorderStyle = bsNone then Exit; 174 Style := GetWindowLong(Handle, GWL_STYLE); 175 if (Style and WS_CAPTION) = WS_CAPTION then 176 begin 177 case BorderStyle of 178 bsSingle, 179 bsSizeable: SetWindowLong(Handle, GWL_STYLE, Style and 180 (not (WS_CAPTION)) or WS_BORDER); 181 bsDialog: SetWindowLong(Handle, GWL_STYLE, Style and 182 (not (WS_CAPTION)) or DS_MODALFRAME or WS_DLGFRAME); 183 end; 184 Height := Height - GetSystemMetrics(SM_CYCAPTION); 185 Refresh; 186 end; 187 end; 188 189 procedure TForm1.ShowTitlebar; 190 var 191 Style: Longint; 192 begin 193 if BorderStyle = bsNone then Exit; 194 Style := GetWindowLong(Handle, GWL_STYLE); 195 if (Style and WS_CAPTION) <> WS_CAPTION then 196 begin 197 case BorderStyle of 198 bsSingle, 199 bsSizeable: SetWindowLong(Handle, GWL_STYLE, Style or WS_CAPTION or 200 WS_BORDER); 201 bsDialog: SetWindowLong(Handle, GWL_STYLE, 202 Style or WS_CAPTION or DS_MODALFRAME or WS_DLGFRAME); 203 end; 204 Height := Height + GetSystemMetrics(SM_CYCAPTION); 205 Refresh; 206 end; 207 end; 208 209 procedure TForm1.Button1Click(Sender: TObject); 210 begin 211 HideTitlebar; 212 end; 213 214 procedure TForm1.Button2Click(Sender: TObject); 215 begin 216 ShowTitlebar; 217 end; 218 219 ################################################################################################### 220 ...Text in einer Text Datei ersetzen? 221 222 procedure FileReplaceString(const FileName, searchstring, replacestring: string); 223 var 224 fs: TFileStream; 225 S: string; 226 begin 227 fs := TFileStream.Create(FileName, fmOpenread or fmShareDenyNone); 228 try 229 SetLength(S, fs.Size); 230 fs.ReadBuffer(S[1], fs.Size); 231 finally 232 fs.Free; 233 end; 234 S := StringReplace(S, SearchString, replaceString, [rfReplaceAll, rfIgnoreCase]); 235 fs := TFileStream.Create(FileName, fmCreate); 236 try 237 fs.WriteBuffer(S[1], Length(S)); 238 finally 239 fs.Free; 240 end; 241 end; 242 243 ################################################################################################### 244 ...den Text einer Datei einem String zuweisen? 245 246 function GetTextFromFile(AFile: string; var Returnstring: string): Boolean; 247 var 248 FileStream: TFileStream; 249 begin 250 Result := False; 251 if not FileExists(AFile) then Exit; 252 FileStream := TFileStream.Create(AFile, fmOpenRead); 253 try 254 if FileStream.Size <> 0 then 255 begin 256 SetLength(Returnstring, FileStream.Size); 257 FileStream.Read(Returnstring[1], FileStream.Size); 258 Result := True; 259 end; 260 finally 261 FileStream.Free; 262 end; 263 end; 264 265 procedure TForm1.Button1Click(Sender: TObject); 266 var 267 s: string; 268 begin 269 if GetTextFromFile('c:\autoexec.bat', s) then 270 begin 271 ShowMessage(s); 272 // Label1.caption := s; or assign the text to a Label 273 // Memo1.text := s; or a memo 274 end; 275 end; 276 277 ################################################################################################### 278 ...INI Dateien verwenden? (*.ini) 279 280 { 281 An INI file stores information in logical groupings, called “sections.” 282 Within each section, actual data values are stored in named keys. 283 284 [Section_Name] 285 Key_Name1=Value1 286 Key_Name2=Value2 287 288 } 289 290 uses 291 IniFiles; 292 293 // Write values to a INI file 294 295 procedure TForm1.Button1Click(Sender: TObject); 296 var 297 ini: TIniFile; 298 begin 299 // Create INI Object and open or create file test.ini 300 ini := TIniFile.Create('c:\MyIni.ini'); 301 try 302 // Write a string value to the INI file. 303 ini.WriteString('Section_Name', 'Key_Name', 'String Value'); 304 // Write a integer value to the INI file. 305 ini.WriteInteger('Section_Name', 'Key_Name', 2002); 306 // Write a boolean value to the INI file. 307 ini.WriteBool('Section_Name', 'Key_Name', True); 308 finally 309 ini.Free; 310 end; 311 end; 312 313 314 // Read values from an INI file 315 316 procedure TForm1.Button2Click(Sender: TObject); 317 var 318 ini: TIniFile; 319 res: string; 320 begin 321 // Create INI Object and open or create file test.ini 322 ini := TIniFile.Create('c:\MyIni.ini'); 323 try 324 res := ini.ReadString('Section_Name', 'Key_Name', 'default value'); 325 MessageDlg('Value of Section: ' + res, mtInformation, [mbOK], 0); 326 finally 327 ini.Free; 328 end; 329 end; 330 331 // Read all sections 332 333 procedure TForm1.Button3Click(Sender: TObject); 334 var 335 ini: TIniFile; 336 begin 337 ListBox1.Clear; 338 ini := TIniFile.Create('MyIni.ini'); 339 try 340 ini.ReadSections(listBox1.Items); 341 finally 342 ini.Free; 343 end; 344 end; 345 346 // Read a section 347 348 procedure TForm1.Button4Click(Sender: TObject); 349 var 350 ini: TIniFile; 351 begin 352 ini: = TIniFile.Create('WIN.INI'); 353 try 354 ini.ReadSection('Desktop', ListBox1.Items); 355 finally 356 ini.Free; 357 end; 358 end; 359 360 361 // Read section values 362 363 procedure TForm1.Button5Click(Sender: TObject); 364 var 365 ini: TIniFile; 366 begin 367 ini := TIniFile.Create('WIN.INI'); 368 try 369 ini.ReadSectionValues('Desktop', ListBox1.Items); 370 finally 371 ini.Free; 372 end; 373 end; 374 375 // Erase a section 376 377 procedure TForm1.Button6Click(Sender: TObject); 378 var 379 ini: TIniFile; 380 begin 381 ini := TIniFile.Create('MyIni.ini'); 382 try 383 ini.EraseSection('My_Section'); 384 finally 385 ini.Free; 386 end; 387 end; 388 389 ################################################################################################### 390 ...ein anderes Programm ausführen? 391 392 uses 393 ShellApi; 394 395 { Start notepad } 396 397 ShellExecute(Handle, 'open', 'notepad.exe', '', nil, SW_SHOW); 398 399 WinExec('C:\Windows\notepad.exe', SW_SHOW); 400 401 { Start notepad and load a file } 402 403 ShellExecute(Handle, 'open', 'notepad', 'c:\MyFile.txt', nil, SW_SHOW); 404 405 { Open a txt file } 406 407 ShellExecute(Handle, 'open', 'c:\Readme.txt', nil, nil, SW_SHOW); 408 409 410 { Calling "Dir" from the DOS-Prompt and redirect the output to a file } 411 412 {1. With Winexec } 413 414 procedure ExecuteShellCommand(cmdline: string; hidden: Boolean); 415 const 416 flags: array [Boolean] of Integer = (SW_SHOWNORMAL, SW_HIDE); 417 var 418 cmdbuffer: array [0..MAX_PATH] of Char; 419 begin 420 GetEnvironmentVariable('COMSPEC', cmdBUffer, SizeOf(cmdBuffer)); 421 StrCat(cmdbuffer, ' /C '); 422 StrPCopy(StrEnd(cmdbuffer), cmdline); 423 WinExec(cmdbuffer, flags[hidden]); 424 end; 425 426 427 procedure TForm1.Button1Click(Sender: TObject); 428 begin 429 ExecuteShellCommand('dir C:\ > c:\temp\dirlist.txt', True); 430 end; 431 432 433 {2. With Shellexecute } 434 435 procedure ExecuteShellCommand(cmdline: string; hidden: Boolean); 436 const 437 flags: array[Boolean] of Integer = (SW_SHOWNORMAL, SW_HIDE); 438 var 439 cmdbuffer: array[0..MAX_PATH] of Char; 440 begin 441 GetEnvironmentVariable('COMSPEC', cmdBUffer, SizeOf(cmdBuffer)); 442 ShellExecute(0,'open',cmdbuffer, PChar('/c' + cmdline), nil, flags[hidden]); 443 end; 444 445 procedure TForm1.Button1Click(Sender: TObject); 446 begin 447 ExecuteShellCommand('copy file1.txt file2.txt', True); 448 end; 449 450 ################################################################################################### 451 ...das eigene Programm Verzeichnis ermitteln ? 452 453 454 { 455 To get your program's directory: 456 Das eigene Programm Verzeichnis/(den Anwendungspfad) ermitteln: 457 } 458 459 procedure TForm1.Button1Click(Sender: TObject); 460 var 461 sExePath: string; 462 begin 463 sExePath := ExtractFilePath(Application.ExeName) 464 ShowMessage(sExePath); 465 end; 466 467 { 468 To get your program's Exe-Name: 469 Und den Exe-Name: 470 } 471 472 procedure TForm1.Button2Click(Sender: TObject); 473 var 474 sExeName: string; 475 begin 476 sExeName := ExtractFileName(Application.ExeName); 477 ShowMessage(sExeName); 478 end; 479 480 481 { 482 Instead of Application.ExeName you can also use Paramstr(0) 483 Anstatt Application.ExeName kann man auch Paramstr(0) einsetzen 484 } 485 486 { 487 If you are working on a DLL and are interested in the filename of the 488 DLL rather than the filename of the application, then you can use this function: 489 } 490 491 function GetModuleName: string; 492 var 493 szFileName: array[0..MAX_PATH] of Char; 494 begin 495 FillChar(szFileName, SizeOf(szFileName), #0); 496 GetModuleFileName(hInstance, szFileName, MAX_PATH); 497 Result := szFileName; 498 end; 499 500 ################################################################################################### 501 502 ..den letzten Zugriff auf eine Datei auslesen? 503 504 {1.} 505 506 function GetFileLastAccessTime(sFileName: string): TDateTime; 507 var 508 ffd: TWin32FindData; 509 dft: DWORD; 510 lft: TFileTime; 511 h: THandle; 512 begin 513 // 514 // get file information 515 h := Windows.FindFirstFile(PChar(sFileName), ffd); 516 if (INVALID_HANDLE_VALUE <> h) then 517 begin 518 // 519 // we're looking for just one file, 520 // so close our "find" 521 Windows.FindClose(h); 522 // 523 // convert the FILETIME to 524 // local FILETIME 525 FileTimeToLocalFileTime(ffd.ftLastAccessTime, lft); 526 // 527 // convert FILETIME to 528 // DOS time 529 FileTimeToDosDateTime(lft, LongRec(dft).Hi, LongRec(dft).Lo); 530 // 531 // finally, convert DOS time to 532 // TDateTime for use in Delphi's 533 // native date/time functions 534 Result := FileDateToDateTime(dft); 535 end; 536 end; 537 538 539 {********************************************************************} 540 541 {2.} 542 543 function GetFileTimes(const FileName: string; var Created: TDateTime; 544 var Accessed: TDateTime; var Modified: TDateTime): Boolean; 545 var 546 h: THandle; 547 Info1, Info2, Info3: TFileTime; 548 SysTimeStruct: SYSTEMTIME; 549 TimeZoneInfo: TTimeZoneInformation; 550 Bias: Double; 551 begin 552 Result := False; 553 Bias := 0; 554 h := FileOpen(FileName, fmOpenRead or fmShareDenyNone); 555 if h > 0 then 556 begin 557 try 558 if GetTimeZoneInformation(TimeZoneInfo) <> $FFFFFFFF then 559 Bias := TimeZoneInfo.Bias / 1440; // 60x24 560 GetFileTime(h, @Info1, @Info2, @Info3); 561 if FileTimeToSystemTime(Info1, SysTimeStruct) then 562 Created := SystemTimeToDateTime(SysTimeStruct) - Bias; 563 if FileTimeToSystemTime(Info2, SysTimeStruct) then 564 Accessed := SystemTimeToDateTime(SysTimeStruct) - Bias; 565 if FileTimeToSystemTime(Info3, SysTimeStruct) then 566 Modified := SystemTimeToDateTime(SysTimeStruct) - Bias; 567 Result := True; 568 finally 569 FileClose(h); 570 end; 571 end; 572 end; 573 574 575 procedure TForm1.Button1Click(Sender: TObject); 576 var 577 Date1, Date2, Date3: TDateTime; 578 begin 579 if GetFileTimes(Edit1.Text, Date1, Date2, Date3) then 580 begin 581 ShowMessage('Created: ' + DateTimeToStr(Date1)); 582 ShowMessage('Last Accessed: ' + DateTimeToStr(Date2)); 583 ShowMessage('Last Modified: ' + DateTimeToStr(Date3)); 584 end; 585 end; 586 587 ################################################################################################### 588 589 ...überprüfen ob ein Pfad existiert? 590 591 uses FileCtrl; 592 593 procedure TForm1.Button1Click(Sender: TObject); 594 begin 595 if DirectoryExists('c:\windows') then 596 ShowMessage('Path exists!'); 597 end; 598 599 ################################################################################################### 600 Windows-Version ermitteln 601 602 function GetWinVersion: string; 603 begin 604 result:='Unbekannte Version'; 605 case Win32Platform of 606 1:// 9x-Reihe 607 If Win32MajorVersion=4 Then Begin 608 Case Win32MajorVersion of 609 0: result:='Windows 95'; 610 10: result:='Windows 98'; 611 90: result:='Windows Me'; 612 end; 613 end; 614 2: // NT-Reihe 615 Case Win32MajorVersion of 616 3:IF Win32MinorVersion=51 then 617 result:='Windows NT 3.51'; 618 4:If Win32MinorVersion=0 then 619 result:='Windows NT 4'; 620 5:Case Win32MinorVersion of 621 0: result:='Windows 2000'; 622 1: result:='Windows XP'; 623 2: result:='Windows .NET Server'; 624 end; 625 End; 626 end; 627 //Win32CSDVersion enthält Informationen zu Servicepacks 628 if Win32CSDVersion<>'' then 629 result:=result+' '+Win32CSDVersion; 630 end; 631 632 ################################################################################################### 633 Auflösung und Farbtiefe ermitteln 634 635 Horizontale_Aufloesung := Screen.Width; 636 Vertikale_Aufloesung := Screen.Height; 637 638 639 function ScreenBitsPerPixel: Integer; 640 var 641 DC: HDC; 642 begin 643 DC := GetDC(0); // Device-Context des Desktops 644 try 645 Result := GetDeviceCaps(DC, BITSPIXEL); 646 finally 647 ReleaseDC(0, DC); 648 end; 649 end; 650 651 procedure TForm1.Button1Click(Sender: TObject); 652 var 653 BitsPerPixel: Integer; 654 begin 655 BitsPerPixel := ScreenBitsPerPixel; 656 case BitsPerPixel of 657 4: ShowMessage('16 Farben (4 Bit Farbtiefe)'); 658 8: ShowMessage('256 Farben (8 Bit Farbtiefe)'); 659 16: ShowMessage('64K Farben, High Color (16 Bit Farbtiefe)'); 660 24: ShowMessage('16M Farben, True Color (24 Bit Farbtiefe)'); 661 32: ShowMessage('16M Farben, True Color (32 Bit Farbtiefe)'); 662 end; 663 end; 664 ################################################################################################### 665 666 ...eine Email mit Attachment mit ShellExecute über Outlook Express verschicken? 667 668 { 669 Shellexecute(Handle,'open','mailto:aaaa@bbb.com?subject&body=body 670 text&CC=aaaa&bcc=dddd&attach=FileName',nil,nil,SW_SHOW) 671 only works with outlook, not for outlook express, 672 but the method below can send attachment to outlook express 673 } 674 675 uses 676 ComObj; 677 678 procedure SendMail(Subject, Body, RecvAddress : string; Attachs : array of string); 679 var 680 MM, MS : Variant; 681 i : integer; 682 begin 683 MS := CreateOleObject('MSMAPI.MAPISession'); 684 try 685 MM := CreateOleObject('MSMAPI.MAPIMessages'); 686 try 687 MS.DownLoadMail := False; 688 MS.NewSession := False; 689 MS.LogonUI := True; 690 MS.SignOn; 691 MM.SessionID := MS.SessionID; 692 693 MM.Compose; 694 695 MM.RecipIndex := 0; 696 MM.RecipAddress := RecvAddress; 697 MM.MsgSubject := Subject; 698 MM.MsgNoteText := Body; 699 700 for i := Low(Attachs) to High(Attachs) do 701 begin 702 MM.AttachmentIndex := i; 703 MM.AttachmentPathName := Attachs[i]; 704 end; 705 MM.Send(True); 706 MS.SignOff; 707 finally 708 VarClear(MS); 709 end; 710 finally 711 VarClear(MM); 712 end; 713 end; 714 715 procedure TForm1.FormCreate(Sender : TObject); 716 begin 717 SendMail('Subject', 'Body'#13#10'Second', 'BillGates@Microsoft.com', 718 ['C:\Winnt\explorer.exe', 'C:\winnt\win.ini']); 719 end; 720 721 ################################################################################################### 722 723 ...das Standard E-Mail Programm zum Senden einer E-Mail starten? 724 725 726 uses 727 ShellApi; 728 729 730 procedure TForm1.Button1Click(Sender: TObject); 731 var 732 strEmail, strSubject, strBody, Param: string; 733 begin 734 strEmail := 'user@host.com'; 735 strSubject := 'Your Subject'; 736 strBody := 'Your Message Text'; 737 738 Param := 'mailto:' + strEmail + '?subject=' + strSubject + 739 '&Body=' + strBody; 740 741 ShellExecute(Form1.Handle, 'open', PChar(Param), nil, nil, SW_SHOWNORMAL); 742 end; 743 744 { 745 Note: Shellexecute doesn't accept Attachments. 746 Use MAPI to send Attachments. 747 748 Use %0D%0A for a line break 749 750 Bemerkung: Shellexecute akzeptiert keine Attachment-Angaben. 751 MAPI unterstützt Attachments. 752 753 Setze ein %0D%0A ein, um einen Zeilenumruch im Body zu erzwingen 754 } 755 756 ################################################################################################### 757 758 ..eine Url im Standard Webbrowser öffnen? 759 760 uses 761 ShellApi; 762 763 procedure TForm1.Button1Click(Sender: TObject); 764 begin 765 ShellExecute(Handle, 766 'open', 767 'http://www.SwissDelphiCenter.ch', 768 nil, 769 nil, 770 SW_SHOW); 771 end; 772 773 ################################################################################################### 774 775 ...machen, dass ein Formular immer im Vordergrund ist? 776 777 with Self do {Form1,...} 778 SetWindowPos(Handle, // handle to window 779 HWND_TOPMOST, // placement-order handle {*} 780 Left, // horizontal position 781 Top, // vertical position 782 Width, 783 Height, 784 // window-positioning options 785 SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE); 786 787 {* Other Values: } 788 HWND_BOTTOM 789 Places the window at the bottom of the Z order. 790 HWND_NOTOPMOST 791 Places the window above all non-topmost windows 792 HWND_TOP 793 Places the window at the top of the Z order. 794 HWND_TOPMOST 795 Places the window above all non-topmost windows. 796 The window maintains its topmost position even when it is deactivated. 797 798 ################################################################################################### 799 800 Form per MouseOver in den Vordergrund holen 801 802 function ForceForeGroundWindow(hWnd: THandle): BOOL; 803 var 804 hCurWnd : THandle; 805 begin 806 hCurWnd := GetForegroundWindow; 807 AttachThreadInput(GetWindowThreadProcessID(hCurWnd, nil), 808 GetCurrentThreadId, True); 809 Result := SetForeGroundWindow(hWnd); 810 AttachThreadInput(GetWindowThreadProcessId(hCurWnd, nil), 811 GetCurrentThreadId, False); 812 end; 813 814 815 816 817 818 procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, 819 Y: Integer); 820 begin 821 ForceForeGroundWindow(Self.Handle); 822 end; 823 824 ################################################################################################### 825 826 ...Ausbrechen des Fensters aus dem Bildschirm verhindern? 827 828 829 procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; 830 Shift: TShiftState; X, Y: Integer); 831 begin 832 if Form1.Left <= 0 then Form1.Left := 0; 833 if Form1.Top <= 0 then Form1.Top := 0; 834 if Form1.Left >= Screen.Width - Form1.Width then 835 Form1.Left := Screen.Width - Form1.Width; 836 if Form1.Top >= Screen.Height - Form1.Height then 837 Form1.Top := Screen.Height - Form1.Height; 838 end; 839 840 ################################################################################################### 841 842 ...ein Programm von der Taskbar verstecken? 843 844 procedure TMainForm.FormShow(Sender: TObject); 845 var 846 hwndOwner: HWnd; 847 begin 848 hwndOwner := GetWindow(Handle, GW_OWNER); 849 ShowWindow(hwndOwner, SW_HIDE); 850 // For Windows 2000, additionally call the ShowWindowAsync function: 851 ShowWindowAsync(hwndOwner, SW_HIDE); 852 ShowWindowAsync(Self.Handle, SW_HIDE); 853 end; 854 855 { 856 Prevent the form from reappearing on the Taskbar after minimizing it: 857 858 Verhindern, dass nach einem Minimize die Applikation wieder in der Taskbar 859 erscheint: 860 } 861 862 private 863 procedure WMSysCommand(var msg: TWMSysCommand); message WM_SysCommand; 864 865 {....} 866 867 implementation 868 869 procedure TMainForm.WMSysCommand(var msg: TWMSysCommand); 870 begin 871 if msg.CmdType and $FFF0 = SC_MINIMIZE then 872 hide 873 else 874 inherited; 875 end; 876 877 ################################################################################################### 878 879 ..disable/enable /hide/show taskbar? 880 881 { 882 All you have to do is to obtain the window handle 883 of the taskbar window and then you can disable or hide it. 884 } 885 886 var 887 wndTaskbar: HWND; 888 begin 889 wndTaskbar := FindWindow('Shell_TrayWnd', nil); 890 if wndTaskbar <> 0 then 891 begin 892 EnableWindow(wndTaskbar, False); // Disable the taskbar 893 EnableWindow(wndTaskbar, True); // Enable the taskbar 894 ShowWindow(wndTaskbar, SW_HIDE); // Taskbar vertecken 895 ShowWindow(wndTaskbar, SW_SHOW); // Taskbar anzeigen 896 end; 897 end; 898 899 ################################################################################################### 900 901 procedure TForm1.Button1Click(Sender: TObject); 902 var 903 sNewText: string; 904 begin 905 // Replace the first Word "FOX" with "tiger". 906 // Ersetzt das erste Wort "FOX" durch "tiger". 907 sNewText := StringReplace('The quick brown fox jumps over the lazy fox.', 908 'FOX', 'tiger', [rfIgnoreCase]); 909 ShowMessage(sNewText); 910 911 // Remove all Spaces in a string. 912 // Alle Leerzeichen in einem String ersetzen. 913 sNewText := StringReplace('This is a Text with Spaces', ' ', '', [rfReplaceAll]); 914 ShowMessage(sNewText); 915 916 // Replace all "True" in a Memo with "False". 917 // Alle Wörter "True" mit "False" ersetzen in einem Memo. 918 Memo1.Text := StringReplace(Memo1.Text, 'True', 'False', [rfReplaceAll, rfIgnoreCase]]); 919 end; 920 921 ###################################################################################################