Click here to Skip to main content
15,878,748 members
Articles / Multimedia / GDI+
Article

Screen Painter

Rate me:
Please Sign up or sign in to vote.
4.55/5 (13 votes)
11 Jul 2004CPOL3 min read 85.2K   2.6K   50   9
Application for painting on the screen.

Image 1

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)


Written By
Software Developer (Senior)
Bosnia and Herzegovina Bosnia and Herzegovina
Bahrudin Hrnjica holds a Ph.D. degree in Technical Science/Engineering from University in Bihać.
Besides teaching at University, he is in the software industry for more than two decades, focusing on development technologies e.g. .NET, Visual Studio, Desktop/Web/Cloud solutions.

He works on the development and application of different ML algorithms. In the development of ML-oriented solutions and modeling, he has more than 10 years of experience. His field of interest is also the development of predictive models with the ML.NET and Keras, but also actively develop two ML-based .NET open source projects: GPdotNET-genetic programming tool and ANNdotNET - deep learning tool on .NET platform. He works in multidisciplinary teams with the mission of optimizing and selecting the ML algorithms to build ML models.

He is the author of several books, and many online articles, writes a blog at http://bhrnjica.net, regularly holds lectures at local and regional conferences, User groups and Code Camp gatherings, and is also the founder of the Bihac Developer Meetup Group. Microsoft recognizes his work and awarded him with the prestigious Microsoft MVP title for the first time in 2011, which he still holds today.

Comments and Discussions

 
GeneralError - ON_REGISTERED_MESSAGE(UWM_KEYDOWN, OnUKeyDown) Pin
Daniel C Belchior22-Aug-08 6:33
Daniel C Belchior22-Aug-08 6:33 

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

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