Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 131,609 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,986 people online right now. Registration is fast and FREE... Join Now!




Win32 Edit Control Dirty Flag?

 
Reply to this topicStart new topic

Win32 Edit Control Dirty Flag?

monkey_05_06
post 26 Aug, 2006 - 08:04 PM
Post #1


New D.I.C Head

*
Joined: 26 Aug, 2006
Posts: 43


My Contributions


For my first Win32 app, I've been using the tutorial here, which seems pretty good to me. I've learned a lot and by tinkering around here and there I've found out some very interesting things.

Anyway, the tutorial has helped me to establish the beginnings of a text-editor. As if anyone really needs another one of those, but, it's a nice first program I think. It's an MDI text editor, and so far it's coming along pretty nicely.

However, I want to implement a "Save before exiting" type of thing (well, I've done this part) but with a check to make sure the text has been changed since the last save (or since it was opened). So I'm trying to figure out how to set a dirty flag.

More specifically what I need to know really is just how to have some sort of event thrown if the text in the edit control is changed...well...that's not really worded right...but hopefully you'll understand what I mean.

Thanks for any help,
monkey_05_06
User is offlineProfile CardPM

Go to the top of the page


Mrafcho001
post 26 Aug, 2006 - 09:23 PM
Post #2


D.I.C Addict

Group Icon
Joined: 1 Nov, 2005
Posts: 753



Thanked 5 times

Dream Kudos: 120
My Contributions


are you using an Edit control or Rich Edit Control.

Youll have to set an Even mask, and handle the notification messages (specificly for WM_CHAR), that'll tell you when the user has typed something.
User is offlineProfile CardPM

Go to the top of the page

monkey_05_06
post 27 Aug, 2006 - 05:24 PM
Post #3


New D.I.C Head

*
Joined: 26 Aug, 2006
Posts: 43


My Contributions


I'm using a plain edit control, not a rich edit control. And...maybe I'm just stupid, but please try to forgive me as this is my first win32 app...but I can't get the WM_CHAR (or WM_KEYDOWN or WM_KEYUP) messages to register. The code I have supplied is never run.

I think it may have something to do with my message loop, but...I'm not really sure.

Just for reference, my message loop is like this:

CODE
  while (GetMessage(&Msg, NULL, 0, 0) > 0) {
    if (!TranslateMDISysAccel(g_hMDIClient, &Msg)) {
      TranslateMessage(&Msg);
      DispatchMessage(&Msg);
      }
    }


I've tried several different code snippets for the aforementioned notification messages (both in my MDI child window proc function and my main window proc function), from changing the value of variables, to a MessageBox, and none of it appears to be running.

If I've done something wrong or you need to see more of my code, please just tell me. I'd really like to figure this out. And thanks again for any help!
User is offlineProfile CardPM

Go to the top of the page

monkey_05_06
post 29 Aug, 2006 - 09:41 AM
Post #4


New D.I.C Head

*
Joined: 26 Aug, 2006
Posts: 43


My Contributions


Okay, I'm guessing no one else has any other ideas how to fix this??? Because the issue still isn't resolved...and I still don't know what to do to fix it.

In my previous post I posted my message loop which shows that I use the TranslateMDISysAccel function...which I believe may be the problem, because MSDN states:

QUOTE
The TranslateMDISysAccel function processes accelerator keystrokes for window menu commands of the multiple-document interface (MDI) child windows associated with the specified MDI client window. The function translates WM_KEYUP and WM_KEYDOWN messages to WM_SYSCOMMAND messages and sends them to the appropriate MDI child windows.


I have attempted to capture the WM_SYSCOMMAND, but it is only run when closing a child window. For simplicity's sake, I only put this code:

CODE
    case WM_SYSCOMMAND:
      MessageBox(NULL, "Echo.", "It won't work.", MB_OK);
    default:
      return DefMDIChildProc(hwnd, msg, wParam, lParam);


The default case was already there, but I posted it to show that I allow it to run the default processes after displaying the messagebox.

As I already stated I have tried this with WM_CHAR, WM_KEYUP, WM_KEYDOWN, and I've also tried WM_DEADCHAR, WM_SYSCHAR, WM_SYSDEADCHAR, WM_SYSKEYUP, WM_SYSKEYDOWN, in addition to WM_SYSCOMMAND.

The only time the messagebox was displayed, was, as I stated, when I used WM_SYSCOMMAND and closed the child window.

Any further assistance would be greatly appreciated.
User is offlineProfile CardPM

Go to the top of the page

kavendek
post 30 Nov, 2007 - 12:56 PM
Post #5


New D.I.C Head

*
Joined: 30 Nov, 2007
Posts: 1


My Contributions


More than a year late, but I know how to do what you're trying, so I may as well post it, for posterity.

You won't receive any WM_CHAR commands. You have to look for something more abstract. The API has certainly already foreseen this as being something folks would want to do.

From the docs:

QUOTE
The user makes editing requests by using the keyboard and mouse. The system sends each request to the edit control's parent window in the form of a WM_COMMAND message. The message includes the edit control identifier in the low-order word of the wParam parameter, the handle of the edit control in the lParam parameter, and an edit control notification message corresponding to the user's action in the high-order word of the wParam parameter.


The notification message you're looking for is EN_CHANGE:

QUOTE
EN_CHANGE Notification

Sent when the user has taken an action that may have altered text in an edit control. Unlike the EN_UPDATE notification message, this notification message is sent after the system updates the screen. The parent window of the edit control receives this notification message through a WM_COMMAND message.


Soooooo... hopefully that's all you need. But since I've got my code here, for completeness, here's how you receive it (from inside your wndproc callback):

CODE
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        //...

        case WM_COMMAND:
        {
            switch(HIWORD(wParam))
            {
                //...

                case EN_CHANGE:
                {
                    //Text has changed!
                    g_bDirty = true;
                    break;
                }

                //...
            }
            break;
        }

        //...
    }
}


This post has been edited by kavendek: 30 Nov, 2007 - 12:58 PM
User is offlineProfile CardPM

Go to the top of the page

monkey_05_06
post 27 Sep, 2008 - 02:05 PM
Post #6


New D.I.C Head

*
Joined: 26 Aug, 2006
Posts: 43


My Contributions


Almost a year after that...sorry for dragging up what I'm sure has been declared a dead thread, but I haven't logged into DIC since 2006. I saw that someone had posted a reply here so I figured I'd check it out.

I do still have that program source, but it is currently on a HDD sitting in the top drawer of my dresser in my bedroom. At the time I was using my parents' computer; now I am using my roommates' computer. One day I should really get around to buying my own...tongue.gif

But a slightly cheaper solution to allow access to my files once more is of course to purchase a SATA HDD external casing. As soon as I can afford one that is.

So for now I can't test the results...but thank you for your response.

-Michael
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/20/08 04:23AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month