Copying text from an MFC CDialog - c++

I'm currently working on code that I inherited. There is a class (I'll refer to it as logWindow) which inherits from CDialog. Overall the logWindow class creates a window and prints out text.
What I need to do is copy the text that is automatically generated in the window.
I know I need some sort of mouse and keyboard listener, but I'm a little lost on how to do this and how to select text.
I also have working code for a different log window written by the same person. That code has a class (I'll refer to it as copyList) which inherits from CListbox. Unfortunately the code isn't well documented or managed, so it is difficult to figure out which functions are related to copying text and which functions are related to other things such as auto scrolling.
I apologize if this is very unspecific, because of what I'm working on I'm limited in how much I can post. I will update the question with as much information as I can.

you can use GetWindowText or CWnd::GetWindowText to get the text from the control that holds the text, but this will copy all the text inside that control, so you will have to do tinker the text if you want some filtering. you said you already have a CListBox example working so you know how to iterate over the items.then you can use this link Clipboard: Using the Windows Clipboard and check how to handle the clipboard.you could also add a simple button "Send to clipboard" that sends the text to the clipboard

Related

How insert multiple FormView in View of an SDI application

I searched on the forum and I don't find a solution for my issue. So I hope you can help me :)
I work on a personal project for SFC designing (Sequential functional chart) and I'm working with visual studio in SDI(I'm using MFC library). If you see the "design" of an SFC you can see the different elements needed to compose this. So you can find Step, Transition, and more. If I take a step for explaining my issue, after double click on the step a popup dialog is opened with the elements to define this step (actions on this step, and more). The issue is here, I can't see two or more step elements at the same time. I want to reuse the existing concept on other software, see this.
Step close
Step open
Dialog to add
My question is, how I can implement a dialog with my graphic element in mainframe (In this case, a step)? I don't know how I can insert a dialog with my element, I think I need to use CFormView, but I don't know.
This dialog needs to be resizable and reduce directly by the step graphic.
any idea?
Thank you in advance! Sorry for my English ..
Sorry, I think my request is not clear .. (Thank you for your answer)
The context, it's an SDI application with the Document/View architecture. Actually the view is derived from CScrollView.
So, in the document class, you have the different lists of components for make SFC (Steps, transitions and symbols ..). I'm working today on Step element.
The user inserts a new step, the step is draw on the view like this :
enter image description here
And now the user want change the events on this Step, for this after double click on the step the events editor is opened at right of step draw, like this :
enter image description here
For this, I've created a new dialog resource and create the class by wizard in CForwView derived class. In step attribute, you can find one instance of this derived class (The derived class of dialog).
But this doesn't work correctly, I think my method is bad. At the first try, I have sent the pointer of the current document to the "CFormView::Create" function for having the "Save" button active with the focus on the FormView. But after destroying the step, the instance of FormView is destroyed and the document with the instance of formview ...
No problem, you can use "Create" within CCreateContext a null pointer. But with the document or without I have a lot of problems (graphic design not correct in FormView, regularly (not systematic I have assert fail on Proc exchange (for differents reason)). But the "concept" is good, the editor follows the draw if I scroll, I can open or close the editor at any time and on any elements.
For the old capture, it's my SFC designer "model". My application is a complement to this application, so I want a similar design. I don't know how work my model application ..
On my application all is draw by MFC GDI, I don't use ActiveX or other tools.
So what is the correct way to implement one instance of editor by instance of step ?
For the implementation on this FormView I have :
- Make new dialog in ressource
- Create a derived class of CFormView with the created dialog
- Add one instance in attributes of Step element
- "OnDbClickOnStep" -> Call "Create" with the good position / size, pointer of mainview (in my case the CSrollView derived class)
- Done, FormView inserted in a mainview, I can edit my step events.
? Not done, I lost save button and other function linked to the document with the focus on a control in FormView. The app want a document with this view, how to override this ?
? Error in Proc exchange, for different reason...
You have an idea ?
You normally don't draw anything in the "main frame" (or the "MDI clild frames", in the case of a MDI application), this is done by the library, and imo sufficiently so. You display your data in a CView-derived class.
CView is the base class of all other MFC view classes. It's a simple graphical class - you need to paint it yourself in the OnDraw() member.
CScrollView is a descendant of CView, adding scrolling functionality (scroll-bars are automatically displayed if the scrollable area is bigger than the visible window area).
CFormView is a descendant of CScrollView, displaying a dialog resource-script, containing "controls" (edit-boxes, check-boxes, images, ActiveX etc).
As in your case the "controls" won't be initially known (except maybe for some few special cases) and rather programatically created, the resource script will most likely be empty, so using either CFormView or CScrollView will basically be the same. I would suggest starting with CFormView, and "downgrade" it to CScrollView if CFormView is not necessary or causes you troubles.
What are those "Step" items shown in the pics? ActiveX controls, child dialogs maybe? These work best as child controls on a dialog window. Are they already implemented, or they are just pics of some other software? Btw ActiveX is a way to define controls that can be used in other projects too, without having to include them in the project source.

MFC can't find GetDocument() in a Dialog

I'm new to MFC,and I want to get some data in a Dialog,but this doesn't work,
CTestDoc* pDoc=GetDocument();
pDoc->Get(...);
I Google it and find GetDocument() only used in CView.
So I try this and it really works:
CMainFrame *pMain=(CMainFrame *)AfxGetApp()->m_pMainWnd;
CTestView *pView=(CTestView *)pMain->GetActiveView();
m_name=pView->v_name;
But I don't think it's a good solution,so I want to know is there any functions to solve this?Thank you.
You didn't say anything about what the dialog does but it may be desirable to pass this data to the dialog, and not have the dialog access the document data directly. This helps keep your dialog more isolated and more likely to be usable in other programs.
I would look at the command where the dialog is displayed. Is it in the view? If so, then you can pass the document data that is needed by the dialog. If not, then the code you posted may still make sense. Either way, that's where you should locate the desired document information, and then pass it to the dialog.
I would avoid making your dialog directly aware of the document if it's not necessary.
If you want to get data from dialog, first set the data, and then get it.
For example:
CString save;
filePath.GetWindowsText(save);
richBox1.AddString(save); // to display in another box

Creating a DialogBar with MFC with my own controls

I'm turning mad with a little problem with Visual Studio 2008 and MFC. I'm working on a project actually and I'm trying to create an SDI Application. Right, now I want to add a dockable DialogBar. Well, the first time I added it with the resource view, I could create the bar without problems.
But... I want to add some controls like a couple of ListBox, buttons and so on. The program doesn't allows me to create member variables for these controls. The option appears in grey.
Searching a little, I found that it's mandatory to create a new class derived from CDialogBar and "enhance" it with the Message handler and so on. I've been reading some tutorials and it didn't work for me.
Can you please help me? I'm starting to get nervous, the use of dialogbars is mandatory in my design and I've never implemented them before.
Thank you very much, and sorry for my poor english.
You can add a control member variable by hand instead of using the wizard. All it takes is a call to DDX_Control in the dialog bar's DoDataExchange function.
But CDialogBar-derived classes do not handle control clicks. The CDialogBar class forwards all of those messages to the dialog bar's parent window. So be prepared to add the message handlers to the parent (usually CMainFrame).
For learning purposes you might try creating your dialog bar as a CDialog first, to see the proper code lines and message map entries supplied by the wizard. Then you can copy/move these details as appropriate into your actual code project.

how to put a derived control ("MyCEdit") onto a dialog or property page?

This should be obvious, but I can't find anywhere that spells it out.
I want to derive a MyCEdit from CEdit so I can override the OnChar handler and do useful things with keyboard input to an edit box. Each edit box I have fills the client area on a MyCPropertyPage (derived from CPropertyPage), and several such pages make up a tab control used to display diagnostics. I leave the edit boxes enabled and not read only (for aesthetics, not function).
In the resource editor (or elsewhere) how to I tell Visual Studio that I want a certain edit box to be a MyCEdit rather than a CEdit? Can I hope to just override the OnChar in MyCEdit to intercept characters... or do I have to override OnKeyDown as well - I have read a suggestion to this effect, but found no MS source article spelling out why.
So far, the only thing I can easily override is MCPropertyPage::OnChar... but that seems to get bypassed, and characters just go straight to the edit box child.
HI if i understand you need you can add simple edit to your page, then add control variable and write MyCEdit in class name field. And dont forget to set parent notify option in resource editor on your MCPropertyPage.

MFC CEdit placeholder text

How do I have a CEdit control display placeholder text when it's empty, similar to the behavior of NSTextFields in Cocoa?
Ages ago, I wrote a custom paint routine to do it, seemed to work fine.
Sometime after, they introduced SetCueBanner to CEdit, but I can remember it:
a) not working correctly
or -
b) not behaving the way I wanted
Perhaps it will work fine for you. If not, I can see if I can find my old code and post what I did in the custom paint routine.
EDIT
I just checked the Win32 docs, I think this is why I abandoned it:
You cannot set a cue banner on a multiline edit control
you could create a small window over the top of it that contains the placeholder text. Then when the user sets the keyboard focus to it hide the window and if the focus is removed and nothing is in the box then show it.
The SetCueBanner banner function is now working.