| How to Convert COleVariant into CString |
CString strvalue;
COleVariant olevar;
olevar = "Lahore";
strvalue = olevar.bstrVal; |
| How to Convert CString to Char * (char
pointer) |
char *charBuffer = new char[1024];
CString strvalue = "Pakistan";
charBuffer = strvalue.GetBuffer(sizeof(charBuffer)); |
| How to Convert char Pointer to CString |
char * charvalue ="Lahore";
CString strvalue =charvalue; |
| How to append text to an edit control? |
void CClassName::AppendTextToEdit(CEdit& edit, LPCTSTR pszText)
{
int Length = edit.GetWindowTextLength();
edit.SetSel(Length, Length);
edit.ReplaceSel(pszText);
edit.LoneScroll(edit.GetLineCount()); //In case you are using multiline Edit
Control.
}
If you want to append text in multiline edit control . set its property
multiline =True;
and append \r\n in the text to whom you want to add like "abc\r\n"
|
| How to Browse Folder in MFC (Visual C++) |
BROWSEINFO bi;
memset(&bi, 0, sizeof(bi));
bi.hwndOwner = this->GetSafeHwnd();
bi.lpszTitle = _T("Choose Folder");
LPITEMIDLIST pIDL =::SHBrowseForFolder(&bi);
if(pIDL != NULL)
{
// Create a buffer to store the path, then get the path.
char buffer[_MAX_PATH] = {'\0'};
if(::SHGetPathFromIDList(pIDL, buffer) != 0)
{
this->txtPath=buffer;
UpdateData(FALSE);
} // free the item id list CoTaskMemFree(pIDL);
}
Download Source Code
|
|
Is there any function to minimize the window?
|
If you are using MFC: this->ShowWindow(SW_MINIMIZE);
If you are using Win32 API based application: ShowWindow(hWnd,SW_MINIMIZE); |
|
What are Guard bytes ? |
malloc_dbg calls malloc, but requests a few more bytes. These bytes are filled with
a predefined value. free_dbg then checks if these extra bytes still hold this value.
If they did, you probably wrote beyond the allocated memory (the VC Runtime prints
a diagnostic message to the debug output). Typical implementations add 4 bytes at
the end.
In this case, using free instead of _free_dbg is often not a problem, but depending
on the implementation, it might leak the guard bytes. But if an implementation adds
guard bytes *before* the memory provided to you (to detect underflows, which are
less common), using free instead of -free_dbg is likely to corrupt the heap.
|
|
How to change the background color of an Edit Box?
|
You can change the background color of an edit control in a dialog by handling the
WM_CTLCOLOR message in the dialog:
class MyDialog : public CDialog {
//...
COLORREF _BkgColor;
HBRUSH _BkgBrush;
};
BOOL MyDialog::OnInitDialog()
{
//...
_BkgColor = RGB(0,255,0);
_BkgBrush = ::CreateSolidBrush(_BkgColor);
}
HBRUSH MyDialog::OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor )
{
hbr = CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
if (pWnd()->GetDlgCtrlId() == IDC_MY_EDIT_CONTROL) {
pDC->SetBkColor(_BkgColor);
hbr = _BkgBrush;
}
return hbr;
}
In the OnInitDialog() handler for the dialog, we initialize the background color
value and create a brush in that color. The WM_CTLCOLOR handler is called OnCtlColor.
The edit control for which we want to change the color has the resource ID IDC_MY_EDIT_CONTROL.
We set the text background to our background color using SetBkColor(), and the overall
background for the control by returning the brush we created.
|
|
14 How to change attributes for a directory?
|
if (! SetFileAttributes("c:\\ResOrg",FILE_ATTRIBUTE_READONLY))
{
DWORD dwError = GetLastError();
}
|
|
How to Set root Folder in CFileDialog?
|
CFileDialog has a member m_ofn, which is an OPENFILENAME structure. In that structure,
you have to set the lpstrInitialDir variable to point to a string containg the folder
in question.
CFileDialog FileDialog(TRUE);
FileDialog.m_ofn.lpstrInitialDir ="C:\\MyDirectory";
FileDialog.DoModal(); |
| Pages 1 2 |