|
Hello all,
I am having a list control(Report style),in that list control i have number of item. When i select a particular row and click on a button particular thread is started and if i select a different row and press the button same thread is started again.....following the same process i can start any number of same thread.
Now my problem is to end the particular selected thread.
i start thread using this line of code
pThread = (CMyThread*) AfxBeginThread( RUNTIME_CLASS CMyThread),THREAD_PRIORITY_NORMAL,NULL,CREATE_SUSPENDED,NULL);
and when i use this line of code to stop a thread it stops the last thread which is executing...
pThread->PostThreadMessage(WM_QUIT, NULL, NULL);
Can anybody solve my problem
Thanks in advance..
|
|
|
|
|
You need to keep the pThread corresponding to each row in list control. List control allows you to keep a usedefine DWORD value corresponding to each row using the funtion CListCtrl::SetItemData()
Suppose you started a thread for item 1 and you got a pointer pThread of type CWinThread. Keep that pointer in the 1 st row
m_list.SetItemData( 1, (DWORD)pThread);
So when you want to terminate the thread corresponding to the row 1 just use
CWinThread *pThread= (CWinThread*)m_List.GetItemData( 1 );<br />
if( 0 != pThread )<br />
pThread->PostThreadMessage(WM_QUIT, NULL, NULL);
nave
|
|
|
|
|
how to create right button click pop menu for list view control. i have to display a popup menu when the user right clicks the mouse in list view. how to do this. pls help me.
Arise Awake Stop Not Till ur Goal is Reached.
|
|
|
|
|
|
handle the NM_RCLICK message of the list ctrl. In that function, load the menu and pop it up
void MyDlg::OnRclickList1(NMHDR* pNMHDR, LRESULT* pResult) <br />
{<br />
CMenu PopUpMenu;<br />
PopUpMenu.LoadMenu( IDR_MENU1 );<br />
CPoint pt;<br />
pt = GetCurrentMessage()->pt;<br />
PopUpMenu.GetSubMenu( 0 )->TrackPopupMenu( TPM_LEFTALIGN, pt.x, pt.y, this, 0 );<br />
*pResult = 0;<br />
}
nave
|
|
|
|
|
ok i have to use the options in windows explorer. ie when we rightclick in explorer it popups a menu with view, arrange by icons etc. i have to show like this. whether is there any options to use this directily form windows or we have to create of our own
Arise Awake Stop Not Till ur Goal is Reached.
|
|
|
|
|
deeps_cute wrote: whether is there any options to use this directily form windows or we have to create of our own
You have to implement it by your self.
deeps_cute wrote: when we rightclick in explorer it popups a menu with view, arrange by icons etc.
When you click on such menu whats actually happing is sorting a column in an order. List control partially help you doing this. Check the LVM_SORTITEMSEX message.
nave
|
|
|
|
|
yes but i have to create the one similar to windows explorer (Mycomputer->Folders). so i thought there will be some fns to use this windows explorer context menu.
Arise Awake Stop Not Till ur Goal is Reached.
|
|
|
|
|
|
hmm is there any shortcut method to do like the one in windows explorer. pls let me know. i think i am irritating you
Arise Awake Stop Not Till ur Goal is Reached.
|
|
|
|
|
deeps_cute wrote: pls let me know.
sure..
deeps_cute wrote: i think i am irritating you
no pblm
nave
|
|
|
|
|
Is it possible to dynamically extend an (int) array?
I have an array of x elements, and at run time I want to add additional elements. ie. Array.push()
The only way I can think of would be using memcpy and malloc, but that'd get a bit messy.
Oh, and I'm using Dev C++.
|
|
|
|
|
normal array can not be extend
Your best choice is using Vector (in C++ Standard Template Library - available with all C++ compiler).
Vector allows direct access to elements and also works like a dynamic list.
|
|
|
|
|
yes, vector is good choice, except u wanna write a dynamic array by urself.
life is like a box of chocolate,you never know what you r going to get.
|
|
|
|
|
hi,
I need to create many UI-threads using MFC. Each thread must run all the time and is able to send/receive message with main thread.
I assume that I will have to create a CMyThread:public CWinThread and create many instance of this class in function AfxBeginThread() for UI-thread. But I notice that this function doesn't allow programmer to pass parameters to the newly-created thread.
So, how could I start those threads with different initial parameters ? (e.g pass a client address to each thread sothat each thread serve one client only)
thanks for any help.
|
|
|
|
|
GameProfessor wrote: So, how could I start those threads with different initial parameters ?
Here is one way
1.Add a function to the CMyThread class say "Initialize()"
2.Create the thread in the suspended mode.
3.Call the Initialize() function and pass the parameters that you want to pass.
4.Resume the thread.
nave
|
|
|
|
|
The code won't compile, but I only get some silly messages that don't help. I must be doing something illegal, but I don't have the knowledge of C++ to know what. Does anything catch anyone's eye? This is a basic linked list class that I'm trying to add enumerator functionality to. Project is set to plain unmanaged C++. Thanks in advance...
#pragma once
#include <assert.h>
template <class T>
class LinkedList
{
public:
class Enumerator
{
friend Enumerator LinkedList<T>::GetEnumerator();
public:
virtual T GetCurrent()
{
return _current->Item;
}
virtual bool MoveNext()
{
if (_current == 0)
_current = _linkedList->_head;
else
_current = _current->Next;
return _current != 0;
}
virtual void Reset()
{
_current = 0;
}
protected:
LinkedList<T> *_linkedList;
ListNode *_current;
Enumerator() : _current(0)
{
}
};
LinkedList() : _count(0), _head(0)
{
}
LinkedList(const LinkedList<T> &objectToCopy) : _count(objectToCopy._count)
{
if (objectToCopy._head == 0)
_head = 0;
else
{
_head = new ListNode;
_head->Item = objectToCopy._head->Item;
ListNode *newestNode = _head;
for (ListNode *nodeToCopy = objectToCopy._head->Next; nodeToCopy != 0; nodeToCopy = nodeToCopy->Next)
{
newestNode->Next = new ListNode;
newestNode = newestNode->Next;
newestNode->Item = nodeToCopy->Item;
}
newestNode->Next = 0;
}
}
virtual ~LinkedList()
{
while (_count > 0)
RemoveAt(0);
}
virtual T GetItem(int index)
{
return (AddressOf(index))->Item;
}
virtual int GetCount()
{
return _count;
}
virtual void Add(T value)
{
Insert(_count, value);
}
virtual void Insert(int index, T value)
{
assert(index >= 0 && index <= _count);
ListNode *nodeToInsert = new ListNode;
nodeToInsert->Item = value;
nodeToInsert->Next = AddressOf(index);
if (index == 0)
_head = nodeToInsert;
else
(AddressOf(index - 1))->Next = nodeToInsert;
_count++;
}
virtual void RemoveAt(int index)
{
assert(index >= 0 && index <= _count - 1);
ListNode *nodeToRemove = AddressOf(index);
if (index == 0)
_head = _head->Next;
else
(AddressOf(index - 1))->Next = (AddressOf(index + 1));
_count--;
delete nodeToRemove;
}
virtual Enumerator GetEnumerator()
{
Enumerator newEnumerator;
newEnumerator._linkedList = this;
return newEnumerator;
}
protected:
struct ListNode
{
T Item;
ListNode *Next;
};
int _count;
ListNode *_head;
virtual ListNode *AddressOf(int index)
{
if (index < 0 || index > _count - 1)
return 0;
else
{
ListNode *node = _head;
for (int i = 0; i < index; i++)
node = node->Next;
return node;
}
}
};
|
|
|
|
|
There are two problems:
1) The ‘GeEnumerator’ method must be defined before making it a ‘friend’.
2) You need to forward declare the ‘ListNode’ or define it before using it.
Exmple:
template <class T>
class LinkedList
{
struct ListNode;
class Enumerator;
virtual Enumerator GetEnumerator()
{
Enumerator newEnumerator;
newEnumerator._linkedList = this;
return newEnumerator;
}
class Enumerator
{
friend Enumerator LinkedList<T>::GetEnumerator();
}
};
You should be able to handle it from there.
Personally I would just use the STL ‘list’ template, possibly wrapping it if I wanted to add additional functionality.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
I played around with the order for a while, but I couldn't hit on the right combination that would get it to compile.
I know I'm just reinventing the wheel here, but this is just an excercise to remove some of the rust on my C++ skills.
|
|
|
|
|
I finally got it to work - I changed everything around to separate the implementations from the declaration and the compiler finally started giving me some better messages ('name' : dependent name is not a type) So it turned out that I just needed to throw a couple 'typename' keywords in there. I've never heard of that before... *sigh* Maybe I should stick to C#.
Anyway, here's the working code:
#pragma once
#include <assert.h>
// Declaration:
template <class T>
class LinkedList
{
public:
class Enumerator;
LinkedList();
LinkedList(const LinkedList<T> &objectToCopy);
virtual ~LinkedList();
virtual T GetItem(int index);
virtual int GetCount();
virtual void Add(T value);
virtual void Insert(int index, T value);
virtual void RemoveAt(int index);
virtual Enumerator GetEnumerator();
protected:
struct ListNode;
ListNode *_head;
int _count;
virtual ListNode *AddressOf(int index);
};
template <class T>
struct LinkedList<T>::ListNode
{
T Item;
ListNode* Next;
};
template <class T>
class LinkedList<T>::Enumerator
{
friend Enumerator LinkedList<T>::GetEnumerator();
public:
virtual T GetCurrent();
virtual bool MoveNext();
virtual void Reset();
protected:
LinkedList<T> *_linkedList;
ListNode *_current;
Enumerator();
};
//Implementation:
template <class T>
T LinkedList<T>::Enumerator::GetCurrent()
{
return _current->Item;
}
template <class T>
bool LinkedList<T>::Enumerator::MoveNext()
{
if (_current == 0)
_current = _linkedList->_head;
else
_current = _current->Next;
return _current != 0;
}
template <class T>
void LinkedList<T>::Enumerator::Reset()
{
_current = 0;
}
template <class T>
LinkedList<T>::Enumerator::Enumerator() : _current(0)
{
}
template <class T>
LinkedList<T>::LinkedList() : _count(0), _head(0)
{
}
template <class T>
LinkedList<T>::LinkedList(const LinkedList<T> &objectToCopy) : _count(objectToCopy._count)
{
if (objectToCopy._head == 0)
_head = 0;
else
{
_head = new ListNode;
_head->Item = objectToCopy._head->Item;
ListNode *newestNode = _head;
for (ListNode *nodeToCopy = objectToCopy._head->Next; nodeToCopy != 0; nodeToCopy = nodeToCopy->Next)
{
newestNode->Next = new ListNode;
newestNode = newestNode->Next;
newestNode->Item = nodeToCopy->Item;
}
newestNode->Next = 0;
}
}
template <class T>
LinkedList<T>::~LinkedList()
{
while (_count > 0)
RemoveAt(0);
}
template <class T>
T LinkedList<T>::GetItem(int index)
{
return (AddressOf(index))->Item;
}
template <class T>
int LinkedList<T>::GetCount()
{
return _count;
}
template <class T>
void LinkedList<T>::Add(T value)
{
Insert(_count, value);
}
template <class T>
void LinkedList<T>::Insert(int index, T value)
{
assert(index >= 0 && index <= _count);
ListNode *nodeToInsert = new ListNode;
nodeToInsert->Item = value;
nodeToInsert->Next = AddressOf(index);
if (index == 0)
_head = nodeToInsert;
else
(AddressOf(index - 1))->Next = nodeToInsert;
_count++;
}
template <class T>
void LinkedList<T>::RemoveAt(int index)
{
assert(index >= 0 && index <= _count - 1);
ListNode *nodeToRemove = AddressOf(index);
if (index == 0)
_head = _head->Next;
else
(AddressOf(index - 1))->Next = (AddressOf(index + 1));
_count--;
delete nodeToRemove;
}
template <class T>
typename LinkedList<T>::Enumerator LinkedList<T>::GetEnumerator()
{
Enumerator newEnumerator;
newEnumerator._linkedList = this;
return newEnumerator;
}
template <class T>
typename LinkedList<T>::ListNode *LinkedList<T>::AddressOf(int index)
{
if (index < 0 || index > _count - 1)
return 0;
else
{
ListNode *node = _head;
for (int i = 0; i < index; i++)
node = node->Next;
return node;
}
}
|
|
|
|
|
Not bad at all! I think you over use ‘virtual’, as this is essentially a container type that you would not normally derive from and those methods (other than destructor) would not normally be overridden.
It is a good idea to keep your C++ skills well oiled, shortly after C# first came onto the seen, there where calls for programmers to convert C# code to C++. There should always be a demand for people with good C and C++ skills in addition to the other languages they may know.
The ability to write good templates is a plus and is one area of C++ where you will learn the most about C++.
Reinvent the wheel or anything else that increases your understanding of the language or programming in general. Some programmers rewrite their favorite piece of code in every new language they learn, so that they can get a better understanding of it.
Have fun and Good luck!
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
OK, so I'm writing a program that basically locks down the computer. One of the necessary components of this is to disable the alt key, but I can't use a keyhook/DLL, etc., anything external. Intercepting WM_SYSKEY or anything like that doesn't work since most function calls are on a higher level. I can successfully block alt+tab, ctrl+alt+dlt, but not alt+spacebar.
So, what I'm using is scancode mapper to assign the alt key(s) to a null value (in other words, they won't function at all). But, upon changing these registry values, I must restart. I need this to be an almost instanteneous change though.
How can I employ this registry change without going throught the restart process? Would I have to reload keyboard drivers, and if so, how do I do that? I have been researching and googling all over the place, but I've found nothing useful. Please help.
Thanks, sjm96
|
|
|
|
|
I have a CMultiDocTemplate application (Doc/View Arc), I have Open multiple documents in the application, I would like to move a specific document with a particular path name to the top of the rest of the documents that is open.
I was able to find that PathName of the open document with this routine:
POSITION template_pos = AfxGetApp()->GetFirstDocTemplatePosition();
while(NULL!=template_pos)
{
CDocTemplate* pDocTemplate = AfxGetApp()->GetNextDocTemplate(template_pos);
if(NULL!=pDocTemplate)
{
POSITION document_pos = pDocTemplate->GetFirstDocPosition();
while(NULL!=document_pos)
{
CDocument* pDoc_to_check = pDocTemplate->GetNextDoc(document_pos);
AfxMessageBox(pDoc_to_check->GetPathName());
}
}
}
But I would like to move it to the top. How can I do that?
Thanks,
Chien
-- modified at 19:50 Wednesday 4th April, 2007
BTW, There is a similar solution in this site, called WindowsManager (OnActivate), however, the solution is too complicated and it does not make use of the Path name.
-- modified at 20:29 Wednesday 4th April, 2007
OK, I guess I can use the Windows Manager solution provided by Ivan Zhakov in http://www.codeproject.com/docview/windowsmanager.asp BUT I need to be able to store the full path name instead of just the window title
void CWindowDlg::FillWindowList(void)
{
m_wndList.SetRedraw(FALSE);
m_wndList.ResetContent();
HWND hwndT;
hwndT=::GetWindow(m_pMDIFrame->m_hWndMDIClient, GW_CHILD);
while (hwndT != NULL)
{
TCHAR szWndTitle[256];
::GetWindowText(hwndT,szWndTitle,sizeof(szWndTitle)/sizeof(szWndTitle[0]));
int index=m_wndList.AddString(szWndTitle);
m_wndList.SetItemData(index,(DWORD) hwndT);
hwndT=::GetWindow(hwndT,GW_HWNDNEXT);
}
m_wndList.SetRedraw(TRUE);
}
|
|
|
|
|
I am new to window enviroment and I would like to know how I can display grayscale image using visual c++ 6.0?
snowcone
|
|
|
|
|
Hello,
You need to use Win32 along GDI functions like this:
CreateWindow()
GetDC()
SelectObject()
GetStockObject()
SetStretchBltMode()
SetPixel()
StretchBlt()
BitBlt()
…
DeleteDC()
DeleteObject()
etc.
Regards,
|
|
|
|