|
Thanks! Sometimes it's good to know why, not just that it works
|
|
|
|
|
Caslen wrote: ::SendMessage(m_ControlsDialog,WM_CLOSE,0,0); //send a message to close the dialog and thread
You've not shown how m_ControlsDialog was declared. I assume it's safe to send a message to. If it's a modeless dialog, why not just call DestroyWindow() ?
Caslen wrote: while(self->m_TerminateThreads!=0)
This loop is suspect if m_TerminateThreads is not declared as volatile . Otherwise, it may or may not execute, or it may fail to end. Because m_TerminateThreads is not being changed within the loop, the compiler would likely optimize it out.
A better way of having the secondary thread end is to have the primary thread signal an event.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
I already figured out the 'volatile' thing - I was more concerned about why I had to 'SendMessage' from CMainFrame::OnClose() - why wasn't CDataControls::OnClose() automatically closed when the App is closed?
|
|
|
|
|
Caslen wrote: ...why wasn't CDataControls::OnClose() automatically closed when the App is closed?
Because it was in the secondary thread, which was not terminating, perhaps? To test this, change your code to:
WaitForSingleObject(pDataGrabThread->m_hThread, INFINITE);
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Ok, that is probably it - but it's correct to use SendMessage() from CMainframe to close it though?
|
|
|
|
|
Caslen wrote: ...but it's correct to use SendMessage() from CMainframe to close it though?
Is the dialog modeless?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
|
Then just call DestroyWindow() .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Note that you should declare m_TerminateThreads as mutable volatile as a compiler optimisation could break your code.
These lines
while(self->m_TerminateThreads!=0)
{
self->DoDataGrab();
could be interpreted as the compiler as:
if (self->m_TerminateThreads!=0)
{
for (;;)
{
self->DoDataGrab();
If you vote me down, my score will only get lower
|
|
|
|
|
Hi
I want to draw line on OnMouseMove function of a dialog class.I want to draw
the line in one color(fixed color not inverse color ),but it is showing in
different/inverse color. If I omit SetROP2 the line will get spread.
<code>
CDC* pDC = this->GetDC();
int nR2 = pDC->SetROP2( R2_NOTXORPEN );
pDC->MoveTo(m_StartPoint);
pDC->LineTo(m_Previouspoint);
m_Previouspoint = point;
pDC->MoveTo(m_StartPoint);
pDC->LineTo(point);
</code>
How to solve it?
thanks
|
|
|
|
|
Please find previous thread.
that will help you
|
|
|
|
|
Exactly how would finding a thread help in drawing a line?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Benjamin Bruno wrote: I want to draw
the line in one color(fixed color not inverse color )
Did you select such a Pen object to your CDC before calling LineTo() function?
|
|
|
|
|
// Add URL
void LeftView::AddUrl(void)
{
CTreeCtrl& trCtrl = GetTreeCtrl();
HTREEITEM hitem,hitem1,hitem3;
hitem = trCtrl.InsertItem(_T("URL"),TVI_ROOT,TVI_LAST);
for(inti=0; i<arrLines.GetSize();i++)
{
CString str = arrLines.GetAt(i);
trCtrl.InsertItem(str,hitem,TVI_LAST);
intk;
}
}
// REad text
arrLines.RemoveAll();
CString pszFileName(_T("D:\\URL\\TextFile.txt"));
CString strLine =_T("");
TRY
{
CStdioFile file(pszFileName, CFile::modeRead);
while( file.ReadString(strLine))
{
arrLines.Add(strLine);
}
}
CATCH_ALL(e)
{
e->ReportError(); // shows what's going wrong
}
END_CATCH_ALL
void LeftView::OnTvnSelchanged(NMHDR *pNMHDR, LRESULT *pResult)
{
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
NM_TREEVIEW *pNMTreeView = (NM_TREEVIEW *) pNMHDR;
CTreeCtrl &tTree = this->GetTreeCtrl ();
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
CString str("Test");
sFullList=" ";
sFullList += tTree.GetItemText(pNMTreeView->itemNew.hItem);
if( sFullList.CompareNoCase("URL") == 0)
{
GetDocument ()->UpdateAllViews ( this, 1L, (CObject *) &sFullList );
}
*pResult = 0;
}
BOOL LeftView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Add your specialized code here and/or call the base class
cs.style |= TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_EDITLABELS;
returnCTreeView::PreCreateWindow(cs);
}
CSplitterWindowDoc* LeftView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSplitterWindowDoc)));
return(CSplitterWindowDoc*)m_pDocument;
}
void CSplitterWindowView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
// TODO: Add your specialized code here and/or call the base class
if(lHint==1L)
{
CString sListToDisplay = ((CString*)pHint)->GetBuffer(0);
Navigate2(sListToDisplay,NULL,NULL);
}
CSingleDocTemplate* pDocTemplate;
pDocTemplate = newCSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CSplitterWindowDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(LeftView));
if(!pDocTemplate)
returnFALSE;
AddDocTemplate(pDocTemplate);
In OnTVNSelChanged funtion i want to check wheather i have clicked the root node. Can any one tell how to check this
|
|
|
|
|
Use GetSelectedItem[^] and compare it to your root HTREEITEM using GetRootItem[^]
Also, wrapping code into <pre></pre> tags will make it more readable.
|
|
|
|
|
|
For what domain? Some domains seem to attract coding standards like flies to jam and people can get very anal about things.
However coding standards are usually set locally by whoever thinks they know best. Usually they (and I include myself in that) don't so just use your common sense and domain knowledge to name things.
Cheers,
Ash
|
|
|
|
|
Any domain ones can suggest the reference to.
Simple scenario as in the link from the post with opposite initializers, finalizers pairs.
It would be handy to have a reference to common names used and not to exert you brain too much.
That is not the post about coding standards but about naming helper, it does not matter if the helper refers to initialize_system or InitializeSystem.
Чесноков
|
|
|
|
|
Buy a thesaurus?
This is actually a serious suggestion, I keep one (and a dictionary) on my desk to look for synonyms for overused words.
Cheers,
Ash
|
|
|
|
|
I'd be interested in your comments on this question[^].
It's time for a new signature.
|
|
|
|
|
Chesnokov Yuriy wrote: Are there similar resources to help in naming during coding?
Not that I am aware of, I think there is no globally accepted "best naming practice" in the C/C++ community. I would introduce a coding standard for your project or company, including class/method/variable naming. Whatever code gets committed/reviewed has to follow the coding standard (with exception of 3rd party libraries). Be aware that different people have strong opinions on this, however the goal should be to have ONE COMMON coding standard whatever that is.
If you have a particular question... how to name pattern xyz... you can ask for suggestions.
/M
|
|
|
|
|
That is not about coding standards or naming standards, the topic is about pure naming diversity for those deprived in literary genre.
I'd like to have a reference book or resource as in the link from the topic, e.g. list of names for object initialization and their opposites.
Чесноков
|
|
|
|
|
Chesnokov Yuriy wrote: I'd like to have a reference book or resource as in the link from the topic
I don't understand what you mean, could you please explain more detailed.
Chesnokov Yuriy wrote: e.g. list of names for object initialization and their opposites
Object initialisation/deinitialisation is done in the constructor and destructor in C++. Do you look for naming of corresponding software pattern in the C programming language? Alternatively, there is http://thesaurus.com.
|
|
|
|
|
I have wrote one program which deletes the elements from first vector 'v1' which are not in another vector 'v3'. At the deleting time i also want to delete that same index element from vector v2.
Eg. The 3 value of 'v3' is not present in 'v1', so i want to delete value 3 from 'v1' and value 7 of index 2 (if we consider 0 based index) from 'v2'.
But it goes crash at some point.
When you see program you get clear with this thing.
I am using Microsoft Visual Studio 6.0 editor. The code snippet is as
#include "stdafx.h"
#include <vector>
#include <algorithm>
#include <iostream>
int main( )
{
using namespace std;
vector <int> v1,v2,v3;
vector <int>::iterator result;
v1.push_back( 1 );
v1.push_back( 2 );
v1.push_back( 3 );
v1.push_back( 4 );
v2.push_back( 7 );
v2.push_back( 7 );
v2.push_back( 7 );
v2.push_back( 7 );
v3.push_back( 1 );
v3.push_back( 2 );
vector <int>::iterator V1Startitr = v1.begin();
vector <int>::iterator V1Enditr = v1.end();
vector <int>::iterator V2Startitr = v2.begin();
vector <int>::iterator V2Enditr = v2.end();
for(V1Startitr,
V2Startitr;
V1Startitr != V1Enditr;
V1Startitr++,V2Startitr++)
{
result = find(v3.begin(),v3.end(),*V1Startitr);
if(result == v3.end())
{
cout<
|
|
|
|
|
You can't erase an element from a vector by using an iterator that you will reuse later (in the for loop). What you have to do, is use the iterator returned by erase instead (but you shouldn't increment it, since it is already pointing to the next element).
Here is some pseudo-code:
while(iter!=v1.end())
{
....
if(remove)
{
iter = v1.erase(iter);
}
else
{
iter++;
}
}
PS: please use the pre tags to format your code properly when posting snippets of code.
|
|
|
|