|
Thank you
Roger Stoltz wrote: they are always created with a call to ::AfxBeginThread()
So, Is it a bad practive deriving a class from CWinThread and calling CreateThread().
I have been doing like that.
KIRAN PINJARLA
|
|
|
|
|
kiran.pinjarla wrote: So, Is it a bad practive deriving a class from CWinThread and calling CreateThread()
Let's just say that from the MFC framework point of view you're supposed to use ::AfxBeginThread() . This is also why the constructor is not publically declared in the CWinThread dervied class created by the wizard.
Doing it the way you have been doing it will work; it will spawn a UI-thread.
But you have to alter the CWinThread derived class to make the constructor public. You will also need to write the error handling that ::AfxBeginThread() would help you with, such as freeing up memory.
I recommend you to follow the MSDN guidelines on this: use ::AfxBeginThread() .
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
kiran.pinjarla wrote: CWinThread from wizard its constructor and destructor are in protected
You are supposed to use CWinThread derived class, hence it is protected.
-- modified at 4:49 Tuesday 22nd May, 2007
See Rogers reply.
Prasad
MS MVP - VC++
|
|
|
|
|
prasad_som wrote: You are supposed to use CWinThread derived class, hence it is protected.
What do you mean Prasad?
The wizard creates a CWinThread dervative and its constructor is protected because the CWinThread object is created with a call to ::AfxBeginThread() which uses CRuntimeClass for creating the object. E.g.
CMyThread* pThread = ::AfxBeginThread( RUNTIME_CLASS( CMyThread ) );
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Roger Stoltz wrote: What do you mean Prasad?
It means, I'd jumped in the discussion, without reading it carefully. My bad.
And replied in just C++ context.( why there should be protected c'tors ? and blah ,blah , )
Thanks for correcting me.
Prasad
MS MVP - VC++
|
|
|
|
|
prasad_som wrote: It means, I'd jumped in the discussion, without reading it carefully. My bad.
And replied in just C++ context.
No worries mate!
Been there, done that. Cheers
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hi.
I am really confused why the layout on an English version and that from anotehr OS (Chinese etc) would display differently. THe other OS would display everything in a smaller area than teh ENglish OS leaving more empty space.
In the CformView dialog, I made sure that the FOnt size and type (10, MS Sans Serif - should be on all computers) are common so that the layout as I would see it on my computer "should" be what someone would see it on another computer.
I know I ma definitely missing something. Can someone help and give a few hints on how to deal with this?
Thanks in advance!
Stan the man
|
|
|
|
|
Hi,
how did you create your font?
There is two possibilities that more or less "ensures" you compatibility
BOOL CreatePointFont( int nPointSize, LPCTSTR lpszFaceName, CDC* pDC = NULL );
but here the "int nPointSize" can depend on the MAPMODE, is not the same MM_TEXT as MM_LOMETRIC (for example)
The other one (from Roger Allen's http://www.codeproject.com/printing/printingtricksandtips.asp[^])
CFont font;
LOGFONT lf;
::ZeroMemory (&lf, sizeof (LOGFONT));
lf.lfHeight = -MulDiv (12, pDC->GetDeviceCaps (), 72);
strcpy (lf.lfFaceName, "Arial");
if it works for printers, it should work for displays too.
EDIT:
I found this article.
http://msdn2.microsoft.com/en-us/library/d8ws31ff(VS.71).aspx[^]
I hope it helps
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
Hello,
In the InitInstance function there is statement by default.
if (!pFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
now instead of IDR_MAINFRAME I made another menu IDR_PLAN and loaded this frame instead of IDR_MAINFRAME.
When I execute the application I get debug assertion failure.If I Ignore the error I get my menu and I can continue with the application.
How do I get rid of this debug assertion failure?
If I want a particukar menu option to be grayed or to be active in a frame .How do I go about doing it ?
A different menu has to be made for grayed menu option and a different menu for the same menu option when it is active has to be made.And they have to be chosen whenever that particular event occurs. Is it?
Thanks
Pritha
|
|
|
|
|
This is how I am controlling the Menu Bar from the View Class Window. I hope this will help you.
void CMyApplicationView::OnFormatWordwrap()
{
// TODO: Add your command handler code here
CMenu* pMenu; // Create a pointer to the current menu.
CWnd* pParent = GetParent();
pMenu= pParent->GetMenu(); // Get the menu.
CWaitCursor wait;
if (pMenu->GetMenuState(ID_FORMAT_WORDWRAP, MF_CHECKED))
{
SetWordWrap(FALSE);
pMenu->CheckMenuItem(ID_FORMAT_WORDWRAP, MF_UNCHECKED);
}
else
{
SetWordWrap(TRUE);
pMenu->CheckMenuItem(ID_FORMAT_WORDWRAP, MF_CHECKED);
}
}
The code is self explainatory.
Please try to be specific in asking question if you want exact solution.
Anurag Gandhi.
Bangalore, India.
|
|
|
|
|
Hi,
I have a MultiView application. I have set the menus as follows.
BOOL CFPSApp::InitInstance()
{
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(5);
pDocTemplate = new CMultiDocTemplate(
IDR_FPSIITYPE,
RUNTIME_CLASS(CFPSDoc),
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CFPSView));
AddDocTemplate(pDocTemplate);
pParamInTemplate = new CMultiDocTemplate(
IDR_VIEWTYPE,
RUNTIME_CLASS(CFPSDoc),
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CParamInView));
AddDocTemplate(pParamInTemplate);
}
And with this is the CChildFrame the one that automatically associates menus to respective classes/views.
I hope it helps you
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
Hello,
I need to add docking support in a dialog based application. Is this possible? (I could not find explicit examples here in CodeProject, most of the examples are for a Single or Multiple Document application and not for a Dialog based application.
The docking child window contains several combo boxes and a graph control, this window should be attached to some location in the main dialog window, but can be also "detached" as a modeless dialog.
I guess that the child dialog should derive from a CDialogBar...but what to do on the main dialog?
Another limitation: I can't use an ActiveX control to contain the docking window as in this example:
Docking CSizingControlBar objects inside ActiveX containers[^]..
Can someone provide some hint on how to do this?
Thanks in advance.
-- Ricky Marek (AKA: rbid)
-- "Things are only impossible until they are not" --- Jean-Luc Picard
My articles
|
|
|
|
|
I add a class in my VC2005 project. I select the class template to be MFC and automation enabled. I want this class to be derived from CCmdTarget and handle some of the connection point events. The wizard created cpp file has a dispatch map.When I try to add methods to thjis class I do not find the dispatch map getting filled up. Is there anything I'm missing here?
|
|
|
|
|
You can always add them by yourself, although you don't find it in the Class Wizard. Try with a new project and another class that you now it has this message in class wizard. Put it in the new project to see the form and copy it to your project. Most of times it should work, as long as you don't ask something imposible to that class.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
What is the difference between
a::a()
and
a::a(void)
Do we enforce some kind of extra information by use of the void keyword?
|
|
|
|
|
tom groezer wrote: What is the difference between
a::a()
and
a::a(void)
Do we enforce some kind of extra information by use of the void keyword?
They are the same. The C language requires functions with no parameters to have the void. A lot of people have carried that over into c++
|
|
|
|
|
hello!!!!!!!
i have two listboxes and two buttons to move the content from one listbox to another.when i select an item from a listbox ...after clicking on button it moves to another listbox....but selected item remains selected in previous listbox.
our requirement is ....item remains in previous box but unselected.
thanks!!
|
|
|
|
|
You can do this by sending a message to the previous ListBox;
Use the SendMessage API as follows:
SendMessage(hWndControl, LB_SETCURSEL, -1, 0);
where hWndControl is the window handle to the previous ListBox. Setting the wParam to -1 means that there is no selection in the ListBox
Hope this helps!
--PerspX
|
|
|
|
|
Hi,
why don't you use the CWnd::SetFocus ()? As CListBox derive from CWnd you can use inheritance**
**is that the english word?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
Hi,
I want to View property of a file for with I have written the following code.
ViewProperty(CString strFile)
{
if(strFile.IsEmpty())
{
MessageBox(CString("Please Select a File."), CString("Properties"), MB_ICONASTERISK);
return ;
}
SHELLEXECUTEINFO sh={0};
sh.cbSize = sizeof ( sh );
sh.fMask = SEE_MASK_INVOKEIDLIST;
sh.lpVerb = CString("properties");
sh.lpFile = strFile;
ShellExecuteEx(&sh);
}
But this is working in VS 2003 but not in VS 2005. Can anyone help me what needs to edited.
Thanking You.
Anurag Gandhi.
|
|
|
|
|
Anurag Gandhi wrote: But this is working in VS 2003 but not in VS 2005.
What do you mean by not working? Not compiling? Not executing? Runtime error?
Shog on learning VB6: Ah, that would have been VB6. Kicked my ass anyway.
So easy to learn, just like falling down a flight of stairs...
|
|
|
|
|
Hi Brahmma,
It was compiling and executing. But program was terminating abnormally when calling that function. Sorry for asking incomplete question.
Anurag Gandhi.
|
|
|
|
|
That's fine; did you try debugging? Where does the crash occur?
Anything I will say you will bring it down to whatever you want.
|
|
|
|
|
Anurag Gandhi wrote: SHELLEXECUTEINFO sh={0};
sh.cbSize = sizeof ( sh );
sh.fMask = SEE_MASK_INVOKEIDLIST;
sh.lpVerb = CString("properties");
sh.lpFile = strFile;
ShellExecuteEx(&sh);
Modify this to,
CString sVerb = _T("properties");
SHELLEXECUTEINFO sh={0};
sh.cbSize = sizeof ( sh );
sh.fMask = SEE_MASK_INVOKEIDLIST;
sh.lpVerb = sVerb;
sh.lpFile = strFile;
ShellExecuteEx(&sh);
Prasad
MS MVP - VC++
|
|
|
|
|
I have such a function:
template <class t=""> T& GetInst()
{
static T t;
return t;
}
I'm not sure whether this is thread safe? If T's constructor has many operations, when two thread entered this function early and later, is there such scenario: the first thread is in T's constructor's, the second thread define t again?
|
|
|
|