Thread: Cut, copy, undo, AAGG

  1. #1
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949

    Cut, copy, undo, AAGG

    I'm tryin to set up the ability to copy, paste, undo, and cut in my MDIWndProc, but it isnt working. Heres what I have so far:
    Code:
    LRESULT CALLBACK MDIChildWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
     switch(msg) {
      case WM_CREATE:
       {
        HFONT hfDefault;
        HWND hEdit;
        hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", 
         WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL, 
         0, 0, 100, 100, hwnd, (HMENU)ID_CHILD_EDIT, GetModuleHandle(NULL), NULL);
        if(hEdit == NULL) {
         MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);
        }
        hfDefault = GetStockObject(DEFAULT_GUI_FONT);
        SendMessage(hEdit, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
       }
       break;
      case WM_CTLCOLOREDIT: 
       {
        HDC dc = (HDC)wParam;
        SetTextColor(dc, RGB(255, 0, 0));
       }
       break;
      case WM_SIZE:
       {
        HWND hEdit;
        RECT rcClient;
        GetClientRect(hwnd, &rcClient);
        hEdit = GetDlgItem(hwnd, ID_CHILD_EDIT);
        SetWindowPos(hEdit, NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER);
       }
       return DefMDIChildProc(hwnd, msg, wParam, lParam);
      case WM_MDIACTIVATE:
       {
        HMENU hMenu, hFileMenu;
        UINT EnableFlag;
        hMenu = GetMenu(g_hMainWindow);
        if(hwnd == (HWND)lParam) {
         EnableFlag = MF_ENABLED;
        } else {
         EnableFlag = MF_GRAYED;
        }
        EnableMenuItem(hMenu, 1, MF_BYPOSITION | EnableFlag);
        EnableMenuItem(hMenu, 2, MF_BYPOSITION | EnableFlag);
        hFileMenu = GetSubMenu(hMenu, 0);
        EnableMenuItem(hFileMenu, ID_FILE_SAVEAS, MF_BYCOMMAND | EnableFlag);
        EnableMenuItem(hFileMenu, ID_WINDOW_CLOSE, MF_BYCOMMAND | EnableFlag);
        EnableMenuItem(hFileMenu, ID_WINDOW_CLOSEALL, MF_BYCOMMAND | EnableFlag);
        DrawMenuBar(g_hMainWindow);
       }
       break;
      case WM_ERASEBKGND:
       return 1;
      case WM_COMMAND:
       switch(LOWORD(wParam)) {
        case ID_FILE_SAVEAS:
         DoFileSaveAs(hwnd);
         break;
        case ID_EDIT_CUT:
         SendDlgItemMessage(hwnd, ID_CHILD_EDIT, WM_CUT, 0, 0);
         break;
        case ID_EDIT_COPY:
         SendDlgItemMessage(hwnd, ID_CHILD_EDIT, WM_COPY, 0, 0);
         break;
        case ID_EDIT_PASTE:
         SendDlgItemMessage(hwnd, ID_CHILD_EDIT, WM_PASTE, 0, 0);
         break;
        case ID_EDIT_UNDO:
         {
          if(SendMessage(hwnd, EM_CANUNDO, 0, 0)) {
           SendMessage(hwnd, WM_UNDO, 0, 0);
          } else {
           MessageBox(hwnd, "Nothing to undo.", "Unable to undo!", MB_OK);
          }
         }
         break;
       }
       break;
      default:
       return DefMDIChildProc(hwnd, msg, wParam, lParam);
     }
     return 0;
    }
    Thanks !
    Do not make direct eye contact with me.

  2. #2
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    About the UNDO:

    hEdit is the handle of the edit box. not hwnd!

    so, it's not if(SendMessage(hwnd, EM_CANUNDO, 0, 0))
    SendMessage(hwnd, WM_UNDO, 0, 0);


    it's suppost to be: if(SendMessage(hEdit, EM_CANUNDO, 0, 0))
    SendMessage(hEdit, WM_UNDO, 0, 0);



    About the CUT, COPY, PASTE:
    try this: SendMessage(hEdit, WM_CUT, 0, 0);

    Because with this you can latter on, make it work with more than one edit boxes, with GetFocus()

    But there is no problem the way you did the cut, paste and copy.



    Note: you should make hEdit a global variable, or if you want it local, you will need to: hEdit=GetFocus(); before every cut, copy, paste, undo


    I hope that helps.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copying constant amount of data
    By TriKri in forum C++ Programming
    Replies: 16
    Last Post: 07-12-2008, 06:32 AM
  2. calling copy constructor from template
    By Ancient Dragon in forum C++ Programming
    Replies: 3
    Last Post: 09-28-2005, 01:54 PM
  3. dynamic memory alloccation & returning objects
    By haditya in forum C++ Programming
    Replies: 8
    Last Post: 04-21-2005, 11:55 PM
  4. Changing font in rich edit, without affecting undo buffer
    By jverkoey in forum Windows Programming
    Replies: 3
    Last Post: 01-17-2004, 08:54 PM
  5. Copy Constructor Help
    By Jubba in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2001, 11:15 AM