Free Source Code and Program Tips
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 app, it does not work, because the routing becomes too complex. Typically, you can send message to a view, but that has risks if there are multiple views on the same document and the one you post message to has been closed.
Solution 2: Use WM_COMMAND message.
A document can’t recerive a message, but it can recerives the commands through MFC’s command mechanism. Then you can use ::PostMessage to post WM_COMMAND message, and repose it in the document.
Solution 3:
Create an invisible top-level window in the CDocument, that represents its message sink. You send/post message to it. Thus will eliminate the complex route policy between the main frame and the views and you don’t worry about the view closing.
| Print article | This entry was posted by support on October 24, 2007 at 1:46 pm, and is filed under General. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
No trackbacks yet.
How to get ClistCtrl item text of another process
about 1 year ago - No comments
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 the item
How to catch the events when click on the app icon on taskbar
about 1 year ago - No comments
How to catch the events when you click on the application’s icon on the taskbar? It’s the WM_NC class messages. For example, you can handle the WM_NCLBUTTONDBLCLK message. And you can alse reponsible the WM_SYSCOMMAND messages. In particular, the special cases of SC_MINIMIZE and SC_MAXIMIZE are what are called from the system menu, which is
How to subclass CTreeCtrl in CTreeView?
about 2 years ago - No comments
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
How to sort items of CListCtrl or CListView?
about 2 years ago - No comments
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
Set the head backgroud color of CPropertyPage
about 2 years ago - No comments
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); CRect rc(lpDIS->rcItem); TCHAR szTabText[255]; TC_ITEM tci; tci.cchTextMax = sizeof(szTabText)-1; tci.pszText = szTabText;
Intermittent work in UI thread
about 2 years ago - No comments
Pedro Ferreira I’m trying to create a UI thread to do constant background work, but I’m having some design problems. The thread needs to fetch records from a database. do some processing on each record and, when there are no more records, sleep for 1 minute before check the database again. The process will be
Intermittent work in UI thread
about 2 years ago - No comments
Pedro Ferreira said: I’m trying to create a UI thread to do constant background work, but I’m having some design problems. The thread needs to fetch records from a database. do some processing on each record and, when there are no more records, sleep for 1 minute before check the database again. The process will
How to translate among CString,string and char array
about 3 years ago - No comments
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
How to hook the file related event
about 3 years ago - No comments
How to hook the file related event? It depends on what you need to do when such an event takes places. If what you just want to be notified, FindFirstChangeNotification and ReadDirectoryChanges are enough. If you need to intercept adn affect the operation somehow, I have heard it can be done with a kenerl-level driver(Filesystem
How to read sectors of a physical drive under Win32?
about 3 years ago - No comments
How to read the sectors of physical drive under win32? The API ReadFile is most useful function, and with it, you can read the physical sectors directly. Here is a sample function, BOOL ReadSectors(…) BOOL ReadSectors( BYTE bDrive, //drive index DWORD dwStartSector, //start sector WORD wSectors, //sectors number LPBYTE lpSectBuff) {  if (bDrive == 0)
about 1 year ago
Hello webmaster
I would like to share with you a link to your site
write me here preonrelt@mail.ru
about 1 year ago
Can you give an example as to where to create the hidden window and proving the syntax on the Create function because I cannot do this ?