Κυριακή 13 Μαΐου 2012
Calling CreateProcess() the easy way
If you look up the CreateProcess() function in Win32 help, you'll
notice that there are more than three dozen parameters that you can
optionally setup before calling it. The good news is that you have to setup
only a small number of those parameters to make a simple
CreateProcess() call.
Auto-resizing and centring forms on screen
Calling this procedure from the form's OnActivate event will
resize the form in proportion to the screen resolution once
the form height and width has been calculated it can then be centred.
Animate tray application windows as they open and close
Have you noticed that when you close the window of a tray application it
often doesn't actually close the application but simply hides the window and
leaves the application running in the tray: it effectively minimizes the
application to the tray. There's usually no visual clue that this has
happened as there would be if you minimized a normal application.
Adding component help to Delphi
Despite what it says in Delphi's documentation, to add component help simply
follow these instructions.
Σάββατο 12 Μαΐου 2012
How to change default hint color and timeouts
Normally, you can just turn hints on or off using property ShowHint
on almost every visual component. But what if you want to change the
default system color of hint “bubble”? And what if you want to change
the default pause, before the hint shows? And hide pause? Everything is
very simple.
Run default screensaver from code
If you want to run default system screensaver from your application,
it’s really easy. Just few lines of code. Here’s how to do it…
Hide and show taskbar programmatically
Just few lines of code to hide and show Windows taskbar programmatically.
Παρασκευή 11 Μαΐου 2012
Disable / enable Start button
The Start button will be still visible, but not clickable. Completely useless trick.
How to detect (and prevent) system shutdown
When Windows are being shutdown or restarted, all runnig applications are closed of course.
This can be dangerous, because you can lost your unsaved documents. But
there is an easy way to detect, that Windows wants to shutdown and your
application can do everything necessary to close properly.This “trick” is pretty simple.
Global system hotkey
Using the RegisterHotKey function and few other lines of code,
you can register a global system hotkey, which is active even if your
application is minimized.
Flash application button on taskbar
If your application is minimized and you still want to alert user, you
should flash icon on taksbar instead of bring your application to front.
Here is how to do it…
Set priority level of running application (process)
Using SetPriorityClass function, you can set priority level of your
running application. Same functionality is in the Task Manager (just
rightclick the process in the list and select priority level).
Create autorun registry key (run application with Windows start)
To run your application automatically after Windows starts, you just need to create an entry in autorun registry key.
Animate application icon (on taskbar and apllication window)
This trick is pretty simple. You just need few icons (at least two) for animation and Timer component. The rest is easy…
Simulate mouse moves and clicks
You can move mouse cursor and simulate clicking programmatically using just one simple procedure.
Determine CPU frequency
Here is just small piece of assembler code to determine CPU frequency in MHz.
Retrieve time since the system was started
This tip is very simple. Just use standard function GetTickCount and the rest is just elementary mathematics.
Just one instance of application
If want to allow users to run just one instance of application, one of possible methods is to use “mutext” (mutual exclusion).
Taskbar position
For some applications, it’s important to know, where the taskbar is
located. Of course, most users use standard “bottom of the screen”
position, but of course, you can place it to the left, rigtht or top of
the screen. Here is the method to determine actual position.
How to detect computer IP addresses
Using
Winsock
unit, we can determine computer IP address. If you have more network adapters, all IP addresses will be detected.Online / offline status detection
There are few methods to check if computer is online (=connected) or offline (=disconnected). This one is really simple.
Implementation of Delay procedure
Do you remember
Delay
procedure from Turbo (Borland)
Pascal? It was used to pause the program “flow” for specific time
interval. In Windows, there is a different style of programming, but
sometimes (maybe) the Dealy procedure may be useful. Here is a simple
implementation of Delay procedure using Delphi.Directory structure with associated icons and file info in ListView
Using
ShellAPI
unit and few lines of code, we can load directory structure into ListView
and show associated icons and information for each file.How to detect system idle time
If you want to detect user inactivity even if your application is in
background (has no focus), it’s really simple. You can achieve this
using
GetLastInputInfo
function.How to locate important system directories
Using
ShlObj
unit and SHGetSpecialFolderLocation
Windows
API function, we can retrieve the location of a special folders, such
as My computer, Desktop, Program Files etc… There are over 20 special
folder locations.Shortened version of a filename
The length of whole path and file name could be too long to show it in
title bar of application or some label. Solution? Show shortened version
of a filename using dots instead of folders.
CRC32 (Cyclic Redundency Check)
One of the most effective method to check if the file is ok is to
calculate CRC32 checksum and compare it with previously saved value.
Using CRC check, you can also compare two files, verify downloaded files
etc…
Right justify a main menu item
If you use standard main menu component, all items are usually on the
left side of the window and there is not much you can do about it using
Object Inspector. Here is a little trick to move one main menu item on
the right side while the rest remains on the left side. It’s usually
useful for “Help” or “About” items.
Own items in application system menu
When you rightclick application title bar (or leftclick icon on title
bar), the system menu will appear. Here are common commands to close,
minimize or maximize window. But you can add your own commands if you
like. Here is how.
Drawing text on desktop
Using this simple trick, you can write any text right on Windows desktop. You can choose text color, transparency, position…
Detect system font size
The standard system font size in Windows XP is 96 dpi. You can also use
120 dpi, if your prefer bigger fonts or you can set this font size to
your own value. However, the most applications today are tested only
with standard font size and if you change it, even professional
applications can have problems with it. With this tip, you can detect
font size directly from your application and change behaviour of user
interface.
Application version
Using this simple function, you will be able to read version information
from any application executable. It’s very useful for example to show
your own application version on title bar or “About” dialog.
How to prevent moving of application window
If you want to “lock” your application window position and prevent user from moving it, it’s really simple.
Volume serial number
With this simple function, you will be able to get volume serial number
and label. It could be either hard disk partition or CD/DVD disk.
Sort ListView by clicking on columns
First of all, set
ListView
to vsReport
style and fill in some data. OnColumnClick
and OnCompare
events will do the rest.Delete file to Recycle Bin
This short tip will show you how to delete file to Recycle Bin. We need ShellAPI unit and the rest is very simple.
Progressbar inside Button? No problem
It’s quite cool efect, but this is also effective way to save some space
in your application GUI. Let’s place progressbar of some time-consuming
function right into the button, which started this function.
Get user name of currently logged in user
This simple function will return name of currently logged in user.
Detecting Windows boot-up state using GetSystemMetrics function
Using GetSystemMetrics function, we can detect how the system is started.
How to minimize application with modal window
When you minimize modal window, this window is “hidden” behind (or
below) application main form. Using this simple trick, we can minimize
also the main application window together with modal “child” window.
Searching for string within a file
To search for a specific substring within any type of file, we can use this rather complex function.
How to detect application associated with file
To get full path to application associated with any file type, we need standard
ShellAPI
unit and the rest will do the FindExecutable
function.Get a unique name for temporary file
Using GetTempFileName, we can create a unique name for temporary file.
It’s useful when your application is using temporary files and you want
to save them into default TEMP folder and use a “random” filename.
Listbox with colored lines
Colored lines in listbox are more user-friendly and easy to read. Here is how to do it…
Change color of ListView items
To change background color of ListView items, you need to write your own OnCustomDrawItem event handler.
Change font, size and style of hint
Hints are everywhere. Almost every GUI element in Windows can be
“hinted”. When user hover mouse over element, small yellow bubble with
help text pops up. Is it possible to change hint “window” behavior? Of
course…
Get Process Memory Info
If you want to know how many bytes of memory is using your process, here is simple example.
Right justify ListBox items
The default ListBox items alignment is LeftJustify. There is no Object
Inspector property to change this, so if we need to right justify items,
we must use a simple trick.
How to detect system time change
If the user changes the system time either with Date and Time properties
dialog box or using command line, we can detect this by catching
WM_TIMECHANGE system message. Here is how.
How to detect clipboard change
Detecting clipboard change is very similar to detecting system time change.
Add own item to Internet Explorer Tools menu
If you want to add own items to Tools menu of Internet Explorer, it’s
simple. All we have to do is to add some keys to Windows registry,
therefore we must use Registry unit.
Own cool text cursor in Editbox
Standard text cursor is boring. What about replacing default vertical line with some cool shape?
Run application only once per windows-session
Using this simple tip, you can block your application to be executable
only once per windows sessions. To run application again, Windows must
be restarted before.
ComboBox with icons
Each ComboBox item with own icon? No problem. Using OwnerDraw style, we can do almost anything.
Adjusting DBGrid column widths automatically
Here's
a handy method to automatically fix the size of TDBGrid columns (at
run-time) to fit the DBGrid width (remove the unfilled space at the
right edge of the grid; and consequently remove the horizontal scroll
bar) when the user resizes the container containing the grid.
Master-detail relationships ADO and Delphi
Using two TTable or TQuery descendats to create master-detail database entry forms.
Get the line number of a selected row in a DBGrid
If you want to get the line number of a selected row in a DBGrid
component, here's what to do... Note: just substitute the Table1
component for whatever dataset you are using to provide data to your
DBGrid.
~~~~~~~~~~~~~~~~~~~~~~~~~
ShowMessage(IntToStr(Table1.RecNo)) ;
~~~~~~~~~~~~~~~~~~~~~~~~~
ShowMessage(IntToStr(Table1.RecNo)) ;
~~~~~~~~~~~~~~~~~~~~~~~~~
Prevent CTRL+DELETE in DBGrid
If you need to disable keyboard delete operation inside a DBGrid you'll need to disable the CTRL+DELETE key press.
How to make the Enter key work like Tab
We know that, generally, pressing the Tab key moves the input focus to
next control and Shift-Tab to previous in the tab order of the form.
When working with Windows applications, most users intuitively expect
the Enter key to behave like a Tab key.
How to Display Only Selected Fields in the DbGrid Component
See how use the Fields
Editor to define a list of some of the fields in a table that are to be
displayed in the Grid. Even more: see how to specify the field order.
How to Create a Simple Database Display Form
General instructions
for setting up a Table, DataSource and DbGrid component at design time
in order to access the data encapsulated by a table component.
Εγγραφή σε:
Αναρτήσεις (Atom)