String Conversion is often used in VC programming. It can be said that string conversion is a headache for beginners and even veterans of VC. In the multi-byte environment, that is, in the ASCII environment, the following code can be used to convert Cstring to char:
CString strXcoord; GetDlgItemText (IDC_EDIT_XCOORD, strXcoord); CString strYcoord; GetDlgItemText (IDC_EDIT_YCOORD, strYcoord); if (strXcoord. isEmpty () | strYcoord. isEmpty () {AfxMessageBox (TEXT ("X and Y coordinates must be specified");} USES_CONVERSION; char * col = T2A (strXcoord. getBuffer (0); char * row = T2A (strYcoord. getBuffer (0); CString strXcoord; GetDlgItemText (IDC_EDIT_XCOORD, strXcoord); CString strYcoord; GetDlgItemText (IDC_EDIT_YCOORD, strYcoord); if (strXcoord. isEmpty () | strYcoord. isEmpty () {AfxMessageBox (TEXT ("X and Y coordinates must be specified");} USES_CONVERSION; char * col = T2A (strXcoord. getBuffer (0); char * row = T2A (strYcoord. getBuffer (0 ));
Oh, we also need strXcoord. ReleaseBuffer (); to prevent memory leakage.