Overview
This article shows painting on screen by using command line parameters. Application is dialog based with transparent property, so painting on screen is actually painting on dialog which is invisible (transparent). Command line parameters provide possibility for other applications to use this application as its component.
Classes
This project contains 5 classes:
CCmdLineParser
- Command line parameters class
CScreenPainterApp
- Application class
CScreenPainterDlg
- Dialog implementation
CStroke
- Modified class form Scribble tutorials
SShortcuts
- Structure for shortcuts key
Command line parameters
Implementation of the command line parameter is based on CCmdLineParser
class by Pavel Antonov. The code below shows the implementation of command line parameters.
void CScreenPainterApp::CommandLine(CScreenPainterDlg *pWnd)
{
if(parser.HasKey("sec"))
{
CString strSec=parser.GetVal("sec");
if(strSec!="123874981724sjdhflaksjdoaisdj20938448laskfj")
{
pWnd->SendMessage(WM_CLOSE);
}
}
else
{
pWnd->SendMessage(WM_CLOSE);
}
if(parser.HasKey("start"))
{
pWnd->StartAnnotation();
}
if(parser.HasKey("clear"))
{
pWnd->ClearTheScreen();
}
if(parser.HasKey("cursor"))
{
CString strCursor=parser.GetVal("cursor");
pWnd->SetCursor(strCursor);
}
if(parser.HasKey("color"))
{
CString col=parser.GetVal("color");
pWnd->SetColor(ParseColor(col));
}
if(parser.HasKey("thinkness"))
{
CString think=parser.GetVal("thinkness");
pWnd->SetThinkness(atoi(think));
}
if(parser.HasKey("pentype"))
{
CString pen=parser.GetVal("pentype");
pWnd->SetPenType(atoi(pen));
}
if(parser.HasKey("exit"))
{
pWnd->SendMessage(WM_CLOSE);
}
if(parser.HasKey("Pclear"))
{
CString str=parser.GetVal("Pclear");
pWnd->m_sShotcuts.clear=str.GetAt(0);
}
if(parser.HasKey("Pexit"))
{
CString str=parser.GetVal("Pexit");
pWnd->m_sShotcuts.exit=str.GetAt(0);
}
if(parser.HasKey("Pincrw"))
{
CString str=parser.GetVal("Pincrw");
pWnd->m_sShotcuts.incrw=str.GetAt(0);
}
if(parser.HasKey("decrq"))
{
CString str=parser.GetVal("Pdecrq");
pWnd->m_sShotcuts.decrq=str.GetAt(0);
}
if(parser.HasKey("Pblue"))
{
CString str=parser.GetVal("Pblue");
pWnd->m_sShotcuts.blue=str.GetAt(0);
}
if(parser.HasKey("Pred"))
{
CString str=parser.GetVal("Pred");
pWnd->m_sShotcuts.red=str.GetAt(0);
}
if(parser.HasKey("Pgreen"))
{
CString str=parser.GetVal("Pgreen");
pWnd->m_sShotcuts.green=str.GetAt(0);
}
if(parser.HasKey("Pyellow"))
{
CString str=parser.GetVal("Pyellow");
pWnd->m_sShotcuts.yellow=str.GetAt(0);
}
pWnd->StartAnnotation();
}
Screen Painter parameters
Command line parameters has the standard form like:
screenpainter.exe [Argument list]
[Argument list] can be one of the following:
- sec:value
- clear
- start
- cursor:filename
- color: Red,Green,Blue
- thinkness:value
- pentype:pentype
- close
- Pclear:value
- Pexit:value
- Pincrw:value
- Pdecrq:value
- Pblue:value
- Pred:value
- Pgreen:value
- Pyellow:value
Arguments
- sec:value argument. Sets the security code for starting. Security code is required when the application starts. If there is no security code, application cannot be started.
Example:
screenpainter.exe �sec:SecurityCode
- clear argument. Clears the screen. Use this argument when you want to clear the screen contents.
Example:
screenpainter.exe �clear
- start argument. This argument starts the annotation.
Example:
screenpainter.exe �start
- cursor: filename argument. The cursor argument sets the cursor from the file name. This argument has a value. The value of the cursor argument is a *.cur or *.ani file name. If file is not in the root directory of the application, you have to specify full path name.
Example:
screenpainter.exe �cursor:test.cur
or
screenpainter.exe �cursor :c:\test.cur
- color:red,green,blue argument. Color argument sets the color of a pen.
Example:
screenpainter.exe �color: 0,0,255
- thinkness:value argument. Sets the pen width.
Example:
screenpainter.exe �thinkness:2 - determines the pen width of 2 pixels.
- pentype:pentype argument. Sets the type of a pen. There are 7 types of pen:
- pentype: 1 =
PS_SOLID
- Creates a solid pen
- pentype: 2 =
PS_DASH
- Creates a dashed pen. Valid only when the pen width is 1 or less, in device units.
- pentype: 3 =
PS_DOT
- Creates a dotted pen. Valid only when the pen width is 1 or less, in device units.
- pentype: 4 =
PS_DASHDOT
- Creates a pen with alternating dashes and dots. Valid only when the pen width is 1 or less, in device units.
- pentype: 5 =
PS_DASHDOTDOT
- Creates a pen with alternating dashes and double dots. Valid only when the pen width is 1 or less, in device units.
- pentype: 6 =
PS_NULL
- Creates a null pen.
- pentype: 7 =
PS_INSIDEFRAME
- Creates a pen that draws a line inside the frame of closed shapes.
Example:
screenpainter.exe �pentype:2 - Set the pen type PS_DASH..
- close argument. Closes the application.
Example:
screenpainter.exe �close
Of course, when you are starting the application, you can use any combination of the mentioned arguments.
Example:
screenpainter.exe -sec:SecurityCode -cursor:filename.cur
-color:127,233,147 -thinkness:20 -pentype:2
or
screenpainter.exe �clear -close
etc��.
Screen Painter options
During the drawing, you can use some of the option commands. Any option command you can fire up by pressing the corresponding keyboard key. The following commands are available:
- x - Exit the application.
- c - Clear the screen.
- w - increase the Pen width for one pixel.
- q - decrease the Pen width for one pixel.
- b - change current color of the Pen in Blue color.
- r - change current color of the Pen in Red color.
- g - change current color of the Pen in Green color.
- y - change current color of the Pen in Yellow color.
All options are available while you are drawing on the screen. The shortcuts for option commands are predefined and they can be modified, with command line parameters.
Pclear:value argument changes default shortcut key �c� for clear to �value� key.
Example:
screenpainter.exe �Pclear:z -after executing this parameter,
default key for clear is cahanged in to �z�.
Pexit:value argument changes default shortcut key �x� for clear to �value� key.