Thread: find if text in edit box has been changed

  1. #1
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378

    find if text in edit box has been changed

    hey, i was wondering how you tell and take action if the text in an edit box has changed. like, with some programs - they append a * to the end of the name of the file open. then if you haven't saved the file since the last time it's been edited, when you go to close the program a prompt appears saying "dude, you haven't saved this and its been changed..wanna do it?" then you have a Yes, No, and Cancel button. so yea..how do i tell if the text has been changed, and how would i go about creating this prompt when the program is closing? thanks
    Registered Linux User #380033. Be counted: http://counter.li.org

  2. #2
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    The parent window of the Edit control receives a WM_COMMAND Message. The LOWORD of wParam is the ID of the control and the HIWORD is EN_CHANGE, a notification that says the text has changed. And, if you need to use it, the lParam of the message is a handle to the control. You can probably figure out the rest.
    Last edited by Jaken Veina; 07-06-2005 at 09:12 AM.
    Code:
    void function(void)
     {
      function();
     }

  3. #3
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    alrighty, thanks.. we'll see what i can come up with
    Registered Linux User #380033. Be counted: http://counter.li.org

  4. #4
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    ..wow.....that was a lot more work than i thought it would be, but i believe that i got it working now. having this function with a MDI is quite the hassle as you must check in multiple places to see if theres an unsaved file before closing the files or the program, and then find out which file it is that is not saved. and then once you do save it, you have to notify your program of that. however, i won't continue to ramble on..just thought that someone wanting to accomplish a similar task may find that info useful.
    Registered Linux User #380033. Be counted: http://counter.li.org

  5. #5
    -AppearingOnThis..........
    Join Date
    May 2005
    Location
    Netherlands
    Posts
    44
    It may be easier if you just have to retrieve the state of the edit at a certain point (ie. not moniter it over a period of time) to use the EM_GETMODIFY message. Simply send that to the edit and the return value'll be non-zero if the contents have been edited and zero if they haven't.

  6. #6
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    and when would i send this message, when the user wants to close a document or the program? do you have any sample code?
    Registered Linux User #380033. Be counted: http://counter.li.org

  7. #7
    -AppearingOnThis..........
    Join Date
    May 2005
    Location
    Netherlands
    Posts
    44
    Sorry, forgot I posted...

    Yeah, just send it when the user's about to close, something of this sort:
    Code:
    //yada yada yada, window procedure
    case WM_CLOSE : 
    	if(SendDlgItemMessage(winh, EDIT_ID, WM_GETMODIFY, 0, 0)) 
    	{
    		if(MessageBox(winh, "This document has not been saved, are you sure you want to close?", "Alert", 
    			MB_ICONEXCLAMATION | MB_YESNO) == IDYES) DestroyWindow(winh);
    	}
    	else DestroyWindow(winh);
    	break;
    //whatever else...
    And whenver you do save it you could send the edit a WM_SETMODIFY message to set the modification status to 0.
    Last edited by SirNot; 07-09-2005 at 03:09 AM.

  8. #8
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    ic ic, alright..thanks. i'll look into giving that a try.
    Registered Linux User #380033. Be counted: http://counter.li.org

  9. #9
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    uhm....i'm thinking there is no such "WM_GETMODIFY" value/message/whatever .. ? because when i search msdn for it, i get nothing..when i search google for it..all i get is a link to this post...when i try to compile with it...Dev-C++ is like "f* you >:O fix your code" lol

    anyone have a replacement?
    Registered Linux User #380033. Be counted: http://counter.li.org

  10. #10
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    try

    EM_GETMODIFY
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  11. #11
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    awesome :-D

    thanks.
    Registered Linux User #380033. Be counted: http://counter.li.org

  12. #12
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    so then if i'm going to use the EN_CHANGE message (for telling if the text has been modified or not and then sending that information to the status bar)...how do i make it go away after the file has been saved? also, after saving the text in the edit control, when i go to close the program it still says the file hasn't been saved and prompts to do so? do i need to like, clear the messages after saving? thanks.
    Registered Linux User #380033. Be counted: http://counter.li.org

  13. #13
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Strangely enough

    EM_SETMODIFY
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  14. #14
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    :-\ yea....*feels retarded* lol and i would use SengMessage() to set that?

    lol thanks..



    // prly someting like SendMessage(hEdit, EM_SETMODIFY, FALSE, 0);
    Last edited by willc0de4food; 09-10-2005 at 11:30 PM.
    Registered Linux User #380033. Be counted: http://counter.li.org

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. Adding text to a disabled edit box
    By osal in forum Windows Programming
    Replies: 1
    Last Post: 06-16-2004, 01:23 PM
  3. Limiting Characters in Edit Box :: MFC
    By kuphryn in forum Windows Programming
    Replies: 5
    Last Post: 06-02-2002, 10:21 AM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM