Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » Clipboard Operations Across All Windows Collapse All
Subject Author Date
Scott Moore Jun 13, 2008 - 9:12 AM

I have an application and I’m trying to make the standard Cut/Copy/Paste/Select All commands operate across all the various dynamic bars, CExtControlBars and tab view containers.


The problem is nothing is consistent.  We have a tab control in the CMainFrame, which mostly works correctly with the clipboard operations.  Inside the tab control is a CHtmlView, but we also have CExtEdit in CExtControlBar and some floating Dynamic Bar windows and they never seem to work correctly.


I started trying to write a global handler like so:




void CMainFrame::OnSelectAll()

{

    CWnd * target = CWnd::GetFocus();



    if (target)

    {

        CRenderView * view = dynamic_cast <CRenderView *> (target);



        if (view)

        {

            view->SelectAll();

            return;

        }



        CEdit * edit = dynamic_cast <CEdit *> (target);

        if (edit)

        {

            edit->SetSel(0, -1);

        }

    }

}


Which actually almost works if you use the Ctrl-A shortcut.  If you select it from the menu, most times the target becomes the menu item itself unless the focus was in CExtEdit.  The focus is always lost for CHtmlView.  However, if you hit Ctrl-A while the CExtControlBar->CExtEdit has the focus, all it does it beep, but selecting "Select All" from the menu works for the CExtEdit.


Please tell me there’s an easier way to make this work like a normal windows application?


 

Technical Support Jun 14, 2008 - 3:39 AM

This code should work correctly only if there is only one instance of the CRenderView object and only one instance of CEdit is created at runtime. Most of applications have more than one CEdit objects instantiating at the same time. Please try to define and use your own CEdit-derived class. Besides, if the edit common control is not configured for displaying selection always and it’s not focused, then you will not see the selection in it.

Scott Moore Jun 13, 2008 - 11:01 AM

Also, I can’t figure out why the CExtEdit control on my CExtControlBar ends up eating the Ctrl-A menu shortcut and causing a beep.  Why doesn’t the menu handler get invoked?


In the CExtResizeableDialog (the child of CExtControlBar), we did override this method:




BOOL UrlToolbar::PreTranslateMessage(MSG * pMSG)

{

    if (WM_KEYFIRST <= pMSG->message && pMSG->message <= WM_KEYLAST

        &&  ( pMSG->wParam == VK_TAB || pMSG->wParam == VK_UP

        || pMSG->wParam == VK_DOWN ))

    {

        return CExtResizableDialog::PreTranslateMessage(pMSG);

    }

    else

    {

        return CWnd::PreTranslateMessage(pMSG);

    }

}

Technical Support Jun 14, 2008 - 3:41 AM

The CExtEditBase::OnCmdMsg() virtual method handles and updates several standard ID_EDIT_*** commands including ID_EDIT_SELECT_ALL. You can implement your CExtEdit-derived class, override the CExtEditBase::OnCmdMsg() virtual method and simply invoke the CWnd::OnCmdMsg() method in it or return FALSE if you don’t needed the command handling/updating of the CExtEditBase class.

Scott Moore Jun 14, 2008 - 8:30 AM

But why doesn’t the CExtEdit handle the Ctrl-A, which maps to ID_EDIT_SELECT_ALL?  Instead of selecting the text in the edit control, it just beeps.


Conversely, if I choose "Select All" from the menu, it works correctly.  Why doesn’t it handle the keyboard accelerator correctly?

Technical Support Jun 14, 2008 - 3:27 PM

The CExtEditBase::OnCmdMsg() virtual method handles and updates all the ID_EDIT_*** commands correctly. Here is the modified version of the SDI sample:

SDI-SampleAppUpdated.zip

It contains an ID_EDIT_SELECT_ALL command in the Edit popup menu in the menu bar and this command is handled correctly by the edit control inside a control bar due to the following code in the CMainFrame::OnCmdMsg() virtual method:

      if(         ::GetFocus() == m_wndInBarEdit.GetSafeHwnd()
            &&    m_wndInBarEdit.OnCmdMsg( nID, nCode, pExtra, pHandlerInfo )
            )
            return TRUE;