Click here to Skip to main content
Click here to Skip to main content

Screen Painter

, 11 Jul 2004
Rate this:
Please Sign up or sign in to vote.
Application for painting on the screen.

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)
{
    //Parsing the command parameters

     //First we check the security code 
    if(parser.HasKey("sec"))
    {
        CString strSec=parser.GetVal("sec");
        if(strSec!="123874981724sjdhflaksjdoaisdj20938448laskfj")
        {
          //string is wromg so there is no security code
          pWnd->SendMessage(WM_CLOSE);
        }
    }
    else
    {
        //ther is no security code
        pWnd->SendMessage(WM_CLOSE);
    }

    //No nedd for this parameter thue to Start Annotation when app starts
    if(parser.HasKey("start"))
    {
        pWnd->StartAnnotation();
    }

    //Clear command
    if(parser.HasKey("clear"))
    {
        pWnd->ClearTheScreen();
    }
    //Cursor
    if(parser.HasKey("cursor"))
    {
        CString strCursor=parser.GetVal("cursor");
        pWnd->SetCursor(strCursor);
    }
    //Color of the pen
    if(parser.HasKey("color"))
    {
        CString col=parser.GetVal("color");

        pWnd->SetColor(ParseColor(col));
    }
    //Thinkness
    if(parser.HasKey("thinkness"))
    {
        CString think=parser.GetVal("thinkness");
        pWnd->SetThinkness(atoi(think));
    }
    //PenType
    if(parser.HasKey("pentype"))
    {
        CString pen=parser.GetVal("pentype");
        pWnd->SetPenType(atoi(pen));
    }
    //Exit App
    if(parser.HasKey("exit"))
    {
      pWnd->SendMessage(WM_CLOSE);
    }
    //option command for clear the screen
    if(parser.HasKey("Pclear"))
    {
        CString str=parser.GetVal("Pclear");
        pWnd->m_sShotcuts.clear=str.GetAt(0);
    }
    //option command for exit app
    if(parser.HasKey("Pexit"))
    {
        CString str=parser.GetVal("Pexit");
        pWnd->m_sShotcuts.exit=str.GetAt(0);
    }
    //option command for pen width
    if(parser.HasKey("Pincrw"))
    {
        CString str=parser.GetVal("Pincrw");
        pWnd->m_sShotcuts.incrw=str.GetAt(0);
    }
    //option command for pen width
    if(parser.HasKey("decrq"))
    {
        CString str=parser.GetVal("Pdecrq");
        pWnd->m_sShotcuts.decrq=str.GetAt(0);
    }
    //option command for blue color
    if(parser.HasKey("Pblue"))
    {
        CString str=parser.GetVal("Pblue");
        pWnd->m_sShotcuts.blue=str.GetAt(0);
    }
    //option command for red color
    if(parser.HasKey("Pred"))
    {
        CString str=parser.GetVal("Pred");
        pWnd->m_sShotcuts.red=str.GetAt(0);
    }
    //option command for green color
    if(parser.HasKey("Pgreen"))
    {
        CString str=parser.GetVal("Pgreen");
        pWnd->m_sShotcuts.green=str.GetAt(0);
    }
    //option command for yellow color
    if(parser.HasKey("Pyellow"))
    {
        CString str=parser.GetVal("Pyellow");
        pWnd->m_sShotcuts.yellow=str.GetAt(0);
    }

    //Start Annotation have to be the last action
    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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Bahrudin Hrnjica
Software Developer (Senior)
Bosnia And Herzegovina Bosnia And Herzegovina
Senior Software Developer at daenet.eu and Microsoft MVP for Visual C#.
Follow on   Twitter   Google+

Comments and Discussions

 
Generalexcellent Pinmemberbecabeca1-Apr-07 4:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140826.1 | Last Updated 12 Jul 2004
Article Copyright 2004 by Bahrudin Hrnjica
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid