|
Something like this will work
void CMyClass::StartNewThread()
{
m_hThread = reinterpret_cast<handle>(
_beginthreadex( NULL, NULL, &_ThreadFunc,
this, CREATE_NORMAL, &dwThreadID ));
}
unsigned _stdcall CMyClass::_ThreadFunc( LPVOID arg )
{
CMyClass *pWrker = (CScrCMyClass *)arg;
pWrker->TheadFunct();
return 0;
}
|
|
|
|
|
Is this compatible with MFC?
|
|
|
|
|
If you are manipulating MFC object from this thread derive your class from CWinThread. If not code I posted works just fine. Just don't use CreateThread because of CRT....
Brian
|
|
|
|
|
When _ThreadFunc is a class member function it have to be a static function becaude of the this pointer passed to all non-static memberfunctions.
Your example will not compile unless it's declared as static .
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
|
I've got an EditView, and I would like to change the behaviour of the tab key.
I want to pad my own spaces depending on where I am.
The changes applied in OnChar(), are apparently too late in the process. Can someone tell me where I can stop tab from tabbing?
Or should I just select the last character in OnChar(), and overwrite it with the spaces I want?
Thanks!
BW
"We get general information and specific information, but none of the specific information talks about time, place or methods or means..."
- Tom Ridge - US Secretary of Homeland Security
|
|
|
|
|
Override PreTranslateMessage
if ((pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_TAB))
{
...
}
do something
|
|
|
|
|
That got me to process before the 'Tab'(which is new to me ), but does not stop the tab from processing.
I've opted to delete the tab, after the fact, and place the spaces I need.
Thanks for your help!
BW
"We get general information and specific information, but none of the specific information talks about time, place or methods or means..."
- Tom Ridge - US Secretary of Homeland Security
|
|
|
|
|
>but does not stop the tab from processing.
did you return from preTranslateMessage, or still called baseClass::PreTranslate()? Sounds to me you are still calling view baseclass with PreTranslate.
Brian
|
|
|
|
|
My understanding was to implement this way, and it would "short-cicuit" normal VK_TAB behaviour. Did I screw it up?
BOOL CQS1EditView::PreTranslateMessage(MSG* pMsg) <br />
{<br />
if ((pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_TAB)) <br />
{ <br />
.... do stuff <br />
}<br />
else<br />
return CEditView::PreTranslateMessage(pMsg);<br />
}<br />
BW
"We get general information and specific information, but none of the specific information talks about time, place or methods or means..."
- Tom Ridge - US Secretary of Homeland Security
|
|
|
|
|
Return TRUE from PreTranslateMessage if you don't want the message to be dispatched. If you are already doing this in your ".... do stuff" section, I'm not sure what the problem is.
Chris Richardson
C/C++ Include Finder[^]
|
|
|
|
|
Chris Richardson wrote:
Return TRUE
hehe, oops. Thanks Chris
BW
"We get general information and specific information, but none of the specific information talks about time, place or methods or means..."
- Tom Ridge - US Secretary of Homeland Security
|
|
|
|
|
|
Hi,
in a SDI application I want to reload a document that was modified with CDosument::SetModified (TRUE) by clicking on the document in the MRU list. But the framework will recognize the document as already beeing loaded and only activates it as current active document again. There seems to be also no simple method to override to allow such a behavoir.
Two functions are involved in this:
CDocManager::OpenDocumentFile and CDocTemplate::MatchDocType
Both are virtual but both are also non trivial.
This function does not belong into the CDocTemplate, since I would like to have it for all Documents in a MDI Application. But this function isn't trivial at all.
Finally I have CWinApp::OnOpenRecentFile. But this isn't a real option also.
Is there any simple way to do this?
Thanks
Dirk
|
|
|
|
|
I took a look at your problem, and it seems like there's no simple way to do this. You need to derive from the DocManager class being used -- it's probably CFileDialogDocManager but look in your InitInstanstance for the exact name. Then you can override the OpenDocumentFile and pretty much copy the whole thing from the base class, except the part that checks the file's name. Well, you actually do want to check the file name so you can close the existing document.
It's not bad, just not very pretty. BTW, don't forget to change InitInstance.
Regards,
Alvaro
There are no stupid questions, but there are a lot of inquisitive idiots. -- despair.com
|
|
|
|
|
Thanks Alvaro,
I hoped there was a simpler solution. Perhaps only setting a flag or something
I realized it now, not overriding the OpenDocumentFile member function, but the MatchDocType function. This results in a much cleaner solution, since I don't have to copy code from the CSingleDocTemplate implementation
class CSingleReloadDocTemplate : public CSingleDocTemplate
{
DECLARE_DYNAMIC(CSingleReloadDocTemplate)
public:
CSingleReloadDocTemplate(UINT nIDResource, CRuntimeClass* pDocClass,
CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass)
: CSingleDocTemplate (nIDResource, pDocClass, pFrameClass, pViewClass)
{
}
virtual Confidence MatchDocType(LPCTSTR lpszPathName, CDocument*& rpDocMatch)
{
Confidence confidence = CSingleDocTemplate::MatchDocType (lpszPathName, rpDocMatch);
if (yesAlreadyOpen == confidence && rpDocMatch->IsModified())
{
int answer = AfxMessageBox ("Do you want to reload the document", MB_YESNO);
if (answer == IDYES)
{
// set the document modification state to "not modified" so the document template
// will not complain during OpenDocumentFile ()
rpDocMatch->SetModifiedFlag(FALSE);
// tell the DocumentManager, that no document with this title is already opened
rpDocMatch = NULL;
confidence = yesAttemptNative;
}
}
return confidence;
}
};
IMPLEMENT_DYNAMIC (CSingleReloadDocTemplate, CSingleDocTemplate);
For a MultiDocTemplate one should perhaps close the found document in some way (perhaps via CDocument::OnCloseDocument) since the CMultiDocTemplate::OpenDocumentFile() function will not reuse an existing open document like the CSingleDocTemplate. I'm not sure wether there is a combined method for this task that can be used for a SingleDocTemplate and a MultiDocTemplate (perhaps one can use CDocument::OnCloseDocument() already)
Regards,
Dirk
|
|
|
|
|
I think I'm not doing it right:
typedef struct{
CTrio * pCTrio;
int indexOfParentDisplay; } TrioIndexStruct;
std::set<TrioIndexStruct*>::iterator trioIt = m_pTrioSet.begin();
for(; trioIt != m_pTrioSet.end(); trioIt++)
{
(*trioIt)->pCTrio->ShowWindow(SW_HIDE);
}
and I'm getting a crash at the SW_HIDE:
BOOL CWnd::ShowWindow(int nCmdShow)
{
ASSERT(::IsWindow(m_hWnd));
if (m_pCtrlSite == NULL)
return ::ShowWindow(m_hWnd, nCmdShow);
else
<code>return m_pCtrlSite->ShowWindow(nCmdShow); </code>
}
m_pCtrlSite isnt null.
Appreciate your help,
ns
|
|
|
|
|
More info is needed: How are you feeding m_pTrioSet ? What's the lifespan of the CTrio objects pointed to by those TrioIndexStruct s?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
LRESULT CSTrainView::OnUDMShowPhoto(UINT index, UINT nDummy)
{
CString mineName;
CTrio* pCTrio = new CTrio;
if (pCTrio == NULL) return 1;
BOOL ret = pCTrio->Create(IDD_CTRIO, this, index);
if(!ret)
{
AfxMessageBox("Error creating photobox");
delete pCTrio;
return 1;
}
int tempIndex = m_imageIndexLo + index;
pCTrio->ShowWindow(SW_SHOW);
<code> TrioIndexStruct trioIndexStruct;</code>
trioIndexStruct.pCTrio = pCTrio;
trioIndexStruct.indexOfParentDisplay = index;
m_pTrioSet.insert(&trioIndexStruct);
PopulatePhotoDisplay(tempIndex, trioIndexStruct.pCTrio, &mineName );
pCTrio->SetPhotoCaption(mineName);
return 0;
}
The Struct is local, but since I'm inserting into a set, it makes a copy that doesnt go out of scope (this is what I gather).
Appreciate your help,
ns
|
|
|
|
|
The Struct is local, but since I'm inserting into a set, it makes a copy that doesnt go out of scope (this is what I gather).
No copy is made, here's the problem. Define m_pTrioSet as a std::set<trioIndexStruct> (no pointer), change everything accordingly and the thing should work.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I'll try it as soon as my machine finishes burning a dvd....doesnt like me to do anything while its burning...
Thanks!
Appreciate your help,
ns
|
|
|
|
|
I had done that (and retried it). I get the following bunch of errors:
:\VC98\INCLUDE\functional(86) : error C2784: 'bool __cdecl std::operator <(const class std::deque<_Ty,_A> &,const class std::deque<_Ty,_A> &)' : could not deduce template argument for 'const class std::deque<_Ty,_A> &' from 'const CSTrainView::Trio
IndexStruct'
.........
e:\VC98\INCLUDE\functional(86) : while compiling class-template member function 'bool __thiscall std::less<struct CSTrainView::TrioIndexStruct>::operator ()(const CSTrainView::TrioIndexStruct &,const CSTrainView::TrioIndexStruct &) const'
e:\VC98\INCLUDE\functional(86) : error C2784: 'bool __cdecl std::operator <(const class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &,const class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &)' : could not deduce template argument for 'const class std::
reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &' from 'const CSTrainView::TrioIndexStruct'
e:\VC98\INCLUDE\functional(86) : while compiling class-template member function 'bool __thiscall std::less<struct CSTrainView::TrioIndexStruct>::operator ()(const CSTrainView::TrioIndexStruct &,const CSTrainView::TrioIndexStruct &) const'
e:\VC98\INCLUDE\functional(86) : error C2784: 'bool __cdecl std::operator <(const struct std::pair<_T1,_T2> &,const struct std::pair<_T1,_T2> &)' : could not deduce template argument for 'const struct std::pair<_T1,_T2> &' from 'const CSTrainView::T
rioIndexStruct'
e:\VC98\INCLUDE\functional(86) : while compiling class-template member function 'bool __thiscall std::less<struct CSTrainView::TrioIndexStruct>::operator ()(const CSTrainView::TrioIndexStruct &,const CSTrainView::TrioIndexStruct &) const'
e:\VC98\INCLUDE\functional(86) : error C2676: binary '<' : 'const CSTrainView::TrioIndexStruct' does not define this operator or a conversion to a type acceptable to the predefined operator
e:\VC98\INCLUDE\functional(86) : while compiling class-template member function 'bool __thiscall std::less<struct CSTrainView::TrioIndexStruct>::operator ()(const CSTrainView::TrioIndexStruct &,const CSTrainView::TrioIndexStruct &) const'
Error executing cl.exe.
STrain.exe - 10 error(s), 29 warning(s)
Appreciate your help,
ns
|
|
|
|
|
looks like it can't find your const operator < function :
bool operator < (const blah & a, const & blah b) const;<code> <br />
<br />
<hr><br />
<font size="-2" color="#6060af">When history comes, it always takes you by surprise.</font><br />
<div align="right"><font size="-1"><a href="http://www.smalleranimals.com/bobber.htm">Bobber!</a></font></div>
|
|
|
|
|
Someone showed me how to write a < operator for the set, since it needs it to compare the structs when its reaaranging the items automatically as they get inserted. Thanks!
Appreciate your help,
ns
|
|
|
|
|
Hai..
In richeditctrl when the test is selected by default the foreground color is white and background color is black. But i have to change change this foreground color to red and background is yellow.
How i can change this selected text colors??
Thanks in Advance
RednamRao
|
|
|
|
|