Free Source Code and Program Tips
Posts tagged Win32/MFC
How to get ClistCtrl item text of another process
Sep 24th
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
Simple CEdit Validation
Jun 27th
Sometime you need some CEdit Validation, for example, restricting the data number only. The simple implemetion is to handle the EN_UPDATE notification message. The EN_UPDATE message is useful to handle as it caters for both normal entry and clipboard paste. You can do that in the Dialog or subclass the CEdit class. Here is an
How to translate among CString,string and char array
Jun 22nd
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 check whether the window is in minimise or Maximise mode
Mar 21st
CWnd::IsIconic BOOL IsIconic( ) const; Return Value Nonzero if CWnd is minimized; otherwise 0. Remarks Specifies whether CWnd is minimized (iconic). Example // This code, normally emitted by the AppWizard for a dialog-based // project for the dialog’s WM_PAINT handler, runs only if the // window is iconic. The window erase the icon’s area, then
sscanf with CString
Mar 20th
Problem: In the C time, we used to use sscanf to read data from string as following: char strUserName[20], strPassword[20]; // if the content of m_recvBuff is “Microsoft Bill”. sscanf((const char *)m_recvBuff, “%s %s”, strUserName, strPassword); And when you first get CString in sight, you may write the similar code: CString strUserName, strPassword; // if the
How to Draw Bitmap from a bmp File?
Jan 4th
How to load a bitmap from bmp file and draw it in DC? There are two main steps: Load the bitmap from the file to a memory DC. Paint the content of the memory DC to the one which display the bitmap. In MFC, there is no API to load a bitmap directly from a
Simple code to create an EMF or Bitmap file from existed draw code
Dec 16th
We often need to create an Enhanced Meta File(EMF) or Bitmap(bmp) from an existed DC draw code. It’s not very difficult but it’s boring to code again and again. The following is a simple solution, what you need to do is only to implement an IPicDrawer and call DrawEnhMeta or DrawBitmap function.
How to change the row height of CListCtrl
Dec 5th
When you want to change the height of CListCtrl, you need to use an owner-draw version of CListCtrl and change the font of the control. But when you change the font of the CListCtrl, the control or its parent window does not get a chance to respecify the height of the rows and the effect will not be
Moving selection of CListCtrl
Dec 3rd
tag: CListCtrl, SetItemState, SetSelectionMark When you try to move the item selection of a CListCtrl object, you should remember to call SetSelectionMark. If not, the program will not work as you think. It will only work once and won’t work any longer. The reason is that even you have called SetItemState and the selection was