CPromptEdit

Environment:

The following project implements a derived box from CEdit featuring a prompt command.

The code guarantees to work well depending on the options that developer chooses when drawing the dialog box: they should be preserved as those included in the following project (MULTILINE, AUTOVSCROLL ...).



Click here for larger image

I do not put any code here, because it would be unuseful and much boring. In fact the code of CPromptBox is very simple and it should be understood easily at running time, since the matter is just to rule the caret movement at each row, or just taking the string of every row.


Anyway, some attention should be payed to how to connect the prompt of a working class (for example: a parser). I have implemented a simple method in this project, where CPromptEdit communicates with a report box on the right.

Look at the image below:



Click here for larger image


Anyway a lot of other methods can be come out, according to your needs or fantasy, so ...

... comments and suggestions are very well appreciated both in this site and directly to me at : my e-mail

Downloads

VC++ 5.0 project - 22 Kb
The class code - 4 Kb


Comments

  • Links to "click here for larger image" fixed

    Posted by Brad Jones on 08/02/2004 08:46am

    The links to the larger images have now been fixed.

    Reply
  • Small fix for using of Home key (VK_HOME)

    Posted by Legacy on 12/18/2002 12:00am

    Originally posted by: Fran�ois Le Luhern

    Here is a small fix which move the caret to the end of the promt when typing home key.
    
    

    void CPromptEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
    {
    static bool bNoTrait = false;

    if ( nChar == 0x0D )
    {
    .
    .
    .
    }
    else
    {
    // Ruling key movements
    if ( bKeyFlag && !bNoTrait )
    {
    .
    .
    .
    }

    CEdit::OnKeyDown(nChar, nRepCnt, nFlags);

    if ( bKeyFlag && !bNoTrait )
    {
    bNoTrait = true;
    if( nChar == VK_HOME )
    {
    pos = limit_text_left;
    for( int i = pos; i; i-- )
    SendMessage( WM_KEYDOWN, VK_RIGHT , 0x0 ) ;
    }
    bNoTrait = false;
    }
    }

    Reply
  • ExEditors Library

    Posted by Legacy on 03/19/2002 12:00am

    Originally posted by: Mike Philips

    A complete collection of editors in a single file:
    
    

    http://www.exontrol.com/sg.jsp?content=products/exeditors

    Regards,
    Mike

    Reply
  • Author: constant updating in my site

    Posted by Legacy on 03/06/2002 12:00am

    Originally posted by: Alessandro Rosa

    Thank you to everyone writing his suggestions to me.
    CPromptEdit has been always updating in my web site
    http://www.malilla.supereva.it/Pages/Prog/Prompt/promptedit.html

    Alessandro Rosa

    Reply
  • Fix for using in a Dialog

    Posted by Legacy on 03/05/2002 12:00am

    Originally posted by: Bill Klavoon

    The code works for a Dialog-App but does not work for a standard modal dialog.  The AfxGetMainWnd() sends the update messages to the applications main window and not to the parent of the control.
    
    

    change:

    // Example of Bridge-connection :
    AfxGetMainWnd()->SendMessage( PROMPT_DEFINED_MSG, 0x0 ,0x0 ) ;

    to:
    GetParent()->SendMessage( PROMPT_DEFINED_MSG, 0x0 , 0x0 ) ;


    -Bill

    Reply
  • Fixed memory leaks & do not add strings twice to history

    Posted by Legacy on 02/27/2002 12:00am

    Originally posted by: Andreas Kuhtz

    Hi
    
    

    The CPromptBox is great!
    One little suggestion: if you add a line twice, the string
    is added twice into the 'history' ! It would be better to
    check if the string already exists in the 'history'. I
    changed the InsertMenuItem to provide this feature.

    int CPromptEdit::InsertMenuItem( CString new_menu_string )
    {
    if ( new_menu_string.IsEmpty() ) return menu_entries ;
    //////////////////////////////////////////////////
    // This routine returns how many items are included
    // in the menu, at current time
    //////////////////////////////////////////////////
    // take last initialized string, but if array is
    // still empty the last index is retrieved -1;
    // look at the end of this routine
    int last_indexed_used_string = -1 ;

    for( int i = 0 ; i < lines_per_screen ; i++ )
    {
    if ( p_array_str[ i ] != (CString*)NULL )
    {
    // --- andreas.kuhtz@siemens.ch ---
    // check if the string is already in the 'history'
    if (p_array_str[i]->Compare(new_menu_string) == 0)
    {
    // string already in 'history'
    return menu_entries;
    }
    // --- andreas.kuhtz@siemens.ch ---

    last_indexed_used_string = i ;
    }
    else
    {
    p_array_str[ i ] = new CString ;
    *p_array_str[ i ] = new_menu_string ;

    return i + 1 ;
    }
    }
    //////////////////////////////////////////////////
    // All entries are full, so slide them all back for one step
    // and fill the last entry
    if ( menu_entries == lines_per_screen )
    {
    for( i = 1 ; i < menu_entries ; i++ )
    *p_array_str[ i - 1 ] = *p_array_str[ i ] ;

    *p_array_str[ i - 1 ] = new_menu_string ;
    }
    //////////////////////////////////////////////////

    return menu_entries ;
    }

    Some memory leaks were fixed:

    CPromptEdit::CPromptEdit()
    : p_array_str (NULL) // --- andreas.kuhtz@siemens.ch --- set init value
    {
    menu_entries = 0 , lines_index = 0 , text_length = 0 ;
    pos = 0 ;
    }

    CPromptEdit::~CPromptEdit()
    {
    // --- andreas.kuhtz@siemens.ch ---
    // delete the strings
    if (p_array_str)
    {
    for( int i = 0 ; i < lines_per_screen ; i++ )
    {
    CString* pString = p_array_str[ i ];
    delete pString;
    }
    delete[] p_array_str;
    }
    // --- andreas.kuhtz@siemens.ch ---
    }

    If you set the "generate debug info" under the linker
    settings you can debug the program!


    Reply
  • Delete key issues

    Posted by Legacy on 02/27/2002 12:00am

    Originally posted by: Chris Wise

    It seems I am able to hit the delete key and destroy the prompt or any other text I've outputted back to the CPromptEdit control. I am in the processing of writing a snippet to prevent this.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

Most Popular Programming Stories

More for Developers

RSS Feeds