|
I am developing my first custom control, CNewEdit derived from CEdit, which will use a non-system font for display. I want to create the font and then call CWnd::SetFont() after the control's window has been created. I don't want to do this outside the CNewEdit class (by adding code to the dialog class that is containing my CNewEdit control).
My instinct is to provide a handler in CNewEdit for WM_CREATE. However, although Class Wizard allows me to define this message handler, I can't get execution to breakpoint inside CNewEdit::OnCreate(). The rest of the class is working as I have customised the background and text colours and these are ok.
I find it strange that if I add a handler for WM_DESTROY to CNewEdit I can breakpoint successfully in OnDestroy(). So why not OnCreate()?
Mark Jones
Software Engineer
Hampshire
UK
|
|
|
|
|
Is your function really CNewEdit::OnCreate()?
If so it is probably not being called. The WM_CREATE message calls.
CMyEdit::OnCreate(LPCREATESTRUCT lpCreateStruct);
I usually override the create function as shown below and add the functionality that I need. But both of the below functions are executed when created by the parent.
One other option is are you calling Create or letting teh creation in a dialog initialization call it? IF the last case it may be only calling the base class.
Header File
class CMyEdit : public CEdit
{
// Construction
public:
CMyEdit();
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyEdit)
public:
virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CMyEdit();
// Generated message map functions
protected:
//{{AFX_MSG(CMyEdit)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
C++ file
BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
//{{AFX_MSG_MAP(CMyEdit)
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyEdit message handlers
// Create Message Handler
int CMyEdit::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CEdit::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
return 0;
}
// Virtual Function Override.
BOOL CMyEdit::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
Michael A Barnhart
mabtech@swbell.net
|
|
|
|
|
Thanks for your reply, Michael.
In answer to your first question - I am using CNewEdit::OnCreate(LPCREATESTRUCT lpCreateStruct), I was trying to be brief in my post - my mistake. I have now overrided the:
virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
function but I still cannot breakpoint in this fn or the WM_CREATE handler.
I am using the CNewEdit object in a dialog, whose resource template I have designed in the resource editor. I dragged the standard CEdit control from the resource toolbar onto the dialog. I have looked in the .rc file and have found the resource is identified as a 'EDITTEXT' control - the same as for normal CEdit controls.
I have added a CNewEdit member variable to the dialog class using class wizard. I am not calling the Create function in my code. I think the creation of the window for the CNewEdit control occurs somewhere in CDialog::OnInitDialog().
Is there another mechanism brought into play when controls are created inside dialog boxes?
Mark Jones
Software Engineer
Hampshire
UK
|
|
|
|
|
Creation of window (HWND) for your CNewEdit control occurs before CDialog::OnInitDialog. By the time CDialog::OnInitDialog is called, all child windows defined in the dialog template are already created. CDialog::OnInitDialog calls DoDataExchange, and DoDataExchange associates your CNewEdit instance with some HWND. There's no chance for OnCreate in this scenario - the window is already created.
The function to override is CWnd::PreSubclassWindow.
Tomasz Sowinski
http://www.shooltz.com.pl
|
|
|
|
|
Thanks Tomasz, that's just what I was looking for.
Mark Jones
Software Engineer
Hampshire
UK
|
|
|
|
|
I have an app that will do print preview. The problem I have is that the buttons on the print preview toolbar is not updating. When the "Next Page" button is clicked, the next page is displayed but the "Prev Page" button remain disabled. When the "Two Page" button is clicked, two pages are displayed but the button does not update to "One Page". I am not deriving a Print Preview class, I'm using the default MFC's print preview. Any help or suggestions are greatly appreciated.
|
|
|
|
|
That was also my problem. But I solved it with an plugin named
AAA EasyGrid ActiveX. A really helpful ActiveX. You may visit
http://www.share2.com/easygrid/ for more details.
|
|
|
|
|
Let me go on the record to say that the MFC print preview blows. I recommend rolling your own, which is what I ended up doing. Today is my third 16 hour day trying to get printing done by the end of the week.
Otherwise, you'll find you can get the control being shown by enumerating child windows of the window. You may also be able to get it by ID. Either way, you could nose around the MFC source to get some ideas and then enable the button yourself.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
in my application i draw rectangles, using points in LButtonDown, MouseMove and
LButtonUp,
1) I don't want LButtonUp to happen outside of my view, How can i stop that?
2) My rectangles can be moved using arrow buttons, i want scrollers to appear if any point of
my rects are outside of the display area(if the window is small)
3) when i scroll the window, my objects ARE redrawn but they don't move with the window.
They stick to the same location. Do i need to do world to normalize to device? Need code
for that....
If you can answer any of the above questions it will be highly appreciated
thanks,
F.Dost
|
|
|
|
|
1) if the user releases the button outside your window, what should happen?
2) call SetScrollSizes with the size of your total window (including objects that have moved off the visible part).
3) GetScrollPos, then add the position to your drawing locations.
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
thank you for your respond....
1) i don't want cursor to go out of my window if it is pressed and is drawing cursor,
3) i can't change the coordiantes of my objects, caz i write them in the file and read them,
user will be able to draw in say (500 by 500), but the view can be smaller of bigger,
do you think i need to scale my view to (500 by 500)?
Thanks,
F.Dost
|
|
|
|
|
By using SetCapture in LMBDown you can make your window continue to recieve the events when your mouse leaves the window. You can also use OnMOuseMove to check your position and limit it ( you'll still need setcapture to get the message ) but limiting a users mouse movement is almost never a good idea. Don't forget to call REleaseCapture in LMB up.
Use a ScrollView and you get the scrollers for free
A scrollview will probably fix problem 3 as well.
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|
|
Sorry guys I'm pretty new to ATL and COM stuff. The project is a shell extension with MFC support. Been looking at the tutorials on it over and over but can't find out how to fix this problem. After starting a new project I can get it to work. Then after compiling a few times (changing nothing) it starts giving this link error. It doesn't start after any specific number of compiles, but once it starts occuring it doesn't go away.
Linking...
mfcs42.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in MSVCRT.lib(dllmain.obj)
mfcs42.lib(dllmodul.obj) : warning LNK4006: _DllMain@12 already defined in MSVCRT.lib(dllmain.obj); second definition ignored
Creating library ReleaseMinSize/program.lib and object ReleaseMinSize/program.exp
ReleaseMinSize/program.dll : fatal error LNK1169: one or more multiply defined symbols found
I can start a new project, transplant the code, and have it working for a while till I get this again. I've had to include afxcmn.h, and change my .cpp files to automatic use of precompiled headers. But apart from that I've not really changed anything. I can get the code to work fine in a nonMFC dll (without using MFC components). Removing all MFC statements I've added doesn't help either.
Any idea on how to fix this?
Thanks
-Neil
|
|
|
|
|
Try removing _ATL_MIN_CRT from the Preprocessor settings.
I think this essentially tells the compiler that you don't want to link with the C runtime, so it creates its own dllmain. Somewhere in your code, however, you are calling CRT functions, so the lib gets pulled in and voila - two dllmains.
You might be able to avoid this by using the 'el' versions of the CRT - e.g. lstrcpy for strcpy.
|
|
|
|
|
Thanks for the reply.
I haven't got _ATL_MIN_CRT in my preprocessor definitions it seems. This is what I have:
WIN32,NDEBUG,_WINDOWS,_WINDLL,_AFXDLL,_MBCS,_USRDLL,_ATL_DLL
Removing _ATL_DLL doesn't seem to help. Removing _AFXDLL creates more errors ofcourse.
The strange thing is I can link the project after creating a new one, and notice no differences in any project settings after it starts having this link error.
I've tried deleting some different generated files but that hasn't helped so far either.
Any ideas?
Thanks
|
|
|
|
|
Sorry guys, fixed it now. I was using memset and including memory.h in one of my classes which seemed to cause it. Although I could comment out the memset and include statements, build it, uncomment them and build again and then it'd work. Although gives a warning:
LINK : warning LNK4089: all references to "MSVCIRT.dll" discarded by /OPT:REF
Which is good I guess. Can't see any options or flags that may have changed to cause this though.
|
|
|
|
|
I have a sample project of a nice looking plot.
When I print it, it prints out the size of a dime
rather than using the entire sheet of paper.
Can I please, please, please, email this project
to someone, anyone and hopefully make it print
bigger?
Any response any one can give me will be greatly
appreciated.
My email address is brinasas@yahoo.com
|
|
|
|
|
try this:
pDC->SetMapMode(MM_ISOTROPIC);
pDC->SetWindowExt(CSize(72, 72));
pDC->SetViewportExt(pDC->GetDeviceCaps(LOGPIXELSX), pDC->GetDeviceCaps(LOGPIXELSY));
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
I need read a file and search for certain keywords and extract the string following that keyword.
I have read through the functions CFile::Read, CStdioFile::ReadString, GetPrivateProfileString functions, but they dun exactly meet my requirements.
the closest function is CStdioFile::ReadString, where I have t indicate the number of chars to read from the file. but how can I ensure that I have retreieved the whole line of text in a file, since i do not knwo how long the line is.
Is there other methods/ functions which i can use to extract data from a file?
pls help. thanz in advance
|
|
|
|
|
There are two ways to use the CStdio::ReadString method. The first is to pass a reference to a CString object and the entire string will be read into the referenced object. This is usually the simplest way of doing this. The second method is to allocate a buffer that is larger than the largest string you ever expect to read. You can then use the method that accepts a buffer pointer and a value that represents the size of the buffer. If you do not know what the largest string is you will read, then I suggest you use the first approach.
a).
CString strReadData;
FileToRead.ReadString(strReadData);
b).
char szBuffer[MAX_STRING_EVER_TO_READ+1];
FileToRead.ReadString(szBuffer, MAX_STRING_EVER_TO_READ);
Chris
|
|
|
|
|
In my situation there is one 'server' (Win2000) and there are numerous 'clients' (Win95/98/ME/NT/2000). Both server and clients have modems, but no internet connection.
Now the question is very simple (even though haven't found a simple answer yet): how can I send a file from the server to a client using the modems? I've looked at RAS, TAPI and other complicated stuff , but surely there must be an EASY way to do this.
Structured programming vs. chaotic mind boggling
|
|
|
|
|
you could use the old zmodem transfer protocol (or any of the others) but i don't know where to find a class that does it (sure there must be a CZModem() somewhere...)
---
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|
|
hi i hve requirements in UK on VC++ with MFC/COM in telecome and embeded systems with 2.5 years exp. and also on GSM. if aou ar ethe on esen dyour cv to naidumg@yahoo.com
Mohan
|
|
|
|
|
hi all!
I have a CFormView, in a split window, and would like to remove the <very> sunken border that is drawn around the edges of the form view by default. Not sure if the border is part of the form or the frame ....
any help very appreciated,
Nick
|
|
|
|
|
Hi Nick - tweak the CREATESTRUCT in the view's overloaded PreCreateWindow...
BOOL CMyFormView::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style = WS_CHILD | WS_VISIBLE;
return CView::PreCreateWindow(cs);
}
|
|
|
|