Would you like to make this site your homepage? It's fast and easy...
Yes, Please make this my home page!
.
Finding driver capacity and available free space.
- DiskFree(0) // Free Space as Byte.
- DiskSize(0) // Capacity as Byte.
- DiskSize(0) div 1024 // Capacity as KB.
Finding Harddisk serial number.
- procedure TForm1.Button1Click(Sender: TObject);
- var
- VolumeSerialNumber : DWORD;
- MaximumComponentLength : DWORD;
- FileSystemFlags : DWORD;
- SerialNumber : string;
- begin
- GetVolumeInformation('C:\', nil, 0, @VolumeSerialNumber, MaximumComponentLength, FileSystemFlags, nil, 0);
- SerialNumber := IntToHex(HiWord(VolumeSerialNumber), 4) +'-' +IntToHex(LoWord(VolumeSerialNumber), 4);
- Memo1.Lines.Add(SerialNumber);
- end;
To Minimize window
- Application.Minimize;
- CloseWindow(handle)
- WindowState := wsMinimized;
To Close window
- Application.Terminate;
- CloseWindow(handle)
- WindowState := wsTerminate;
Shutdown and Reboot windows
- var
- i:dword;
- begin
- ExitWindowsEx(EWX_SHUTDOWN); //For Reboot EWX_REBOOT
- end;
Convert ico to Bmp
- var
- Icon : TIcon;
- Bitmap : TBitmap;
- begin
- Icon := TIcon.Create;
- Bitmap := TBitmap.Create;
- Icon.LoadFromFile('c:\picture.ico');
- Bitmap.Width := Icon.Width;
- Bitmap.Height := Icon.Height;
- Bitmap.Canvas.Draw(0, 0, Icon );
- Bitmap.SaveToFile('c:\picture.bmp');
- Icon.Free;
- Bitmap.Free;
- end;
Open and Close CdRom driver
- Add MMSystem unit to Uses part.
- mciSendString('Set cdaudio door open wait', nil, 0, handle); //Open
- mciSendString('Set cdaudio door closed wait', nil, 0, handle); //Close
Open-Close Numlock and Capslock keys
- procedure TMyForm.Button1Click(Sender: TObject);
- Var
- KeyState : TKeyboardState;
- begin
- GetKeyboardState(KeyState);
- if (KeyState[VK_CAPITAL] = 0) then
- KeyState[VK_CAPITAL] := 1
- else
- KeyState[VK_CAPITAL] := 0;
- SetKeyboardState(KeyState);
- end;
- //Write VK_NUMLOCK for Numlock Key
Adding bitmaps to a menu
- procedure TForm1.FormCreate(Sender: TObject);
- var
- Bmp1 : TPicture;
- begin
- Bmp1 := TPicture.Create;
- Bmp1.LoadFromFile('c:\deneme\turkey.bmp');
- SetMenuItemBitmaps( deneme1.Handle, 0, MF_BYPOSITION, Bmp1.Bitmap.Handle, Bmp1.Bitmap.Handle);
- end;
Beep sound from PcSpeaker
Open a Web Adress
- Add Shellapi unit to Uses part.
- ShellExecute(Handle,'open','http://www.geocities.com/siliconvalley/campus/4958/', nil, nil, sw_ShowMaximized);
Open-Close Screen Saver
- //Close
- SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 0, nil, 0);
- //Open
- SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 1, nil, 0);
Using animated Cursors
- procedure TForm1.Button1Click(Sender:TObject);
- var
- h : THandle;
- begin
- h := LoadImage(0,'C:\TheWall\Magic.ani',IMAGE_CURSOR,0,0,LR_DEFAULTSIZE or LR_LOADFROMFILE);
- if h = 0 then ShowMessage('Cursor not loaded') else begin
- Screen.Cursors[1] := h;
- Form1.Cursor := 1;
- end;
- end;
Finding Windows lisance acknowledge(name,Company)
- Add Registry unit to Uses part.
- procedure TForm1.Button1Click(Sender:TObject);
- var
- reg: TRegIniFile;
- begin
- reg := TRegIniFile.create('SOFTWARE\MICROSOFT\MS SETUP (ACME)\');
- Memo1.Lines.Add(reg.ReadString('USER INFO','DefName','Mustafa SIMSEK'));
- Memo1.Lines.Add(reg.ReadString('USER INFO','DefCompany','Bilgisayar Bilimleri Müh.'));
- reg.free;
- end;
Changing Wallpaper
- var
- s: string;
- begin
- s := 'c:\windows\athena.bmp';
- SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, PChar(s),0);
Writing number with comma
- procedure TForm1.Button1Click(Sender: TObject);
- var
- i : integer;
- begin
- i := 12345678;
- Memo1.Lines.Add(FormatFloat('#,', i));
Changing system Date and Time
- var
- t:TSystemTime;
- begin
- t.wYear:=1998;
- t.wMonth:=5;
- t.wDay:=23;
- t.wHour:=12;
- t.wMinute:=34;
- SetLocalTime(t);
- end;
Show the Mouse Busy
- try
- Screen.Cursor := crHourGlass;
- {Writing your code here...}
- finally
- Screen.Cursor := crDefault;
- end;
- Application.ProcessMessages;
Running a DOS program and closing its window after running it
- When you run a DOS program in Windows95, its window remains open until closed by the user. To run a Dos program that
- closes its windows after running, you must specify "command.com /c program" in the command line. Using WinExec
- API function to run a program named progdos.exe, the call should be:
- WinExec("command.com /c progdos.exe",sw_ShowNormal);
- If you wish that the program is run hidden from the user, the second parameter must be sw_Hide. You must specify the
- .com extension, or the program will not run.
Changing a TEdit text in its OnChange event
- If you want to change a TEdit text in its OnChange event, it will fire the event recursively until stack exhausts. To do this,
- you must set it to NIL before changing its text and reassigning it after, like this:
- procedure Edit1Change(Sender : TObject);
- begin
- Edit1.OnChange := NIL;
- if Edit1.Text = 'Some Text' then
- Edit1.Text := 'New Text';
- Edit1.OnChange := Edit1Change;
- end;
- This tip works also with OnValidate events.
/hr size="2" color=White noshade>
Shrinking the executable
- In Delphi 1.0, sometimes checking the Optimize for size and load time checkbox, in Options/Project/Linker doesn't
- work (you get a Disk full message, even with plenty of space). Delphi 1.0 comes with a Dos program, W8LOSS, that does
- the same. To use, it you must type:
- W8LOSS program.exe
- It will shrink your executable in about 20%, and will speed up loading time.
Getting current line and column from a memo
- To get the current line and column from a memo you must use this:
- With Memo1 do begin
- Line := Perform(EM_LINEFROMCHAR,SelStart, 0);
- Column := SelStart - Perform(EM_LINEINDEX, Line, 0);
- end;
Changing a menu font
- To change a menu font, you must forget using Delphi's menu designer. You must create the menu items using Api function
- AppendMenu, with flag MF_OWNERDRAW, in the Form's OnCreate Event. Then you must use WM_MEASUREITEM
- and WM_DRAWITEM to draw your menu options. Download an example.
International settings
- By default, Delphi gets its date/time, currency and numeric format from Control Panel's International settings. This can lead
- to errors, when parsing dates, numbers or lists. To avoid these errors, you can set the constants defined in Delphi, like
- DecimalSeparator, ShortDateFormat and others like this:
- DecimalSeparator := '.';
- ShortDateFormat := 'mm/dd/yy';
- This will override the default settings assuring the correct values. To a complete list of these variables, look at Currency
- Formatting Variables in Delphi Help
Extracting icons from an executable
- To extract icons from an executable, you must use ExtractIcon API function. It gets 3 parameters:
- Instance - Instance of the application
- FileName - Name of the executable. Must be a PChar
- NumIcon - Number of the icon to be retreaved. If it's Word(-1), the function returns the number of icons in the
- executable.
How to Get Dos Environment
To get DOS Environment, you must use GetDosEnvironment API Function.It returns a PChar that can be parsed.
Filtering and sorting tables in Delphi 1.0
- To filter and sort a table in Delphi 1.0 you can use a QBE (Query by Example) file as the TableName TTable's property.
- This is useful to filter, sort or join tables, while still using the TTable component. QBE files can be created in Database
- Desktop.
Acessing DBNavigator buttons
- The DBNavigator has a protected Buttons array that acesses its buttons. An inherited Navigator can acess them and
- change their properties. TBSNavigator does this to change their Enabled state or Glyph.
Making Enter key act as Tab
- To make the Enter key act as Tab key is a 3 step procedure:
- 1) Set the form's KeyPreview property to True
- 2) Set all form's buttons property Default to False
- 3) Create an OnKeyPress event for the form like this:
- procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
- begin
- if Key = #13 then begin
- Key := #0;
- if (Sender is TDBGrid) then
- TDBGrid(Sender).Perform(WM_KeyDown,VK_Tab,0)
- else
- Perform(Wm_NextDlgCtl,0,0);
- end;
- end;
Packing tables
- To pack (remove phisically all deleted records) from a Paradox table you must use this code
- procedure ParadoxPack(Table : TTable);
- var
- TBDesc : CRTblDesc;
- hDb: hDbiDb;
- TablePath: array[0..dbiMaxPathLen] of char;
- begin
- FillChar(TBDesc,Sizeof(TBDesc),0);
- with TBDesc do begin
- StrPCopy(szTblName,Table.TableName);
- StrPCopy(szTblType,szParadox);
- bPack := True;
- end;
- Table.Open;
- hDb := nil;
- Check(DbiGetDirectory(Table.DBHandle, True, TablePath));
- Table.Close;
- Check(DbiOpenDatabase(nil, 'STANDARD', dbiReadWrite,
- dbiOpenExcl,nil,0, nil, nil, hDb));
- Check(DbiSetDirectory(hDb, TablePath));
- Check(DBIDoRestructure(hDb,1,@TBDesc,nil,nil,nil,False));
- Table.Open;
- end;
- To pack Dbase tables use this command
- DBIPackTable(Table1.DBHandle,Table1.Handle,nil,nil,True);
Working with multiselect grids
- Delphi 2.0 multiselect grids have an undocumented SelectedRows property, a TBookmark list. You can use it with a code
- like this:
- With DbGrid1 do begin
- for i := 0 to Pred(SelectedRows.Count) do begin
- DataSource.DataSet.Bookmark := SelectedRows[i];
- {the dataset is positioned on the selection. Do your stuff}
- end;
- end;
Listing all open windows
- To list (get) all open windows, you must use EnumWindows API function. It uses a callback function, that receives 2
- parameters: a Window handle and a Pointer. You can use it with a code like this (this code lists all open windows, even
- invisible ones in a listbox):
- function EnumWindowsProc(Wnd : HWnd;Form : TForm1) : Boolean; Export; {$ifdef Win32}
- StdCall; {$endif}
- var
- Buffer : Array[0..99] of char;
- begin
- GetWindowText(Wnd,Buffer,100);
- if StrLen(Buffer) <> 0 then
- Form.ListBox1.Items.Add(StrPas(Buffer));
- Result := True;
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- EnumWindows(@EnumWindowsProc,LongInt(Self));
- end;
Converting the first letter of an EditBox to uppercase
- To convert the first letter of an EditBox to uppercase this code can be used:
- procedure TForm1.Edit1Change(Sender: TObject);
- var
- OldStart : Integer;
- begin
- With Edit1 do
- if Text <> '' then begin
- OnChange := NIL;
- OldStart := SelStart;
- Text := UpperCase(Copy(Text,1,1))+LowerCase(Copy(Text,2,Length(Text)));
- SelStart := OldStart;
- OnChange := Edit1Change;
- end;
- end;
Doing incremental search in a Table
- To do incremental search on a table, using a TEdit, you must put this code in the TEdit's OnChange Event:
- procedure TForm1.Edit1Change(Sender: TObject);
- begin
- With Edit1 do
- if Text <> '' then
- Table1.FindNearest([Text]);
- end;
Doing incremental search in a Query
- To do incremental search in a Query, using a TEdit, you must put this code in the TEdit's OnChange Event (this works only
- in D2/D3):
- procedure TForm1.Edit1Change(Sender: TObject);
- begin
- With Edit1 do
- if Text <> '' then begin
- Query1.Filter := 'code = '''+Edit1.Text+'''';
- Query1.FindFirst;
- end;
- end;
- Another way could be
- procedure TForm1.Edit1Change(Sender: TObject);
- begin
- With Edit1 do
- if Text <> '' then
- Query1.Locate('code',Edit1.Text,[loPartialKey]);
- end;
Creating non rectangular windows (D2/D3)
- To create a non rectangular window, you must create a Windows Region and use the API function SetWindowRgn, like
- This (this works only in D2/D3):
- var
- hR : THandle;
- begin
- {creates an Elliptic Region}
- hR := CreateEllipticRgn(0,0,100,200);
- SetWindowRgn(Handle,hR,True);
- end;
Detecting Windows Shutdown
- To detect Windows Shutdown, you must trap WM_EndSession message. These steps should be taken:
- Declare a message handling procedure in your Form's Private section:
- procedure WMEndSession(var Msg : TWMEndSession); message WM_ENDSESSION;
- Add the procedure to the implementation section of your Unit:
- procedure TForm1.WMEndSession(var Msg : TWMEndSession);
- begin
- if Msg.EndSession = TRUE then
- ShowMessage('Windows is shutting down ' + #13 + 'at ' +
- FormatDateTime('c', Now));
- inherited;
- end;
Moving the mouse pointer
- To move the Mouse pointer with no user's action, you can use a timer and put the following code in it's OnTimer event:
- procedure TForm1.Timer1Timer(Sender: TObject);
- var
- pt:tpoint;
- begin
- getcursorpos(pt);
- pt.x := pt.x + 1;
- pt.y := pt.y + 1;
- if pt.x>=screen.width-1 then setcursorpos(0,pt.y);
- if pt.y>=screen.height-1 then setcursorpos(pt.x,0);
- end;
Positioning the caret in a line in a memo or RichEdit
- To position the caret in a line in a Memo or RichEdit you must use this:
- With Memo1 do
- SelStart := Perform(EM_LINEINDEX, Line, 0);
Moving forms with no caption
- To move a form with no caption, you must override WM_NCHITTEST message, like this:
- type
- TForm1 = class(TForm)
- public
- procedure WMNCHitTest(var M: TWMNCHitTest); message WM_NCHitTest;
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.DFM}
- procedure TForm1.WMNCHitTest(var M: TWMNCHitTest);
- begin
- inherited;
- if M.Result = htClient then {if the mouse clicked on the form}
- M.Result := htCaption; {make windows think that mouse has been clicked on caption}
- end;
Right justifying menu items
- To justify menu items on the right side of the main menu bar, you must do like this:
- {It will right justify all menu items to the right of the one selected}
- procedure SetJustify(Menu: TMenu; MenuItem: TMenuItem; Justify: Byte);
- {$IFDEF WIN32}
- var
- ItemInfo: TMenuItemInfo;
- Buffer: array[0..80] of Char;
- {$ENDIF}
- begin
- {$IFDEF VER80}
- MenuItem.Caption := Chr(8) + MenuItem.Caption;
- {$ELSE}
- ItemInfo.cbSize := SizeOf(TMenuItemInfo);
- ItemInfo.fMask := MIIM_TYPE;
- ItemInfo.dwTypeData := Buffer;
- ItemInfo.cch := SizeOf(Buffer);
- GetMenuItemInfo(Menu.Handle, MenuItem.Command, False, ItemInfo);
- if Justify = 1 then
- ItemInfo.fType := ItemInfo.fType or MFT_RIGHTJUSTIFY;
- SetMenuItemInfo(Menu.Handle, MenuItem.Command, False, ItemInfo);
- {$ENDIF}
- end;
/hr size="2" color=White noshade>
Display and Change video resolutions
- To display available video modes, you must use the API function EnumDisplaySettings: it gets all display setting modes
- available.
- To change modes, you must use ChangeDisplaySettings, that changes the video resolution and color depth.
Detecting when the mouse is over a component
- When the mouse enters the area of a component, Delphi sends the CM_MouseEnter message. When it leaves, Delphi
- sends a CM_MouseLeave message. Treating this two messages, you can detect if the mouse is over the component. The
- Fly-Over label component shows this technique.
Detecting Windows shutdown
- When Windows is shutting down, it sends a WM_QueryEndSession to all open applications. To detect (and prevent
- shutdown), you must define a message handler to this message. Put this definition on the private section of the main form:
- procedure WMQueryEndSession(var Msg : TWMQueryEndSession); message
- WM_QueryEndSession;
- And put this method in the implementation section of the unit:
- procedure TForm1.WMQueryEndSession(var Msg : TWMQueryEndSession);
- begin
- if MessageDlg('Close Windows ?', mtConfirmation, [mbYes,mbNo], 0) = mrNo then
- Msg.Result := 0
- else
- Msg.Result := 1;
- end;
Drawing with different line types
- Windows allows to draw lines where each pixel is another shape or drawing with LineDDa function. It needs a callback
- function that is called when each pixel must be drawn. There you can put the drawing routines. This routine draws a
- rectangle every 4 pixels:
- TForm1 = class(TForm)
- procedure FormCreate(Sender: TObject);
- procedure FormPaint(Sender: TObject);
- public
- DrawNow : Integer;
- end;
- var
- Form1: TForm1;
- procedure DrawPoint(x,y : Integer;lpData : LParam); stdcall;
- implementation
- {$R *.DFM}
- procedure DrawPoint(x,y : Integer;lpData : LParam);
- begin
- with TObject(lpData) as TForm1 do begin
- if DrawNow mod 4 = 0 then
- Canvas.Rectangle(x-2,y-2,x+3,y+3);
- Inc(DrawNow);
- end;
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- DrawNow := 0;
- end;
- procedure TForm1.FormPaint(Sender: TObject);
- begin
- LineDDA(0,0,Width,Height,@DrawPoint,Integer(Self));
- end;
Calling Windows DialUp Connection Dialog
- To call Windows DialUp Connection Dialog, you can use WinExec, like this:
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- winexec(PChar('rundll32.exe rnaui.dll,RnaDial '+Edit1.Text),sw_show);
- end;
Acessing Protected Members of an Object
- Usually, you can't access protected members of an object. But Delphi let you access protected members if the object is
- defined in the same unit. So you can define a derived object and typecast where you want to use the protected member. It's
- something like this:
- THackControl = class(TCustomEdit)
- end;
- After defining this class, you can access all protected members of TCustomEdit, with objects of derived classes with a
- code like this:
- THackControl(MyEdit).Color := clBlack;
Hiding Minimized MDI Child Windows
- To hide minimized MDI child windows, you must trap its WM_Size message, like this:
- type
- TForm1 = class(TForm)
- public
- procedure WMSize(var M : TWMSIZE);Message WM_Size;
- end;
- implementation
- procedure TForm1.WMSize(var M:TWMSIZE);
- begin
- if M.SizeType=Size_Minimized then
- showwindow(Handle,Sw_Hide);
- end;
Hiding and showing the Windows Taskbar
- To hide the Windows Taskbar you must use a code like this:
- procedure TForm1.Button1Click(Sender: TObject);
- var
- hTaskBar :Thandle;
- begin
- hTaskBar := FindWindow('Shell_TrayWnd',Nil);
- ShowWindow(hTaskBar,Sw_Hide);
- end;
- To Show the Windows Taskbar, you must use this code:
- procedure TForm1.Button2Click(Sender: TObject);
- var
- hTaskBar :Thandle;
- begin
- hTaskBar := FindWindow('Shell_TrayWnd',Nil);
- ShowWindow(hTaskBar,Sw_Normal);
- end;
Paradox Password in code
- To give the password of a Paradox table in code, you can use this code:
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- Session.AddPassWord('MyPass');
- Table1.Acive := True;
- end;
Executing default action of an Ole Container
- To execute the default action of an Ole Container (open a Word or Excel document or run a Powerpoint presentation), you
- can use this code:
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- OleContainer1.DoVerb(ovprimary);
- end;
Extracting / Matching text from a string (TServerSocket)
- Let's say you have a client/server application that you
- want to communicate between. A simple way to do so is the following
- using an 'extract' function.
- Create a form with TClientSocket and another with TServerSocket.
- Let's say you want the server to 'delete' a file when it
- receives a certain string. You would call the following from
- a OnClientRead event (which I call ServerSocketClientRead in the sample).
- {the TClientSocket must first send this)
- <>
- //below we send a string the server will recognize followed
- //by the filename to be deleted on the server (full path+file)
- ClientSocket1.Socket.SendText ('delfile'+OpenDialog1.Filename);
- (TServerSocket retreives buffer)
- procedure TServerForm.ServerSocketClientRead(Sender: TObject;
- Socket: TCustomWinSocket);
- var gotstr:string;
- begin
- gotstr:=socket.receivetext;
- if copy (gotstr, 1, 7)='delfile' then
- begin
- DeleteFile (extract (gotstr, 8, Length(gotstr)));
- end;
- end;
- //Dont forget to declare the 'extract' function
- function extract (st: string; ind1, ind2 : integer): string;
- var i: integer;
- begin
- result:='';
- for i:=ind1 to ind2 do
- result:=result+st[i];
- end;
- ((((END CODE)))
Hide the TaskBar
- If you need to hide the Windows-Taskbar for your application you need to follow this steps:
- var
- wndClass: Array[0..50] of Char;
- wndHandle: THandle;
- 1) We need the TaskBar-class:
- StrPCopy(@wndClass[0], 'Shell_TrayWnd')
- 2) We need the TaskBar-handle:
- wndHandle := FindWindow(@wndClass[0], nil)
- 3) Now we can simply show/hide the Taskbar:
- Show: ShowWindow(wndHandle, SW_SHOW)
- Hide: ShowWindow(wndHandle, SW_HIDE)
How to put a monitor into stand-by mode
- If a device such as a monitor support Stand by mode then you can programmatically set the
- set in code. This will work with Windows95 and above.
- To place a monitor into Stand by mode:
- SendMessage(Application.Handle, wm_SysCommand, SC_MonitorPower, 0) ;
- To take it out of Stand by mode:
- SendMessage(Application.Handle, wm_SysCommand, SC_MonitorPower, -1) ;
- Here is a snippet of code to try it out:
- On a new form, place a Command button, a timer and a ListBox.
- Timer (use Object Inspector):
- Enabled := False
- Interval := 15000
- Add this event for the timer:
- procedure TForm1.Timer1Timer(Sender: TObject);
- begin
- ListBox1.Items.Add(FormatDateTime('h:mm:ss AM/PM',Time)) ;
- SendMessage(Application.Handle, wm_SysCommand, SC_MonitorPower, -1);
- end;
- Command Button:
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- ListBox1.Items.Add('--> ' + FormatDateTime('h:mm:ss AM/PM',Time)) ;
- Timer1.Enabled := not Timer1.Enabled ;
- SendMessage(Application.Handle, wm_SysCommand, SC_MonitorPower, 0) ;
- end;
- After building the program I suggest exiting Delphi and execute the program from Explorer.
- Once you hit the Command Button the screen should go blank for 15 seconds.
- Note: You should check in Control Panel if the computer supports power-saving features!
- Although many computers support this feature (Stand By), many have the feature disabled.
Hide Titlebar
- Here is how to hide the titlebar:
- Procedure TYourFormName.HideTitlebar;
- Var
- Save : LongInt;
- Begin
- If BorderStyle=bsNone then Exit;
- Save:=GetWindowLong(Handle,gwl_Style);
- If (Save and ws_Caption)=ws_Caption then Begin
- Case BorderStyle of
- bsSingle,
- bsSizeable : SetWindowLong(Handle,gwl_Style,Save and
- (Not(ws_Caption)) or ws_border);
- bsDialog : SetWindowLong(Handle,gwl_Style,Save and
- (Not(ws_Caption)) or ds_modalframe or ws_dlgframe);
- End;
- Height:=Height-getSystemMetrics(sm_cyCaption);
- Refresh;
- End;
- end;
- And here is how we show it again:
- Procedure TYourFormName.ShowTitlebar;
- Var
- Save : LongInt;
- begin
- If BorderStyle=bsNone then Exit;
- Save:=GetWindowLong(Handle,gwl_Style);
- If (Save and ws_Caption)<>ws_Caption then Begin
- Case BorderStyle of
- bsSingle,
- bsSizeable : SetWindowLong(Handle,gwl_Style,Save or
- ws_Caption or ws_border);
- bsDialog : SetWindowLong(Handle,gwl_Style,Save or
- ws_Caption or ds_modalframe or ws_dlgframe);
- End;
- Height:=Height+getSystemMetrics(sm_cyCaption);
- Refresh;
- End;
- end;
How you NOT show your form on Startup
- program Project1;
- uses
- Forms,
- Unit1 in 'Unit1.pas' {Form1};
- {$R *.RES}
- begin
- Application.Initialize;
- Application.ShowMainForm := False;
- Application.CreateForm(TForm1, Form1);
- Application.Run;
- end.
A Control that HighLights when mouse moves over it
- Some times ago I need to create a button that highlight when the mouse pointer
- move over the button and normal after the mouse leaving the control.
- I'd try with OnMouseMove event, but not worked properly, because
- if mouse pointer leaving the button, the OnMouseMove not triggered.
- My friend (Wawan) say me to try the CM_MOUSEENTER and CM_MOUSELEAVE messages.
- I'd try and I got it.
- The source code below is a sample.
- I create an object inherited from TControl.
- The Control is a white rectangle. When Mouse Pointer move over it, then it
- became a yellow rectangle.
- It is easy to handle CM_MOUSEENTER and CM_MOUSELEAVE, because no parameters
- needed.
- 1. Create an object inherited from TControl.
- 2. Define a TCanvas variable to draw the rectangle and a Boolean variable that
- have True value when the mouse move over the control.
- 3. Define procedures to handle CM_MOUSEENTER, CM_MOUSELEAVE and WM_PAINT
- messages.
- the control type is
- THighLightControl = class(TControl)
- private
- FMouseOver: Boolean;
- FCanvas: TCanvas;
- protected
- procedure CMMouseLeave(var msg : TMessage); message CM_MOUSELEAVE;
- (* Procedure to handle CM_MOUSELEAVE *)
- procedure CMMouseEnter(var msg : TMessage); message CM_MOUSEENTER;
- (* Procedure to handle CM_MOUSEENTER *)
- procedure WMPaint(var msg: TMessage); message WM_PAINT;
- (* Procedure to handle WM_PAINT *)
- public
- constructor Create(Owner: TComponent); override;
- (* Constructor to Create Control *)
- destructor Destroy; override;
- (* Canvas to draw rectangle *)
- end;
- Or, copy this source, save as UHigh.pas, and install to your component palette.
- ===========================================
- Kusnassriyanto S. Bahri
- kstotok@hotmail.com
- PIKSI-ITB
- Institut Teknologi Bandung Computer Center
- LabTek V Lantai III
- Jl. Ganesha 10 Bandung 40132
- Indonesia.
- ===========================================
- (* Source Code *)
- unit Uhigh;
- interface
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls;
- type
- THighLightControl = class(TControl)
- private
- FMouseOver: Boolean;
- FCanvas: TCanvas;
- protected
- procedure CMMouseLeave(var msg : TMessage); message CM_MOUSELEAVE;
- (* Procedure to handle CM_MOUSELEAVE *)
- procedure CMMouseEnter(var msg : TMessage); message CM_MOUSEENTER;
- (* Procedure to handle CM_MOUSEENTER *)
- procedure WMPaint(var msg: TMessage); message WM_PAINT;
- (* Procedure to handle WM_PAINT *)
- public
- constructor Create(Owner: TComponent); override;
- (* Constructor to Create Control *)
- destructor Destroy; override;
- (* Canvas to draw rectangle *)
- end;
- procedure Register;
- implementation
- constructor THighLightControl.Create(Owner: TComponent);
- begin
- inherited Create(Owner);
- Width := 100;
- Height := 100;
- FMouseOver := False;
- FCanvas := TControlCanvas.Create;
- TControlCanvas(FCanvas).Control := Self;
- (* The TControlCanvas is an object inherited from TCanvas that can be used to
- draw on Control Surface. *)
- end;
- destructor THighLightControl.Destroy;
- begin
- FCanvas.Destroy;
- inherited Destroy;
- end;
- procedure THighLightControl.CMMouseLeave(var msg : TMessage);
- begin
- FMouseOver := False;
- Invalidate;
- (* Set the FMouseOver value to False, and redraw the control *)
- end;
- procedure THighLightControl.CMMouseEnter(var msg : TMessage);
- begin
- FMouseOver := True;
- Invalidate;
- (* Set the FMouseOver value to True, and redraw the control *)
- end;
- procedure THighLightControl.WMPaint(var msg: TMessage);
- begin
- (* Procedure to draw rectangle *)
- if FMouseOver then begin
- (* Mouse move over the control *)
- FCanvas.Brush.Color := clYellow;
- end else begin
- FCanvas.Brush.Color := clWhite;
- end;
- FCanvas.Rectangle(0, 0, Width, Height);
- end;
- procedure Register;
- begin
- RegisterComponents('SAMPLES', [THighLightControl]);
- end;
- end.
Adding an AVI in your EXE File.
- In Notepad type or some other simple text editor type:
- MyAvi AVI "some.avi"
- or
- 100 AVI "some.avi"
- depending on how you want to reference the identifier. You will want to know whether it is
- referenced by a resource name or a resource ID when you write the code to play the AVI.
- Save the file with a .RC extension
- You will be using the Animate Component to play the file, therefore the same rules apply, like
- no sound can be with the AVI.
- Use Borland's Resource Compiler: BRCC32.EXE to convert the file to a .RES file. At the dos
- prompt type the following:
- brcc32 myfile.rc
- This is some code to play an animation using the Resource Name:
- Animate.ResHandle := 0;
- Animate.ResName := 'MyAvi';
- Animate.Active := True;
- To stop an animation, call the Stop method.
- Place the following code to add your resource file into your executable.
- {$R MYFILE.RES}
- A sample file is listed below of how this would work correctly:
- AviRes.pas
- unit AviResU;
- interface
- uses
- Forms, ComCtrls, StdCtrls, Classes, Controls;
- type
- TForm1 = class(TForm)
- PlayBtn: TButton;
- Animate: TAnimate;
- StopBtn: TButton;
- procedure PlayBtnClick(Sender: TObject);
- procedure StopBtnClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.DFM}
- {$R AVIRESRC.RES}
- procedure TForm1.PlayBtnClick(Sender: TObject);
- begin
- Animate.ResHandle := 0;
- Animate.ResName := 'TurboGuy';
- Animate.Active := True;
- PlayBtn.Enabled := False;
- StopBtn.Enabled := True;
- end;
- procedure TForm1.StopBtnClick(Sender: TObject);
- begin
- Animate.Stop;
- PlayBtn.Enabled := True;
- StopBtn.Enabled := False;
- end;
- end.
Gradient Filled Forms!
- Want to add a cool gradient fill to your delphi forms but don't want to buy a component to do
- so?
- Just follow these simple steps
- Step 1. Create a Windows Metafile (.wmf), I used PaintShop 4.0
- A. Create a new image - any size (make it small, it'll be doctored up later)
- B. Use the paint bucket fill tool and select a type of fill gradient.
- B. Save it as a (.wmf).
- Step 2. (in delphi) Place a image component on a form, set the following properties:
- Align: alClient
- Picture: Load the metafile you created.
- Stretch: True
- Step 3. Your done, a free gradient fill, and you almost paid money for this.
Wait for -More Tips. Comming Soon !!!!