|
i need checking, bot building.
includeh10
|
|
|
|
|
|
It's really not MFC that have it, it just use some of the CRT debugging functions
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
You can hook memory allocations in the runtime library via something like the following (I pulled this out of some software of mine):
FILE *_AllocHookFile = NULL;
bool _AllocHookFileClose = false;
void _AllocHookInitialize()
{
_AllocHookFile = fopen("AllocHook.Log","w");
_CrtSetAllocHook(_AllocHook);
}
void _AllocHookTerminate()
{
_AllocHookFileClose = true;
if (_AllocHookFile != NULL) {
fclose(_AllocHookFile);
_AllocHookFile = NULL;
}
}
int _AllocHook(int allocType,
void *userData,
size_t size,
int blockType,
long requestNumber,
const unsigned char *filename,
int lineNumber)
{
if (requestNumber == 87) DebugBreak();
if (blockType == _CRT_BLOCK) return TRUE;
if (_AllocHookFileClose) return TRUE;
long _request = requestNumber;
char _allocType = '?';
char _blockType = '?';
int _size = size;
char *_filename = (char *)filename;
int _line = lineNumber;
switch (allocType) {
case _HOOK_ALLOC: _allocType = 'A'; break;
case _HOOK_REALLOC: _allocType = 'R'; break;
case _HOOK_FREE: _allocType = 'F'; break;
}
switch (blockType) {
case _FREE_BLOCK: _blockType = 'F'; break;
case _NORMAL_BLOCK: _blockType = 'N'; break;
case _IGNORE_BLOCK: _blockType = 'I'; break;
case _CLIENT_BLOCK: _blockType = 'C'; break;
}
if (allocType == _HOOK_FREE) {
if (_size == 0) {
_size = _msize_dbg(userData,blockType);
}
if (userData != NULL) {
typedef struct _CrtMemBlockHeader
{
struct _CrtMemBlockHeader *pBlockHeaderNext;
struct _CrtMemBlockHeader *pBlockHeaderPrev;
char *szFileName;
int nLine;
size_t nDataSize;
int nBlockUse;
long lRequest;
unsigned char gap[4];
} _CrtMemBlockHeader;
_CrtMemBlockHeader *header = (((_CrtMemBlockHeader *)userData)-1);
if (_filename == NULL) {
_filename = header->szFileName;
}
if (_line == 0) {
_line = header->nLine;
}
if (_request == 0) {
_request = header->lRequest;
}
}
}
fprintf(_AllocHookFile,"%10d %10d %c %c %s;%d\n",
_request,_size,_allocType,_blockType,_filename,_line);
return TRUE;
}
The initialize function opens a file where allocations are logged and sets the allocation hook, and the terminate function closes it. The hook function gets called on each heap operation. You can look at the resulting log file to see where things are allocated and deallocated.
Software Zen: delete this;
|
|
|
|
|
I have a nice mfc control and want to use this control under WinCE (PocketPC).
So the problem is that the control uses very often the following functions
CDC::SetTextAlign(...);
CDC::TextOut(...);
and this 2 functions are not supported under WinCE.
I know I can write CDC::ExtTextOut(...); or CDC::DrawText(...); instead of CDC::TextOut(...); , but I have to recalc all the positions where to plot the text, because the CDC::SetTextAlign(...); function is not supported by WinCE.
Is it possible to write this two functions, so that I don't need to recalc all the positions!
Or any other idea?
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
I am using VC++ 7.0, with a simple wizard generated MDI applictaion, and I am reporting the warning LNK4089: 'all references to oledlg.dll will be cancelled by /OPT:REF' (as i have this option enabled). The application itself works fine but the documentation suggests to cut all the references to unnecessary dlls. I have carefully browsed the project settings dialog but couldn't find an option to get this result.
any info/tip will be greatly appreciated
Thanks in advance
|
|
|
|
|
Remove oledlg from the list of libraries under the link options (input). This is a message that can basically be ignored. I wouldn't worry about it.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Why does this piece of code create a totally frozen window?
It paints(once?), but can't be moved, resized or clicked on
It seems to work for the first time after I-don't-know-what(Worked once this morning, never again. Last night didn't work. Haven't restarted)
<br />
#define IB_BACKGROUND BLACK_BRUSH<br />
#define IB_TILESET_ID 5141 // <- Should this be some number that means anything? I am not sure what it is needed for<br />
<br />
<br />
if (!m_wndTileset.Create(AfxRegisterWndClass(CS_VREDRAW | CS_HREDRAW, 0,<br />
(HBRUSH)::GetStockObject(IB_BACKGROUND), 0), "Tileset", WS_VISIBLE | WS_CAPTION<br />
| WS_SIZEBOX, theApp.m_lastTilesetRect, this, IB_TILESET_ID))<br />
{<br />
TRACE0("Failed to create tileset window\n");<br />
return -1;<br />
}
I am doing this in CMainFrame::OnCreate
m_wndTileset is a CWnd derived class without any real modifications yet.
|
|
|
|
|
do u use loop, i.e. while(), for() somewhere? if yes, check them first.
includeh10
|
|
|
|
|
Nope. I don't do absolutely anything with that window besides creating it and updating the theApp.m_lastTilesetRect on move & size. No loops in that either.
|
|
|
|
|
i wrote a program which borrow some mfc class, when i let my view derive from CWnd, it runs OK, but when i let it derive from CHtmlView, it crashed. anybody knows why, the code is below:
//StdAfx.h
#include <afxwin.h>
#include <afxext.h>
#include <afxcmn.h>
#include <afxhtml.h>
//StdAfx.cpp
#include "StdAfx.h"
//MainFrm.h
#include "SimpleHtmlView.h"
class CMainFrame : public CFrameWnd
{
protected:
DECLARE_DYNCREATE(CMainFrame)
// Constructor & Destructor
public:
CMainFrame();
virtual ~CMainFrame();
// Attributes
protected:
CStatusBar m_wndStatusBar;
CSimpleHtmlView m_wndView;
// Methods
public:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
DECLARE_MESSAGE_MAP()
};
//MainFrm.cpp
#include "StdAfx.h"
#include "SimpleHtml.h"
#include "MainFrm.h"
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR,
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
CMainFrame::CMainFrame()
{}
CMainFrame::~CMainFrame()
{}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
cs.dwExStyle = 0;
cs.lpszClass = AfxRegisterWndClass(0, 0, 0, ::LoadIcon(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDR_MAINFRAME)));
return TRUE;
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
//Register the windows class for its creation
if ( CFrameWnd::OnCreate(lpCreateStruct) == -1 )
return -1;
if ( !m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators) / sizeof(UINT)) )
{
TRACE0("Failed to create status bar\n");
return -1;
}
if ( !m_wndView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL) )
{
TRACE0("Failed to create view window\n");
return -1;
}
return TRUE;
}
//SimpleHtml.h
#include "Resource.h"
class CSimpleHtmlApp : public CWinApp
{
// Constructor & Destructor
public:
CSimpleHtmlApp();
virtual ~CSimpleHtmlApp();
// Methods
virtual BOOL InitInstance();
protected:
afx_msg void OnAppAbout();
DECLARE_MESSAGE_MAP();
};
//SimpleHtml.cpp
#include "StdAfx.h"
#include "SimpleHtml.h"
#include "MainFrm.h"
BEGIN_MESSAGE_MAP(CSimpleHtmlApp, CWinApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
END_MESSAGE_MAP()
CSimpleHtmlApp theApp;
CSimpleHtmlApp::CSimpleHtmlApp()
{}
CSimpleHtmlApp::~CSimpleHtmlApp()
{}
BOOL CSimpleHtmlApp::InitInstance()
{
CMainFrame* pMainFrame = new CMainFrame();
if( !pMainFrame->LoadFrame(IDR_MAINFRAME) )
return FALSE;
m_pMainWnd = pMainFrame;
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
return TRUE;
}
void CSimpleHtmlApp::OnAppAbout()
{
CDialog aboutDlg(IDD_ABOUTBOX);
aboutDlg.DoModal();
}
//SimpleHtmlView.h
class CSimpleHtmlView : public CHtmlView
{
protected:
DECLARE_DYNCREATE(CSimpleHtmlView)
// Construction & Destructor
public:
CSimpleHtmlView();
virtual ~CSimpleHtmlView();
// Methods
public:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
DECLARE_MESSAGE_MAP()
};
//SimpleHtmlView.cpp
#include "StdAfx.h"
#include "SimpleHtml.h"
#include "SimpleHtmlView.h"
IMPLEMENT_DYNCREATE(CSimpleHtmlView, CHtmlView)
BEGIN_MESSAGE_MAP(CSimpleHtmlView, CHtmlView)
//{{AFX_MSG_MAP(CSimpleHtmlView)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CSimpleHtmlView::CSimpleHtmlView()
{}
CSimpleHtmlView::~CSimpleHtmlView()
{}
BOOL CSimpleHtmlView::PreCreateWindow(CREATESTRUCT& cs)
{
return CHtmlView::PreCreateWindow(cs);
}
thank you very much
|
|
|
|
|
I'm taking a wild guess here but I believe this article might help you out:
http://www.microsoft.com/msj/0100/c++/c++0100.asp
-------------
-= Nasty_p =-
|
|
|
|
|
HideCaret(hwndEdit) function was just what I was looking for...The problem of the text still being selected still remains. Also if I double click on the edit box select some text and then move around the mouse then the whole thing just gets distorted...Am I doing the right thing by using and edit control to display a text file. Is there another more efficient approach to this matter?
|
|
|
|
|
i may offer some advices but what is u really want?
an edit control on dialog box with read-only (not by style), no selection etc?
includeh10
|
|
|
|
|
Yes, that's exactly what I want. I want basically a control on a dialog which looks and behaves like a list box which does not allow selections. So I figure the edit box is the best way to go about this. From the resource editor I chose multiline/vscroll/read-only. Displays the text file just fine except for when it starts up where everthing is highlighted. The only other problem is that if you start dragging the mouse all over the control then the text gets distorted...maybe I should process mouse messages? So basically that's it. The main problem them is the the text being selected. The HideCaret() function was very nice. Thanks for your help.
|
|
|
|
|
basic solution needs 1 second.
if u have more than 2 controls on dialog, extra one may be any except CStatic. goto resource edit, from menu tool(?) then select TAB order, change the edit control not as first. that is all.
but the edit is light-gray. for high level solution, u need to override the edit to handle message.
includeh10
|
|
|
|
|
That was a great idead, even though my dialog is filled up by just one huge edit control. But I made one more, put it behind the main one, made it invisible and gave it a TAB Stop of 1. Than I subclassed the edit control so as to not be able to accept WM_LBUTTONDOWN messages and that was all. Now the caret doesn't show and most importantly the text is NEVER highlighted. Maybe this isn't the best way to go about things but if it works...why not...thanks so much for your time.
|
|
|
|
|
hi,
the usage of CCriticalSection, several threads try lock(), unlock() the CCriticalSection object.
i want to know whether the lock(), unlock() action be atomic operation.
i think it is not a atomic operation, right?
if so, does anyone know the mechanism inside object able to prevent any interrupt to the object during one thread locking/unlocking the object?
thanks,
jim
|
|
|
|
|
If it wasn't atomic what would be the point of it? The purpose of CCriticalSection is for thread synchronization, so I would guess that it would be an atomic operation to lock/unlock the object.
I would guess that the mechanisms in order to make that happen are done at the opreating system level, but other than that I have no clue.
- Anatari
|
|
|
|
|
Was wondering whether it is possible to view normal function names in a .c file in the Workspace pane.
The function is not a class.
Codewright has this feature.
Thanks.
|
|
|
|
|
You have them, under the "Global" folder.
Back to real work : D-21.
|
|
|
|
|
I just opened the *.c file without loading any *.dsp or *.dsw.
Any pointers how to load the global folder?
Thanks.
|
|
|
|
|
I have a property sheet. Before I changed anything, the default push button used to be the OK button.
Then I added three pushbutton controls the the property page. Now the first button I added has become the default pushbutton. In the UI, "Default Pushbutton" is not checked, however, running Spy++ confirms that this button is indeed being set to be the default pushbutton.
Why is that? How does MFC select which button it will use as the default? How do I change it back so that the OK button is the default?
Jon Sagara
If you think of wheat fields as questionable metaphors, you can think of me as the state of Kansas.
-- Mike Blaszczak
|
|
|
|
|
Thats strange, because I had the exact opposite experience. I had to override several functions before I could get it to stop being the default button. You can try this tho:
In your CPropertyPage derived class override the OnInitDialog() function. Then include something like this in it:
<br />
BOOL CYourClass::OnInitDialog() {<br />
BOOL nRet = CPropertyPage::OnInitDialog();
SetDefID(IDOK);
return nRet;<br />
}<br />
I think it will work else where in your code too. Like in response to an update UI message would be a good place i think.
- Anatari
|
|
|
|
|
Would anyone tell me whether i can use CArray and CTypePtrList toghether? Are they conflicted to each other in Serialize function?
Thanks
|
|
|
|