|
One example is CView and its derivatives. Its constructor is protected which means that it can only be created by one of its numerous friend classes such as CDocument, CDocTemplate, CFrameWnd, CMDIChildWnd, and CMDIFrameWnd.
|
|
|
|
|
Hi Christian:
See you again
Here is the code MFC generate for my class.
I know why the DECLARE_DYNCREATE(EventLog) is protected, but I don't know why EventLog is protected, although the comment said "dynamic creation" will do this.
thank you.
/////////////////////////////////////////////////////////////////////////////
// EventLog view
class EventLog : public CObject
{
protected:
EventLog(); // protected constructor used by dynamic creation
DECLARE_DYNCREATE(EventLog)
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(EventLog)
protected:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
//}}AFX_VIRTUAL
// Implementation
protected:
virtual ~EventLog();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
// Generated message map functions
protected:
//{{AFX_MSG(EventLog)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
|
|
|
|
|
Alex Dong wrote:
know why the DECLARE_DYNCREATE(EventLog) is protected, but I don't know why EventLog is protected, although the comment said "dynamic creation" will do this.
..so that you can not create the class using standard C++ ways, such as creating them on the stack or on the heap using new operator. MFC wants you to create these classes using its own specific way, such as the one used by CObject's ::CreateObject() method. Creating this way would allow you to save extra runtime information. If you dig into MFC source code related to document-view classes, you will find more on how these objects are created.
Hope this helps.
// Fazlul
Get RadVC today! Play RAD in VC++
http://www.capitolsoft.com
|
|
|
|
|
I think Christian was taking issue with your use of "all" in your statement. Obviously things like CString and even CWinApp or CWnd don't have private constructors.
The answer is in the MFC FAQ (actually, it's credited to me, though I don't remember answering it... must have been like 7 years ago when I was active on the MFC mailing list, that's when I was using the name credited).
Odd.. I just went searching for the FAQ and it seems to have disappeared from the face of the internet (except a very early version).
Anyways, the gist is that CView and several other types are created dynamically by the framework without using new. (it's part of the CObject stuff). The constructors are marked private because originally the classes were not createable in any other way (they needed to be hooked up to the framework to function). They have since changed the framework so that you can create View's outside of the framwork, but the constructors are still private.
--
Where are we going? And why am I in this handbasket?
|
|
|
|
|
One reason for making a constructor protected is to ensure that users of the class always properly construct the object using an initializing public constructor.
CFoo* pFoo = new CFoo();
CFoo* pFoo = new CFoo (bar);
/ravi
"There is always one more bug..."
ravib@ravib.com
http://www.ravib.com
|
|
|
|
|
I have a binary file that stores information about user settings. But, when I look to save the bar state information, it does not allow me to get the data, instead writes it to a profile (ini file / registry). Any ideas to do this?
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
The save bar state functions are written to write to the registry or ini files, no surprises here.
You'll need to look at the MFC source and write your own version of these functions if you want to save to your own file.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
I want to populate and delete an stl vector using several threads.
Also one of the threads if going to sort the vector.
I derived a class from vector <t> and then put a mutex at the beginning of some methods. But I am not sure what to do with iterators.
When std::sort is called i do like this.
std::sort (vectr.begin(), vector.end())
I think this is not thread safe ?
I don't want to create a new method for the class and use the sort in the because I am sorting the vector according to many different criterias.
What do you think I should do ?
If you have a thread safe vector can you please send it to me ?
Orcun Colak
|
|
|
|
|
Thread safe containers are up to the user. You will have to protect access to your vector with a mutex or critical section.
Also note that it's not recommended to inherit from vector or any other container since none of them have a virtual destructor. It's better to use your vector as a member variable.
Todd Smith
|
|
|
|
|
Thanks Todd for your help.
Orcun Colak
|
|
|
|
|
I handle this message in my Win32 app, in order to not allow the user to size the window below the width of my tool area, which is variable, and to not allow sizing the floating tool window below the width of one button (alsovariable ), plus slider if necessary.
This worked fine up until a day or so ago. That is to say I noticed yesterday that it stopped working at some point. Now the minimum width is always 100 for all windows, no matter what. I've tried hard coded values in WM_GETMINMAXINFO, but they only work if they are greater than 100. Any width less than 100 seems to clamp to 100, and I don't know why.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Can you show me some code, Christian? I dealt with this problem a couple of weeks ago when Steen gave me a helping hand. I managed to get mine so that it could set the max width etc. to 0. Have you reset the lpMMI->ptMinTrackSize to (0,0)? It may default at (100,100)? Hope this helps you Christian, since you`ve helped me countless times in the past.
Alan.
"When I left you I was but the learner, now I am the Master" - Darth Vader
|
|
|
|
|
Ok.. I have this service, runs GREAT!! then I have this socket, runs CRAPPY.
With Naughter's testsvr's example I had taken the beeeep out of the main while loop and put a Thread that runs my Listening socket. I have a log that I can go to, to see my progression in the code.
My thread does initialize the socket and it creates it. I receive no errors. Then my client who is going to connect to my socket trys to connect. The "client" says it connects fine but the Service/Socket doesn't get to that point. This is where the problem is. The OnAccept for the Listening socket does not get called. This is a total MFC app. It is not a console app so I am assuming that I do have a message pump. I could be wrong too. If anyone has tried Sockets with servers I would appreciate any help. I have exhausted all my resources and I am really not sure this could be done. If someone can even tell me it can't be done I would appreciate that too.
Thanks in advance
|
|
|
|
|
I have two classes in a MFC DLL that use AFX_EXT_CLASS to export the classes (like below), but when I link it up to my application and include the header files for the classes I get a lot of errors (error C2228: left of '.Disconnect' must have class/struct/union type) - meaning the functions in the class don't have any code for them... but they should be in the DLL. Here are the classes I am trying to export. Any help would be good on what I am doing wrong, this is my first DLL experience. Thank you.
class AFX_EXT_CLASS CFirstClass
{
}
class AFX_EXT_CLASS CSecondClass
{
}
|
|
|
|
|
Supposing I want to allow the user to supply the file name when creating a file, I am not sure how to do it? I know you can do something similar to this:
#include <fstream.h>
int main()
{
ifstream infile;
infile.open("this_file.txt");
infile.close();
}
What would I use for a declaration to allow the user to name the file whatever they wanted? I hope this is clear enough, I know it is a rather generic question. Thanks in advance.
Nick Parker
|
|
|
|
|
I'm sure if you think about it, the answer is obvious.
#include <fstream>
int main(int argc, char *argv[])
{
ifstream infile;
infile.open(argv[1]);
}
Or, you can ask the user for the name.
int main()
{
string name;
cout << "Enter a filename";
cin >> name;
ifstream infile;
infile.open(name);
}
BTW, there is no need to close the file because it will close automatically when the ifstream object goes out of scope.
--
Where are we going? And why am I in this handbasket?
|
|
|
|
|
This is really strange, but I get a compile error when I try to do:
<small>Erik Funkenbusch wrote:
</small>int main()
{
string name;
cout << "Enter a filename";
cin >> name;
ifstream infile;
infile.open(name);
}
I can't get that to work, only when I specify the name, I know this sounds really strange. Obviously I am using a char instead of string for declaration, does this sound wierd or do you think I am doing something goofy here? Thanks.
Nick Parker
|
|
|
|
|
Try this it should work fine...
#include <iostream.h>
#include <fstream.h>
void main(){
char name[20];
cout << "Enter a filename" << endl;
cin >> name;
ifstream infile;
infile.open(name);
}
Joshua
Sonork ID: 100.9944
ICQ: 519642
Hotmail: JoshuaJGuy@hotmail.com
|
|
|
|
|
I've created a CDialog dlg and I want it to have a system tray icon.
Also I want to handle the messages that are sent from it (the icon).
the code I've wrote for adding the icon:
BOOL CMyDlg::OnInitDialog()
{
//.....................
//.....................
NOTIFYICONDATA nd =
{
sizeof(NOTIFYICONDATA), //.......Structure size
m_hWnd, //.......................Dialog's HWND
m_nIconID, //....................Icon's ID
NIF_ICON|NIF_MESSAGE|NIF_TIP,//..Flags
SYSTRAY_ICO_NOTIFY, //...........#define SYSTRAY_ICO_NOTIFY 12345
m_hIcon, //......................Dialog's HICON
"The tip!" //....................Tooltip text
};
Shell_NotifyIcon(NIM_ADD, &nd);
return 1;
}
BOOL CMyDlg::PreTranslateMessage(MSG *pMsg)
{
if( pMsg->message == SYSTRAY_ICO_NOTIFY ){
//Call some user defined message handler
return TRUE;
}
CDialog::PreTranslateMessage(pMsg);
}
***************************************************
the SYSTRAY_ICO_NOTIFY is never sent, WHY???
***************************************************
Thanks in advance!
--BlackSmith--
|
|
|
|
|
bar-cochva wrote:
the SYSTRAY_ICO_NOTIFY is never sent, WHY???
hm... 12345 is not the right value for that message!
define it as this:
#define WM_TRAYICON WM_APP + 10
But what you realy should do is to use the CSystemTray class by Chris M here on Code Project! go see that
------------------------------
©0d3 ©®4©k3® - That's me!
------------------------------
|
|
|
|
|
Does anyone know of a way to find out what was thrown in a "catch all" catch clause?
The app I'm working on throws all sorts of things in addition to exceptions. I hate having to catch each one.
e.g.
throw TRUE;
throw 3;
throw ErrObject;
Thanks for the help,
Bill
|
|
|
|
|
You can't figure what is cought. That's the catch of catch(...)
|
|
|
|
|
u can combine C++ error handling with C's SEH and u can use SEH to get information abt the exception. Please refer to John Robbins article on SEH and C++ in MSDN Magazine( i forgot the issue ) or his book
Ganesh Ramaswamy
|
|
|
|
|
There's no general way to catch anything throwable inside a try block. However, you can consider the possibility of having your app send an object of generic type, this meaning a class capable of holding values of an undetermined type. This beast indeed exists, and has been implemented in Boost any library (hey, it even works with MSVC++ 6.0). If you follow this approach, all you have to do is replace your throw s with:
throw bost::any(TRUE);
throw boost::any(3);
throw boost::any(ErrObject); Hope this helps.
Joaquín M López Muñoz
Telefónica, Ivnestigación y Desarrollo
|
|
|
|
|
You're probably right about this being the way to go. I was hoping to avoid replacing several hundred assorted throw stmts that are already in the app.
Oh well, Guess I'll get to work!
I appreaciate all the responses.
Thanks for the help,
Bill
|
|
|
|