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

Screen Painter

By , 11 Jul 2004
 

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)

About the Author

Bahrudin Hrnjica
Software Developer (Senior)
Bosnia And Herzegovina Bosnia And Herzegovina
Member
Senior Software Developer and Microsoft MVP for Visual C#.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralScreen Paintermembervijay_varma8617 Aug '09 - 4:14 
Hello,
 
I think the ScreenPainter.exe file is working excellent but there is a problem with source demo code. can you provide me full source code for this application if possible.
 
Thanks & Regards,
Karumanchi
GeneralError - ON_REGISTERED_MESSAGE(UWM_KEYDOWN, OnUKeyDown)memberMember 338542822 Aug '08 - 6:33 
Hi,
 
I am trying to run the project on visual studio 2005, but when i try to run e receive the message above.
 

Error 1 error C2440: 'static_cast' : cannot convert from 'BOOL (__thiscall CScreenPainterDlg::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)' c:\documents and settings\daniel.belchior\desktop\screenpainter_src\screenpainter\screenpainterdlg.cpp 77
 

I wonder if some one can help me.
 
Thanks,
 
Daniel
GeneralGood work but Too many memory leaks!!memberbygreencn18 Apr '07 - 20:00 
Good work but Too many memory leaks!!
Generalexcellentmemberbecabeca1 Apr '07 - 4:14 
dear Sir,
 
excellent app!
 
best regards,
 
bb
General?Gr8memberSendilkumar.M12 Jul '05 - 2:23 
Nice stuff.
But i need the same in C#.Can you help me to have it?
 
M.Sendilkumar
|Thomson Financial | Bangalore |India |
GeneralWindow Clippingmembermr.axe23 Nov '04 - 2:39 
First off all, great code !
I was wondering, how can I draw only in a certain region of the screen ?
 
Mrax.
Smile | :)
GeneralRe: Window ClippingmemberBahrudin Hrnjica6 Dec '04 - 21:01 
First of all, thanks for interesting in my article.
Now, you can draw anywhere on the screen, so if you want to draw certain region, you have to specify size of dialog in OnSize() message, or better create dialog window region.
 
Regards
 

QuestionSecurity code?memberEricLaw13 Jul '04 - 15:54 
The security code is totally hackable, so why bother?
AnswerRe: Security code?memberBahrudin Hrnjica15 Jul '04 - 7:02 
When you use this app as a component to another application by using ShellExecute(...), and you dont want other user and application to run it, you can use the secirity code.
This is just an example how to use it, so if you use the application as stand alone forget the security code.
regards

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

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