|
You don't need to make the edit-box to be read-only. You only have to manage the WM_KEYDOWN message, like this:
BOOL CTestDlg::PreTranslateMessage( MSG *pMsg )
{
if ( pMsg -> message == WM_KEYDOWN )
{
CEdit *p = (CEdit *) GetDlgItem( IDC_Readme );
if ( GetFocus( ) == p )
return TRUE;
}
return CDialog::PreTranslateMessage( pMsg );
} I don't know what is the name of your application's main dialog class. In my example it's CTestDlg. Don't forget to declare this overriden function in that class.
Good luck!
|
|
|
|
|
|
Handle the WM_CTLCOLORSTATIC message.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
FredrickNorge wrote: If i set the readonly parameter, it is exactly the way i want it, except its color background is greyed, i want the white.
Hanle OnCtlColr message and repaint the ctrl with white color
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
Hi!
I have created a very simple project called Test in Microsoft Visual Studio 2005 of type Win32 Console Application, using MFC,which looks like this:
#include "stdafx.h"
#include "Test.h"
#define _CRTDBG_MAP_ALLOC
#include "stdlib.h"
#include "crtdbg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
_CrtDumpMemoryLeaks( );
return nRetCode;
} After compiling and executing it in Debug mode, in the Output window of the IDE appeared this information:
'Test.exe': Loaded 'E:\Test\debug\Test.exe', Symbols loaded.
'Test.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', No symbols loaded.
'Test.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', No symbols loaded.
'Test.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugMFC_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_c8452471\mfc80ud.dll', Symbols loaded.
'Test.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c\msvcr80d.dll', Symbols loaded.
'Test.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll', No symbols loaded.
'Test.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll', No symbols loaded.
'Test.exe': Loaded 'C:\WINDOWS\system32\user32.dll', No symbols loaded.
'Test.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll', No symbols loaded.
'Test.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', No symbols loaded.
'Test.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', No symbols loaded.
'Test.exe': Loaded 'C:\WINDOWS\system32\oleaut32.dll', No symbols loaded.
'Test.exe': Loaded 'C:\WINDOWS\system32\ole32.dll', No symbols loaded.
'Test.exe': Loaded 'C:\WINDOWS\system32\sockspy.dll', Binary was not built with debug information.
'Test.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.MFCLOC_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_3415f6d0\mfc80ENU.dll', Binary was not built with debug information.
Detected memory leaks!
Dumping objects ->
{61} client block at 0x003A3298, subtype c0, 64 bytes long.
a CDynLinkLibrary object at $003A3298, 64 bytes long
Object dump complete.
The program '[2164] Test.exe: Native' has exited with code 0 (0x0). As you can see, I haven't allocated any memory on the heap. The only pieces of code added by me were #define _CRTDBG_MAP_ALLOC, the include lines for stdlib.h, crtdbg.h and the call of _CrtDumpMemoryLeaks, in order to be able to see if there are any memory leaks.
In MSDN, they say that a client block is a special type of memory block used by MFC programs for objects that require a destructor.
In my opinion, no matter how hard someone tries to create an application which correctly allocates and deallocates the heap memory, that application would still have a memory leak of 64 bytes. Is this a bug in Microsoft Visual Studio 2005? Because I really don't think I'm the one responsible for deallocating those 64 bytes of memory. (Moreover, when I create an empty project (with no MFC), no memory leak is detected. I guess the call of AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0) is responsible for this trouble)
Any help will be greatly appreciated!
Thanks in advance!
|
|
|
|
|
For an MFC app, you don't need a _tmain() entry point. Use the CWinApp::InitInstance() and
CWinApp::ExitInstance() overrides for initialization and cleanup.
If you absolutely MUST have your own entry point then you'll need to look at the source code for
MFC's entry-point implementation and make sure you are covering all initialization and cleanup.
If the only reason you need to override the entry point is to check for memory leaks then
you can use a static object like your CWinApp object. I use this in my app module:
#ifdef _DEBUG
class _MemStateCheck
{
public:
CMemoryState oldMemState, newMemState, diffMemState;
_MemStateCheck();
~_MemStateCheck();
};
_MemStateCheck::_MemStateCheck()
{
oldMemState.Checkpoint();
}
_MemStateCheck::~_MemStateCheck()
{
newMemState.Checkpoint();
if( diffMemState.Difference( oldMemState, newMemState ) )
{
TRACE( "************************\n" );
TRACE( "Memory leaks Detected\n" );
TRACE( "************************\n" );
diffMemState.DumpStatistics();
diffMemState.DumpAllObjectsSince();
}
else
{
TRACE( "************************\n" );
TRACE( "No memory leaks Detected\n" );
TRACE( "************************\n" );
}
}
_MemStateCheck MemCheckObj;
#endif //#ifdef _DEBUG
|
|
|
|
|
|
There is no problem creating an app like this. The memory leak is a side effect of the MFC dlls unloading and is on shutdown only (and is likely due to the restrictions on unloading DLLs, rather than MFC itself.) If you link statically, the leak will go away.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Thank you very much for the explanation and for the solution, at the same time!
|
|
|
|
|
I m working in VC++/MFC application now.
It is dialog a based one.
In text bow, i created the CString textBox control for giving 10 digit numeric values.
When i submit the application , i receive the Application Error like 'The Instruction at "0x6c3b7f98" referenced memory at "0x00000048".The memory could not be read.'
After i will send it to the server.
In server it is received as a String.I don't know what's the problem.
So, give the solution this proplem.
Thanks.
Govindarajan.B
|
|
|
|
|
The error message says it all. You have tried (probably unintentionally ) to read from an
adddress you are not allowed to read from.
If you run in the debugger you should be able to trace back to the offending code when the
exception occurs.
There's a bad pointer problem somewhere.
Mark
|
|
|
|
|
I have a CListCtrl (m_ListCtrlStyled) on a form (A CFormView based application, developed in VC 6.0 SP6).
I initiate the CListCtrl in the OnInitialUpdate() function like the following.
<br />
<br />
DWORD dwStyle = ::GetWindowLong(m_ListCtrlStyled.m_hWnd, GWL_STYLE); <br />
dwStyle &= ~(LVS_TYPEMASK);<br />
dwStyle &= ~(LVS_EDITLABELS);<br />
SetWindowLong(m_ListCtrlStyled.m_hWnd, GWL_STYLE, dwStyle| LVS_REPORT|LVS_NOLABELWRAP|LVS_SHOWSELALWAYS);<br />
<br />
DWORD styles = LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_CHECKBOXES;<br />
ListView_SetExtendedListViewStyleEx(m_ListCtrlStyled.m_hWnd, styles, styles );<br />
<br />
m_ListCtrlStyled.SetExtendedStyle( LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);<br />
<br />
<br />
TCHAR rgtsz[3][10] = {_T("SerialNumber"), _T("Doc"), _T("Score")};<br />
<br />
LV_COLUMN lvcolumn;<br />
CRect rect;<br />
m_ListCtrlStyled.GetWindowRect(&rect);<br />
for(int i=0;i<3;i++)<br />
{<br />
lvcolumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH | LVCF_ORDER;<br />
lvcolumn.fmt = LVCFMT_LEFT;
lvcolumn.pszText = rgtsz[i];<br />
lvcolumn.iSubItem = i;<br />
lvcolumn.iOrder = i;<br />
switch (i)<br />
{<br />
case 0 :<br />
lvcolumn.cx = rect.Width()*1/10 ;
break;<br />
case 1:<br />
lvcolumn.cx = rect.Width()*7/10 ;
break;<br />
case 2:<br />
lvcolumn.cx = rect.Width()*2/10 ;
break;<br />
}<br />
<br />
m_ListCtrlStyled.InsertColumn(i, &lvcolumn);<br />
}<br />
<br />
CFont m_font;<br />
<br />
m_font.CreateFont(16, 0,0,0,FW_REGULAR, 0,0,0, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Courier"); <br />
<br />
<br />
<br />
m_ListCtrlStyled.SetFont(&m_font);<br />
<br />
m_ListCtrlStyled.SetBkColor(RGB(247,247,255)); <br />
m_ListCtrlStyled.SetTextBkColor(RGB(247,247,255));<br />
<br />
<br />
The problem is that there was no change of the font when I change "arial" of m_font to other font name, say "courier".
i also tried with the following code , but failed again.
<br />
CWnd *pWnd=GetDlgItem(IDC_LIST2);<br />
CDC *pDC=pWnd->GetDC();<br />
CFont font;<br />
LOGFONT stFont;<br />
memset(&stFont,0,sizeof(LOGFONT));<br />
stFont.lfHeight=MulDiv(12,pDC->GetDeviceCaps(LOGPIXELSY),72); <br />
stFont.lfWeight=FW_NORMAL;<br />
stFont.lfCharSet=GB2312_CHARSET;<br />
strcpy(stFont.lfFaceName,"Arial");
font.CreateFontIndirect(&stFont);<br />
<br />
pWnd->SetFont(&font,TRUE);<br />
<br />
Please help me my friends
-- modified at 3:51 Saturday 2nd December, 2006
|
|
|
|
|
Isn`t UpdateData() needed here? Sorry if I`m wrong
|
|
|
|
|
Hi, Makakuin,
Makakuin wrote: Isn`t UpdateData() needed here? Sorry if I`m wrong
What do you mean. I did not use UpdateData in the my code.
|
|
|
|
|
Try to call UpdateData() right after all changes you need to make to ListCtrl as UpdateData really does "Update data"... This might help..
|
|
|
|
|
Is your CFont object going out of scope before any text is actually displayed?
Try making "CFont m_font;" a member variable instead of a local variable.
Mark
|
|
|
|
|
By the way gtsz[3][10] is too small. It should be gtsz[3][13]. (The strings really shouldn't be hard coded, but I assume this is a test app.)
And the problem as indicated above is that m_font is local and the font handle is being deleted. (The list control is robust enough that it recovers from this error.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
finaly, i found the answer, i should have declare m_font as a class member variable instead of a local variable, since i initiate the CListCtrl in OnInitialUpdate() and use it in another function. A local variable will go out of scope.
|
|
|
|
|
Hi
How can I change(set) the background color of my dialog box?
Thanks in advance
Taruni
|
|
|
|
|
Use SetDialogBkColor()
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
You should handle the WM_CTLCOLOR message.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hi All,
I need to know how to set a default value in Combo Box. For example, right now I have a combo box with 3 times in it (Train, Bus, Both). I need to set "BOTH" as a default value in the combo box.
Thanks in advance
C++Prog
|
|
|
|
|
You can send the combobox a CB_SETCURSEL message (CComboBox::SetCurSel() in MFC).
Mark
|
|
|
|
|
Thanks a lot
Can I do it in 'Combo Box properties dialog'..or need to write a code for it?
C++Prog
|
|
|
|
|
Only at runtime, anytime after the Windows object (HWND) is created.
In response to the WM_INITDIALOG message is a good place
Mark
|
|
|
|
|