|
simoncoul wrote: I'm sure that it is not the UpdateData that is causing the problem
OK but you said the message box was looking for a number between 0 and 1000.
You showed a validator on m_dradix - DDV_MinMaxFloat(pDX, m_dradix, 0.f, 1000.f);
What is the value of m_dradix at the time of the scroll message?
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thank you very much everyone I have found my problem. I piece of the code was passing a zero into a log base 10, resulting is crazy numbers. I just don't understand why VC6 and VS2003 did not pick this up as an error?
|
|
|
|
|
Hi folks,
Got a Q re updating text on a status bar after changing focus from an application. I have a program I wrote that updates a database and shows the numbers of records processed on the status bar. When I change focus from that program the counter stops and when I subsequently go back to it, the numbers of recds processes stay frozen. What can I do to update the status bar once the program regains focus? Thx,
Ralf.
ralf.riedel@usm.edu
|
|
|
|
|
are you using MFC and UpdateCmd mechanism?
led mike
|
|
|
|
|
Using MFC and in CMainFrame() I have the following code. That's all I have for code handling the status bar.
void CMainFrame::UpdateStatus(UINT nPane, CString str) {
this->m_wndStatusBar.SetPaneText(nPane, str);
}
ralf.riedel@usm.edu
|
|
|
|
|
You should do some reading about the MFC macro ON_UPDATE_COMMAND_UI and associated framework implementation.
led mike
|
|
|
|
|
hi i have to change the dialog background color at runtime frequently. how to do this
|
|
|
|
|
* Handle WM_CTLCOLOR (handler OnCtlColor)
* prepare a HBRUSH (CreateSoldBrush or so)
* return that brush from the handler (also use CDC::SetBkMode(TRANSPARENT) if needed)
--
=====
Arman
|
|
|
|
|
prathuraj wrote: change the dialog background color at runtime
On the WM_CTLCOLOR you need when want to use SetBkColor(); use of a global variable(COLORREF).
|
|
|
|
|
I currently get a C++ compiler error 32385:
Ambiguous access of CreateNewThread in 'mainloop'
Now, The cause of this is because the mainloop class inherits,
ClxThread object, and Poll_LenzeInvertors object. The Poll_LenzesInvertors objects also inherits ClxThread object. The ClxThread object has a function called CreateNewThread() that spinns a thread of virtual function called ThreadFunc(). I used the ClxThread to create OO way to create threads. Howver, this seems to be the problem with multiple inheritenace.
I would like to find a solution to this problem and still be capable of using my ClxThread Object. Any advise would be helpful.
Is there a way to distrigish which base class you are trying to call?
Should i just rewrite ClxThread so, it does not have to be inherited to work...
Scott
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
ScotDolan wrote: I currently get a C++ compiler error 32385:
C2385 perhaps?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
yes, My mistake on the error number.
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
Try overloading CreateNewThread() in your derived class. There you can now call ClxThread::CreateNewThread() or Poll_LenzesInvertors::CreateNewThread() - whatever your logic requires.
Failure is not an option - it's built right in.
|
|
|
|
|
I'm not sure to have fully understood your description (a small drawing or scheme would be usefull here). Is the case described here[^] the problem ?
Try to make the inheritance virtual:
class MyClass : public virtual CMyBase
But in general, this kind of situation should be avoided if possible.
|
|
|
|
|
Cedria,
The dread problem is exactly what i am seeing and the solution you provide works. That web site was helpful also.
Scott
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
thank you.
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
Cédric,
I miss spoken, the virtual keyword did make the code compile but it still did not function as as expected.
I want to achieve the following functionality of having two ClxThread base objects using inheritence. I basiclly develop a ClxThread class object that provides all the functionaliy to create, kill, suspend, and start a Thread function. I now realize my design decision of making clxthread as base class was probably not the best idea. However, it does make it easy to turn any class into a little worker class/app. Is thare any way i can achieve my desire results.
Desire Results Actual Results
ClxThread ClxThread
\ / \
\ / \
\ / \
Poll ClxThread Poll |
\ / \ /
\ / \ /
\ / \ /
mainloop mailoop
Here is the header for the clx thread class
<br />
<br />
class ClxThread<br />
{<br />
public:<br />
ClxThread();<br />
virtual ~ClxThread();<br />
<br />
typedef unsigned (__stdcall *PTHREADFUNC)(void *);<br />
bool CreateNewThread(void);<br />
bool CreateNewThread(PTHREADFUNC pThreadFunc);<br />
bool Wait();
bool Suspend();
bool Resume();
bool Kill();
bool IsActive();
<br />
virtual void ThreadEntry(){ }<br />
virtual void ThreadExit(){ }<br />
virtual void ThreadRun(){ }<br />
<br />
static UINT WINAPI _ThreadFunc(LPVOID pParam);<br />
<br />
public:<br />
HANDLE m_hThread;
UINT uiThreadId;
<br />
bool m_bActive;
DWORD m_lpId;
};
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
Why do you want to do such a thing ? I really don't understand why you want to inherit from ClxThread once again.
You know that the functionalities of your class will be inherited even if there is a class (Poll) in between ?
|
|
|
|
|
I want to inherit ClxThread twice because, i need to create two ClxThreads which are just worker threads. One in the Mainloop and one in Poll. It is looking like I should change ClxThread to have the capablities to be object within Mainloop and Poll instead of a inherited object.
<br />
class ClxThread<br />
{<br />
public:<br />
ClxThread();<br />
virtual ~ClxThread();<br />
<br />
typedef unsigned (__stdcall *PTHREADFUNC)(void *);<br />
bool CreateNewThread(void);<br />
bool CreateNewThread(PTHREADFUNC pThreadFunc);<br />
bool Wait();
bool Suspend();
bool Resume();
bool Kill();
bool IsActive();
<br />
virtual void ThreadEntry(){ }<br />
virtual void ThreadExit(){ }<br />
virtual void ThreadRun(){ }<br />
<br />
static UINT WINAPI _ThreadFunc(LPVOID pParam);<br />
<br />
public:<br />
HANDLE m_hThread;
UINT uiThreadId;
<br />
bool m_bActive;
DWORD m_lpId;
};<br />
The main loop classes header.
<br />
<br />
class mainloop : public LENZE_8200_MOTION, private ClxThread<br />
{<br />
public:<br />
mainloop();<br />
~mainloop();<br />
<br />
void Start(void){ CreateNewThread( ); };
<br />
protected: <br />
<br />
void init_mc362X(void);<br />
bool read_mc362x(void);<br />
bool read_lenze_cfg_sheet(void);<br />
bool read_independencer( void );<br />
<br />
private: <br />
void ThreadRun(void); <br />
<br />
MC362X_MOTION isacard;
<br />
ClxUdp cmd_socket;
ClxUdp data_socket;
<br />
bool isRaising;<br />
void Raise(void);<br />
bool Balance_A( double position );<br />
void Balance_B(void);<br />
void init_lift(void);<br />
void lift(void);<br />
<br />
private:<br />
bool m_bBalanced;<br />
char m_cStateCurrent;<br />
char m_cStateLast;<br />
bool m_bDown;<br />
bool m_bEStop;<br />
bool m_bPortUp;<br />
bool m_bStarboard;<br />
bool m_bCanopyOpen;<br />
bool m_bUp;<br />
char m_cCommand; <br />
<br />
};<br />
The Poll classer headers
<br />
class LENZE_8200_MOTION : public ClxThread, protected CLX_LENZE_8200<br />
{<br />
public:<br />
LENZE_8200_MOTION(void);<br />
~LENZE_8200_MOTION(void);<br />
<br />
public:<br />
bool init_lenze8200( int comm_port, int baud_rate, long timeout_ms, int maxtxfailures );<br />
bool start_lenze8200(void){ return CreateNewThread(); }<br />
<br />
void pitch_set_address( char address ){ return SetAddress( &pitch_axis_data, address ); };<br />
char pitch_get_address( void ){ return GetAddress( &pitch_axis_data ); }<br />
<br />
}<br />
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
My 2 cents...
From the sound of the class names involved -
If you think in terms of "is a..." and "has a..." where "is a..." means you derive from and "has
a..." means you have a member object, it sounds like Poll_LenzeInvertors doesn't need to BE a
thread object but needs to HAVE a thread object.
The same with mainloop - is mainloop a poll object, or does it need to have a poll object.
Maybe something to think about in the design. If not, simply ignore
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Mark,
I think you are right, I am thinking I need stop inheriting a ClxThread and declare a clxthread object within the mainloop and poll_lenze class. However, I have been struggling to pass a void ThreadFunc(void) into CreateNewThread(PTHREADFUNC pThreadFunc); which turns the function ThreadFunc into working thread/function. However, if i create a function in mainloop like this static UINT WINAPI MaintainingThreadProc(LPVOID pParam); and pass it into CreateNewThread(PTHREADFUNC pThreadFunc) Than, MaintainingThreadProc() function becomes a worker thread. I really would like to just pass the stardard void ThreadFunc(void) function prototype if possible.
class ClxThread<br />
{<br />
public:<br />
ClxThread();<br />
virtual ~ClxThread();<br />
<br />
typedef unsigned (__stdcall *PTHREADFUNC)(void *);<br />
bool CreateNewThread(void);<br />
bool CreateNewThread(PTHREADFUNC pThreadFunc);<br />
bool Wait();
bool Suspend();
bool Resume();
bool Kill();
bool IsActive();
<br />
virtual void ThreadEntry(){ }<br />
virtual void ThreadExit(){ }<br />
virtual void ThreadRun(){ }<br />
<br />
static UINT WINAPI _ThreadFunc(LPVOID pParam);<br />
<br />
public:<br />
HANDLE m_hThread;
UINT uiThreadId;
<br />
bool m_bActive;
DWORD m_lpId;
};<br />
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
ScotDolan wrote: I am thinking I need stop inheriting a ClxThread and declare a clxthread object within the mainloop and poll_lenze class.
Maybe Whatever is best for your design. I suppose since mainloop and poll_lenze both have
associated threads, they could each derive from ClxThread, but mainloop, then, shouldn't be
derived from poll_lenze since mainloop is not a poll_lenze.
ScotDolan wrote: if i create a function in mainloop like this static UINT WINAPI MaintainingThreadProc(LPVOID pParam); and pass it into CreateNewThread(PTHREADFUNC pThreadFunc)
I'm not sure how you've implemented your ClxThread class, but from the header info,
CreateNewThread(PTHREADFUNC pThreadFunc) needs as a parameter a pointer to a function declared as
unsigned __stdcall func(void *). You shouldn't be able to pass a pointer to a function declared
as UINT WINAPI MaintainingThreadProc(LPVOID pParam).
Since you've put a nice little wrapper around a thread, I'm not sure why you need to pass a
thread proc in...
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
ScotDolan wrote: However, I have been struggling to pass a void ThreadFunc(void) into CreateNewThread(PTHREADFUNC pThreadFunc); which turns the function ThreadFunc into working thread/function.
Why would you do that. Wouldn't a thread class encapsulate the HANDLE and the Thread function?
led mike
|
|
|
|
|
The purpose of the thread class is to make simple functions that consolidate, hide all the mondain task that need to be performed to start, kill, suspend, resume, a thread. The object is to try to prevent any Operating System specific code from getting into the my mainloop and poll-lenze code. This will make it easier for me to port the code over to Linux, Unix or any other os that supports C++. This is why the i use ThreadEnter(),ThreadRun(), and ThreadExit() can all be override. Because, ThreadEnter(),ThreadRun(), and ThreadExit() get called in the worker thread. other object is to keep the create a spreate function where the thread code goes.
The end results is that when it comes time to port the code over to a new Os, i should only have to rewrite ClxThread.
<br />
#pragma once<br />
<br />
<br />
class ClxThread<br />
{<br />
public:<br />
ClxThread();<br />
virtual ~ClxThread();<br />
<br />
typedef unsigned (__stdcall *PTHREADFUNC)(void *);<br />
bool CreateNewThread(void);<br />
bool CreateNewThread(PTHREADFUNC pThreadFunc);<br />
bool Wait();
bool Suspend();
bool Resume();
bool Kill();
bool IsActive();
<br />
virtual void ThreadEntry(){ }<br />
virtual void ThreadExit(){ }<br />
virtual void ThreadRun(){ }<br />
<br />
static UINT WINAPI _ThreadFunc(LPVOID pParam);<br />
<br />
public:<br />
HANDLE m_hThread;
UINT uiThreadId;
<br />
bool m_bActive;
DWORD m_lpId;
};<br />
#include "stdafx.h"<br />
#include ".\ClxThread.h"<br />
#include <process.h><br />
<br />
<br />
ClxThread::ClxThread()<br />
{<br />
m_hThread = NULL; <br />
m_bActive = false;<br />
uiThreadId = NULL;<br />
}<br />
<br />
<br />
ClxThread::~ClxThread()<br />
{<br />
Kill();<br />
}<br />
<br />
bool ClxThread::CreateNewThread(PTHREADFUNC pThreadFunc)<br />
{<br />
if( m_hThread == NULL )<br />
{<br />
<br />
<br />
<br />
m_hThread = (HANDLE)_beginthreadex(NULL, 0, pThreadFunc, this, CREATE_SUSPENDED, &uiThreadId);
<br />
if ( NULL != m_hThread)<br />
{<br />
ResumeThread( m_hThread );<br />
m_bActive = true;<br />
return true;<br />
}else{<br />
m_bActive = false;<br />
<br />
}<br />
}<br />
<br />
return true;<br />
}<br />
<br />
bool ClxThread::CreateNewThread(void)<br />
{<br />
if( m_hThread == NULL )<br />
{<br />
<br />
<br />
<br />
m_hThread = (HANDLE)_beginthreadex(NULL, 0, _ThreadFunc, this, CREATE_SUSPENDED, &uiThreadId);
<br />
if ( NULL != m_hThread)<br />
{<br />
ResumeThread( m_hThread );<br />
m_bActive = true;<br />
return true;<br />
}else{<br />
m_bActive = false;<br />
<br />
}<br />
}<br />
<br />
return true;<br />
}<br />
<br />
<br />
bool ClxThread::Suspend(void)<br />
{<br />
m_bActive = false;<br />
return (-1 != SuspendThread(m_hThread));
}<br />
<br />
<br />
<br />
bool ClxThread::Kill(void)<br />
{<br />
if( TerminateThread(m_hThread, 1) )
{<br />
m_hThread = NULL;<br />
m_bActive = false;<br />
return 1;<br />
}else{<br />
return 0;<br />
}<br />
}<br />
<br />
<br />
<br />
bool ClxThread::Resume(void)<br />
{<br />
m_bActive = true;<br />
return (-1 != ResumeThread(m_hThread));
}<br />
<br />
<br />
<br />
bool ClxThread::Wait(void)<br />
{<br />
return (WAIT_OBJECT_0 == WaitForSingleObject(m_hThread, INFINITE));<br />
}<br />
<br />
<br />
<br />
bool ClxThread::IsActive(void)<br />
{<br />
return m_bActive;<br />
}<br />
<br />
<br />
<br />
<br />
<br />
UINT WINAPI ClxThread::_ThreadFunc(LPVOID pParam)<br />
{<br />
ClxThread* pThis = reinterpret_cast<ClxThread*>( pParam );<br />
_ASSERTE( pThis != NULL );<br />
<br />
pThis->ThreadEntry();
pThis->ThreadRun();<br />
pThis->ThreadExit();
<br />
pThis->m_bActive = false;<br />
pThis->m_hThread = NULL;<br />
pThis->m_lpId = NULL;<br />
<br />
return 1L;<br />
}
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
But again, why do you need a member function that takes a function pointer as an argument if
you've encapsulated the threadproc so nicely? Your virtual functions expose derived classes to
the threadproc generically.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|