Code Library

Free Source Code, Program Tips and Technology Documents

How to get ClistCtrl item text of another process

Question:
In some app like WinSpy/Spy++ to make adjustments to list controls. It can correctly set an app’s list control’s modes, alignments, sorting, styles, and extended styles. It can also get the widths of the columns and count of items.
The problem is that you cannot seem to get the columns’ names or [...]

How to subclass CTreeCtrl in CTreeView?

Another title:
How to use a derived CTreeCtrl in a CTreeView?
It is similar with this article: “How to use an derived CListCtrl in CListView” or “How do I subclass the CListCtrl part of a CListView Class?“.
Just like CListView, there is no CTreeCtrl to subclass in CTreeView. The CTreeView is the subclass of the WC_TREEVIEW common control. [...]

How to send/post message to CDocument?

Sometime you need to send/post message to CDoumnet, but CDocument is not a window, and it can’t receive message. How do that?
There are 3 solutions:
Solution 1: Send the message to the main window.
Send/Post the message to the main frame or the view, and then call some functions of the document.
But if in a MDI [...]

How to sort items of CListCtrl or CListView?

How to sort the items of a CListCtrl or CListView(CReportView)?
First, when you add items, you need to call SetItemData to attach an data structure(an integer or a pointer) to the item.
Then, define a callback sort function.
int CALLBACK SortFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
And here, the prarameters lParam1 and lParam2 are the data structure you [...]

Set the head backgroud color of CPropertyPage

How to set the head backgroud color of CPropertyPage?
In the DrawItem function the TextOut position is pretty half-hearted, and looks a bit better (to my eyes) if you do it something like this instead.

void CMyTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
CDC* pDC = CDC::FromHandle(lpDIS->hDC);
[...]

How to translate among CString,string and char array

In MFC program, you’d better try to avoid using std::string. There is no compelling reason to use it in MFC, and it leads to confusion.
There are some standard method to translate among Cstring ,string and char[].

// Suppose
CString str;
std::string s;
char buf[SIZE];
// from CString to std::string
s = str;
// from std::string to CString
str = s.c_str();
// to char[]
_tcscpy(buf, [...]