How to implement Outlook Express alike address field control - c++

I was thinking about inserting some object (button, panel or static text) into textctrl, like Outlook Express does this.
You can see from a pic "group1" is an object, you can double click on it, when you delete it, it gets deleted the whole text not just a part of it.
I made some research and this text field is just a simple RichEdit20W. I understand that I can do it by implementing some logic to a text field and so on, but it will not be proper way of doing it.
I wonder how they done that. Should I implement IRichEditOleCallback interface to achieve that? I will appreciate your answer very much.
Thanks!

The ability to insert an object is built-in to the RichEdit control, that's what Outlook is using, and you can do the same yourself. It seems you would need to implement your own OLE object for your own item, and then use the RichEdit's COM interface to insert it. You can see a sample on MSDN that gets the COM interface and inserts an object here.

Related

How can I sort Items in `CListCtrl` when the button is clicked?

How can I sort Items in CListCtrl when the button is clicked?
I made a Dialog based application in MFC.
I put CListCtrl control on my Dialog and set its view style to report type.
I have two columns in this list view.
In here when I clicked the "Sorting" button, it should sort item in the list.
I saw many examples related to this, but none is working for me.
Can some one guide me how to do that?
I assume that you mean the column header when you write "sorting button".
You probably forgot to put this into the message map of your dialog:
ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST1, OnColumnclickList1)
IDC_LIST1 is the id of the list control which may be different in your code.
Are you somewhat familiar with MFC ? If not, you should follow one of the numerous tutorials available on the net.
I would use a CMFCListCtrl. It is easier, as it as built in sorting functionality and you only have to provide a function with the comparing items algorithm for sorting. I have succeeded using it. You have to override the OnCompareItems on your class derived from CMFCListCtrl. I also recommend you to do a call to EnableMarkSortedColumn(); after your list is created.
The CListCtrl has a SortItems method.
All you need to do is provide your Compare function to it as the parameter.
I don't know much about the contents of your list control so I can't really give you more information.
Please read up on it and extend your question with example code and details of which column needs to be sorted and I can help more.
If the contents of your cells are just text then I usually just return the value of:
return Value1.CollateNoCase(Value2);
There are also lots of tutorials on the Internet. For example:
http://www.codeproject.com/Articles/27774/CListCtrl-and-sorting-rows
In fact, that tutorial suggests us in SortItemsEx. That is what I would use.

How to paste information into filtered CHeaderCtrl

We have an MFC application that uses the CHeaderCtrl and have been using the HDS_FILTERBAR style to filter data. Works great. But our users want to be able to paste in text into the filter cell. I have not found a way to get a pointer to any CEdit-type of control here so that I can call >Paste. I have managed to detect a Control-V while in the filter in the application's ::PreTranslateMessage. There is a way to send text to the filter by way of a CHeaderCtrl->SetItem call, but this will immediately launch the filter. I just want to be able to paste text.
So...I tried (I was desperate) using keybd_event and SendInput to force keystrokes. This worked but had undesirable side effects, probably due to MFC's message handling, and in my case, the user already had the Control + V pressed down. But in just sending the letter 'A', and forcing the SHIFT key, I accidently discovered that the CHeaderCtrl's filter does support a paste if you:
CONTROL + SHIFT + V
The problem is its hard to do, and hard to tell my users to do this.
I can simulate this sequence using keybd_event, but again, its real quirky.
Can anyone find a way to either get access to the CEdit (if there even is one) to a filtered CHeaderCtrl or know of another workaround ? I tried using a spy utility, but was not sure what to look for. Sorry for the long post.
So remove Ctrl+V from the accelerator list and you can handle it inside the control...
(Answer added according to the comment).

How can I visually design a component in C++ Builder?

I have been away from C++ for a couple of years now doing AS3/Flex work. I have gotten used to being able to create a component and place it in design mode with very little fuss and I am struggling to get my head around the C++ Builder way of doing the same thing.
I have written many components for C++ Builder in the past, but none of them have been visual. What I would like to do now is create a component for customer search and another for order processing because I want to be able to create a new instance of these on the fly. What I don't want to do is have to place each of the components like the dbgrid and search fields manually in code. I would like to do this (as well as set their properties) in design mode.
How do I go about this? I have browsed the source for other Delphi components and I notice they have dfm files which seems to be what I need. How do I do this in C++ Builder? The only option I see is to add a new form if I want a dfm, but this isn't what I want as my components will be based on TPanel.
Is there a way to do this or do I have to resort to doing it all in code with no visual reference?
Pursuing the DFM idea I did a test this morning where I created a component based on TPanel and added a new form to it which I create and parent in the constructor of the component. In design mode I set the form border to none and placed a grid on it. This all looks OK until I place the component in my application, at that point it looks like a panel with a standard looking form in it and the grid is missing. If I run the app the panel shows as expected, borderless and with a grid. The DFM appears to be ignored in design mode for some reason.
If you know a better way to do this than using components then please give me some pointers.
Any help and advice will be appreciated beyond words
You might want to have a look at frames (look for "Frame objects"). They are "subforms" you can design visually and then place on forms.
Just as an FYI item, you can also drop the panel on a form, put any other controls on it, position them, set captions, etc..
Now, click the panel to select it, and use Component->Create Component Template from the IDE's main menu. This creates a unit you can install as a component which will add the panel and it's sub-controls (as a single component) to the IDE's component palette.
Of course, you can then modify the source for that new component like any other component source.

How to extend listControl class in C++ and add new functions?

Hi I need to extend the CListControl class in C++/MFC, which will add several new features in the list control,
Any one have good sample code ?
Or could you please tell me how can i start it ?
Thanks in advance!
Or just write the new features and listControl into a ActiveX or COM ??
Which is better ?
TO add functionality such as you suggest in your comments above I wouldn't even make a derivation of CListCtrl. It would make more sense, IMO, to create a CListCtrlManager class that handles things such as you suggest and then handles populating an associated CListCtrl.
Thing is if you wish to derive from a CListCtrl then it is USUALLY done for handling owner draw. There is very little functionality that REQUIRES a derivation. For example I have a derived list ctrl that provides row colouring based on certain information as well as a checkbox in the list view. To handle that I had to set the owener draw flag and handle list ctrl drawing directly, but you do not need to make a derivation to handle the functionality you desire.

Win32Api - Window Name Property

Is there any way to get a control's name through win32api? (c++)
I'm talking about the property that in C# is 'Name', like 'frmMain', or 'btnNext'.
Is there any way to retrieve this data through the win32API?
I've tried GetWindowInfo() and stuff but I think I'm not heading in the right direction..
thanks
edit: I'm iterating with EnumChildWindows() and I got the correct HWND.. not sure if I can use it to print it's name.. (im a c++/win32 absolute noob)
Added 7/10/09
By the way I found this really good tool to operate win32 apps.
http://www.autoitscript.com/autoit3/
Check it out looks good and looks like it's freeware? :)
The name of a control is usually a private variable of the control and is not exposed to win32. You could try GetWindowText to get the title of some controls or GetWindowLong to get some properties, but I don't think you can get the name of most controls.
I seriously doubt that this information is even in the executable code, I would think that from the c# compilers point of view these symbols get reduced to object pointers or window identifiers values (the IDC_ mentioned above).
Having been faced with this type of problem before I chose to create hidden static text controls with identifying text on each window to provide this named window capability to an external process. Not very elegant but solved my problem at the time.
The name property is something added, AFAIK, by the compiler. Win32 does not, inttrinsicaly, support naming like this.
In C/C++ one uses the IDC_* value instead with the added bonus that integer comparisons are far faster than string comparison.
Edit: Btw Its possible to use the IDC values mentioned above to get child controls of a dialog by using the GetDlgItemInt( hDlgWnd, IDC_* ) to get an HWND to the control. Far easier then using EnumWindows ....