Ads 468x60px

Smaller time frame always follow the bigger time frame. It's better wait be patience to enter in position than risk with BIG SL. Having strong trading discipline and taking losses when necessary is a sign of serious trading approach
Subscribe:

Labels

Showing posts with label Delphi. Show all posts
Showing posts with label Delphi. Show all posts

Tuesday, August 14, 2012

turn on/off my monitors


I have successfully tested this on Windows XP and Windows 7:
const
  MONITOR_ON      = -1;
  MONITOR_OFF     =  2;
  MONITOR_STANDBY =  1;
To turn off the monitor:
  SendMessage(Application.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF);
To turn on the monitor:
  SendMessage(Application.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON);


comments

Saturday, August 11, 2012

WINDOWS SERVICES - CONVERTING BETWEEN KEY AND DISPLAY NAMES


We've demonstrated how to check the status of Windows services and how to control them. One element missing from those functions was a way to convert between key and display names of Windows services. 
 
That's right, a Windows service has two names. The long name you see in the Control Panel is the display name of the service. The internal shorter name of the serivce is called the key name. Most functions require that you use the key name of a service, so here's a function to convert a display name to a key name. comments

WINDOWS SERVICES - GETTING A LIST OF INSTALLED SERVICES


Want to get a list of active, inactive or all Windows services? Following function can help you to do this, but be sure to read other Windows services related tips for details. 
 
const
  //
  // Service Types
  //
  SERVICE_KERNEL_DRIVER       = $00000001;
  SERVICE_FILE_SYSTEM_DRIVER  = $00000002;
  SERVICE_ADAPTER             = $00000004;
  SERVICE_RECOGNIZER_DRIVER   = $00000008;
comments

BIN2HEX - SCRIPT TO CONVERT DATA FILES INTO SOURCE CODE ARRAYS


Looking for a way to convert a binary (or even a text) file into a Perl, Pascal/Delphi, C/C++, or Java source code array? For example, you may want to do this to include a GIF or other binary file directly inside your Perl CGI script, rather than reading the data from a file to reduce file access. If you're writing Windows programs, you could use the same method to store resource files in your executable files. 
 
The bin2hex.pl script will take a binary file name and output a source code array, in the specified language, necessary to recreate the input data inside a program.
 
To run the script, first make sure that you have a Perl interpreter installed on your system and download the bin2hex.pl script. Then execute the following command from your command prompt (assuming you want to convert a file named banner.gif to a Perl string):
 
comments

CALLING CONTROL PANEL APPLETS FROM YOUR PROGRAMS AND SCRIPTS


Looking for a way to open Control Panel applets from your programs without opening the Control Panel
 
Whether you want your users to change the system date/time properties, add a new modem or change joystick settings, there's an easy way to call all such Control Panel applets (icons) without opening the Control Panel folder. The good news is that you can use this method in any Windows programming environment or even in a simple BATch file.
 
Running the following command from your program will do the trick (CPL being the file name of the Control Panel applet to open. a list of such applets can be found at the bottom of this document):
 
comments

IS WINDOWS TASKBAR'S AUTO HIDE FEATURE ENABLED?


Want to know if the Windows taskbar's auto hide feature is enabled? Here's a simple function to check this written in C Language / C++ and Delphi. 
 
Delphi CODE
 
uses ShellAPI;

(*
  Returns TRUE if taskbar auto hide is on.

  if(IsTaskBarautoHideOn)then
  begin
    // auto hide is ON
  end;
comments

EASY WAY TO COMPARE DATES


Did you know that you can easily compare dates by using the "EncodeDate()"? Here are some examples: 
 
uses
  SysUtils;

{...}

if(Date > EncodeDate( 1997, 1, 1 ))then
begin
  { display "this program has expired" }
end;

{...}

if( EncodeDate( 1997, 1, 1 )
  > EncodeDate( 1996, 1, 1 ) ) then
begin
  {...}
end;
Listing #1 : Delphi code. Download datecomp (0.27 KB).

comments

ADD PERSONALITY TO YOUR GOOD OLD MKDIR() FUNCTION...


Looking for a function that can create multiple directories (directories inside directories) using a single function call? Well, "MkDir()" function is not it, but the following function maybe just what you're looking for: 
 
program MkDirMul;

uses
  SysUtils, FileCtrl;

procedure MkDirMulti(sPath : string);
begin
  if('' = sPath[Length(sPath)])then
  begin
    sPath := Copy(sPath, 1,
                  Length(sPath)-1);
  end;
comments

HOW TO CLEAR MULTIPLE EDIT CONTROLS WITHOUT HAVING TO REFER TO THEM ONE BY ONE


So your new form has 40 edit controls, and now you're looking for a quick and easy way to clear all of them without having to refer to them one by one. How about using a function like this: 
procedure TForm1.Button1Click(Sender: TObject);
var
  i : integer;
begin
  for i := 0 to ComponentCount-1 do
    begin
      if( Components[ i ] is TEdit )then
      begin
        (Components[ i ] as TEdit).Text := '';
      end;
  end;
end;



comments

TWO WAYS TO CHANGE THE DEFAULT PROJECT OPTIONS


You can change the default project options (which is being used by every new project you create) from Delphi GUI:
  1. Create a new project (File | New Application)
  2. Go to "Project | Options" and change the options as you wish.
  3. Check "Default" checkbox in the tabs which you changed options in.
If you rather change the options "manually," you can do so using a simple text editor:

  1. Edit defproj.dof file located in your Delphi's BIN directory (C:\Program Files\Borland\Delphi 2.0\Bin for example) using Notepad or any other text editor. If you don't see the defproj.dof, create one using your favorite text editor in the Delphi's BIN directory using the following format:

    [Compiler]
    A=1
    B=0
    C=0
    D=1
    E=0
    F=0
    G=1
    H=1
    I=1
    J=1
    K=0
    L=1
    M=0
    N=1
    O=1
    P=1
    Q=0
    R=0
    S=0
    T=0
    U=0
    V=1
    W=0
    X=1
    Y=0
    Z=1
    ShowHints=0
    ShowWarnings=0
    UnitAliases=WinTypes=Windows;
    WinProcs=Windows;DbiTypes=BDE;
    DbiProcs=BDE;DbiErrs=BDE;

    [Linker]
    MapFile=0
    OutputObjs=0
    ConsoleApp=1
    DebugInfo=0
    MinStackSize=16384
    MaxStackSize=1048576
    ImageBase=4194304
    ExeDescription=

    [Directories]
    OutputDir=
    SearchPath=
    Conditionals=

    [Parameters]
    RunParams=

comments

HOW TO CALL INTERNET EXPLORER FROM DELPHI


Now that Internet Explorer is a standard part of Windows NT 4.0 and future versions of Windows [95], you may find it useful to add a hot key to your program which will take the user to your home page. Here's a simple function which will do just that: 
program iexplor;

uses
  Windows, OLEAuto;


procedure OpenInternetExplorer( sURL : string );
const
  csOLEObjName = 'InternetExplorer.Application';
var
  IE        : Variant;
  WinHanlde : HWnd;
comments

IS IT 'C:\PROGRAM FILES' OR 'C:\PROGRA~1'


Here's a way to convert between short 8.3 DOS file names and long file names. 
 
First function will convert long file names to the 8.3 format:
 
// remove following two lines
// if already included
uses
  Windows, SysUtils;

function
  GetShortName( sLongName : string )
  : string;
comments

IS IT 'C:\PROGRAM FILES' OR 'C:\PROGRA~1'


Here's a way to convert between short 8.3 DOS file names and long file names. 
 
First function will convert long file names to the 8.3 format:
 
// remove following two lines
// if already included
uses
  Windows, SysUtils;

function
  GetShortName( sLongName : string )
  : string;
comments

BACKGROUND DELPHI FORM


Of course you could place a "TImage" component on your form and set its "Alignment" to "Client" in order to place a background image on your form. Here's another way: 
  1. Add following code to your form's "Public declarations" section:
     
    bmpBackground : TBitmap;
    Listing #1 : Delphi code. Download code (0.15 KB).
     
  2. Double click on your form and add bitmap initialization code in the "FormCreate" event:
     
comments

DRAG AND DROP FILES ON YOUR PROGRAM


If you want to let your users drag and drop files on your program from the File Manager and Windows Explorer, simply add the code inside //>>> and //<<< to your program as in the following example: 
 
unit dropfile;

interface

uses
  Windows, Messages, SysUtils, Classes,
  Graphics, Controls, Forms, Dialogs;
comments

EXPLORE YOUR DOCUMENTS, PROGRAMS AND URLS


If you like how Windows Explorer and File Manager lets you open documents just by double clicking on them, without openning the associated program first, here's how to achieve similar functionality from your Delphi program: 
 
program shellexe;

uses
  WinTypes, ShellAPI;

procedure OpenObject( sObjectPath : string );
begin
  ShellExecute( 0, Nil, PChar( sObjectPath ),
                 Nil, Nil, SW_NORMAL );
end;
comments

FIND OUT WHERE YOUR PROGRAM IS RUNNING FROM


Sometimes it's necessary to find out the path to the executable file of your program, in order to find out where to get the rest of the files from. In most cases, the current directory would be the directory where your programs are executed from, but this method would not work if your program path is listed in the PATH or if an user executes your program from another directory. 
 
Here's how to get the directory where your programs is located:
 
  MessageDlg(
    'program path =  ' +
    ExtractFilePath( Application.ExeName )
    , mtInformation, [mbOk], 0 );
Listing #1 : Delphi code. Download exepath (0.23 KB).

comments

HOW TO CREATE A CONSOLE MODE PROGRAM


You can write console mode programs, also called command line programs, programs that usually does not use Windows' graphical user interface, using Delphi. 
 
  1. Create a new application using "File | New Application"
     
  2. Go to the "Project Manager" ("View | Project Manager")
     
  3. Remove the default form from the project (highlight the unit and hit DELETE -- do not save changes)
     
  4. Go to "Project Source" ("View | Project Source")
     
  5. Edit your project source file:
comments

CHANGE WINDOWS WALLPAPER FROM YOUR PROGRAM


Many programs including major Internet browsers lets you change the Windows wallpaper. Here's how you can add similar functionality to your program: 
 
program wallpapr;

uses
  Registry, WinProcs;

procedure SetWallpaper(
            sWallpaperBMPPath : String;
            bTile : boolean );
comments

HOW TO ACCESS PORTS


In the old days of DOS and 16bit Windows, writing to ports (serial, printer, game, video and other ports) in your computer was easy; all you had to do was use the "port[]" command. 
 
Delphi no longer supports the "port[]" command, so you may have to use assembly functions as follows:
 
function ReadPortB
         ( wPort : Word ) : Byte;
begin
  asm
    mov dx, wPort
    in al, dx
    mov result, al
  end;
end;
comments