|
void CCash3mfcDlg::Ongobutton()
{
THREADSTRUCT *_param = new THREADSTRUCT;
_param->_this = this;
AfxBeginThread (StartThread, _param);
UpdateData(TRUE);
}
put it this way _param->_this = GetSafeHwnd();
and in the Run() proc
CYourDialog *pYourDlg;
*pYourDlg = (CYourDialog*)CWnd::FromHandle("the hwnd that was saved in the _param");
This space is empty.
|
|
|
|
|
I put this in and of course it doesn't work what am I doing wrong now.
errors i get:
C:\Downloads\cash3 mfc\cash3 mfcDlg.cpp(254) : error C2440: '=' : cannot convert from 'struct HWND__ *' to 'class CCash3mfcDlg *'
C:\Downloads\cash3 mfc\cash3 mfcDlg.cpp(268) : error C2065: '_param' : undeclared identifier
Error executing cl.exe.
cash3 mfc.exe - 2 error(s), 0 warning(s)
Thanks for your patience,
tony
void CCash3mfcDlg::Ongobutton() <br />
{<br />
<br />
THREADSTRUCT *_param = new THREADSTRUCT;<br />
_param->_this = GetSafeHwnd();<br />
<br />
<br />
AfxBeginThread (StartThread, _param);<br />
UpdateData(TRUE);<br />
<br />
<br />
<br />
<br />
}<br />
<br />
int CCash3mfcDlg::run()<br />
{<br />
CCash3mfcDlg *pdlg;<br />
pdlg = (CCash3mfcDlg*)CWnd::FromHandle(_param); <br />
<br />
<br />
m_processstatus.SetPos(0);<br />
<br />
<br />
AfxEndThread(0);<br />
CWnd::MessageBox("THREAD IS DONE");<br />
pdlg.UpdateData(FALSE);<br />
<br />
<br />
<br />
return 0;<br />
}<br />
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
win32newb wrote:
_param->_this = GetSafeHwnd();
_this is defined as CCash3mfcDlg* make it HWND
pdlg = (CCash3mfcDlg*)CWnd::FromHandle(_param);
change it to
pdlg = (CCash3mfcDlg*)CWnd::FromHandle(_param->_this);
This space is empty.
|
|
|
|
|
THANKs for you help. that cleared that error but now i get one more
it says run() is not a member of HWND which its not. its a member of CCASH3MFCDLG
I tried changing ts->_this->run(); to the following
CCash3mfcDlg::run();
and i get an error
C:\Downloads\cash3 mfc\cash3 mfcDlg.cpp(239) : error C2352: 'CCash3mfcDlg::run' : illegal call of non-static member function
i tried this as well
typedef struct ANOTHERTHREAD //structure for passing to the controlling function
{
CCash3mfcDlg* _this;
} ANOTHERTHREAD;
and then
ANOTHERTHREAD* ts = (ANOTHERTHREAD*)param;
it compiled with no errors but as soon as i start the thread it crashes
Win32newb
if (user=="Win32newb")
{
CWnd::Messagebox
("DUH");
}
ELSE
{
CWnd::Messagebox
("HELP WIN32NEWB");
}
"Making windows programs worse than they already are"
|
|
|
|
|
In the first case dont say ts->_this->run();
in the thread we had recreated the dialog pointer
CMyDialog *pDlg;
pDlg = (CMyDialog*)CWnd::FromHandle(ts->_this);
remember ?
now do this
pDlg->Run();
This space is empty.
|
|
|
|
|
I know i'm bugging you and i'm really sorry. its still not working correctly it compiles but still crashes when i run the thread.
again sorry to be a pest,
tony
here is what i currently have;
UINT CCash3mfcDlg::StartThread(LPVOID param)
{
THREADSTRUCT *_param = new THREADSTRUCT;
CCash3mfcDlg *pdlg;
pdlg = (CCash3mfcDlg*)CWnd::FromHandle(_param->_this);
pdlg->run();
//here is the time-consuming process which interacts with your dialog
return 1;
}
void CCash3mfcDlg::Ongobutton()
{
THREADSTRUCT *_param = new THREADSTRUCT;
_param->_this =GetSafeHwnd();
AfxBeginThread (StartThread, _param);
UpdateData(TRUE);
}
int CCash3mfcDlg::run()
{
counter = 0;
bool win=false;
stop=false;
int random1,random2,random3;
m_processstatus.SetRange (1, 10000);
while (stop==false&&win==false)
{
m_win=counter;
Sleep(50);
random1 = rand()%5;
random2 = rand()%5;
random3 = rand()%5;
switch (random1)
{
case 0:
m_ball1.SetIcon(m_h0);
break;
case 1:
m_ball1.SetIcon(m_h1);
break;
case 2:
m_ball1.SetIcon(m_h2);
break;
case 3:
m_ball1.SetIcon(m_h3);
break;
case 4:
m_ball1.SetIcon(m_h4);
break;
}
switch (random2)
{
case 0:
m_ball2.SetIcon(m_h0);
break;
case 1:
m_ball2.SetIcon(m_h1);
break;
case 2:
m_ball2.SetIcon(m_h2);
break;
case 3:
m_ball2.SetIcon(m_h3);
break;
case 4:
m_ball2.SetIcon(m_h4);
break;
}
switch (random3)
{
case 0:
m_ball3.SetIcon(m_h0);
break;
case 1:
m_ball3.SetIcon(m_h1);
break;
case 2:
m_ball3.SetIcon(m_h2);
break;
case 3:
m_ball3.SetIcon(m_h3);
break;
case 4:
m_ball3.SetIcon(m_h4);
break;
}
if (m_ticket1==random1&&m_ticket2==random2&&m_ticket3==random3)
{
win=true;
}
m_processstatus.StepIt ();
counter++;
}
m_processstatus.SetPos(0);
UpdateData(FALSE);
m_win = counter;
UpdateData(TRUE);
AfxEndThread(0);
CWnd::MessageBox("THREAD IS DONE");
return 0;
}
Win32newb
if (user=="Win32newb")
{
CWnd::Messagebox
("DUH");
}
ELSE
{
CWnd::Messagebox
("HELP WIN32NEWB");
}
"Making windows programs worse than they already are"
|
|
|
|
|
Thats where i'm confused. I would assume its an mfc object. if i can't pass it then how do i make it update after the thread is finished? once run completes then it stops.
if have a button onstatbutton()
void CCash3mfcDlg::Onstatbutton()
{
UpdateData(TRUE);
}
then it will update the edit box with the correct value;
so how do i make it either call a function after the thread breaks or whatever?
I even tried putting a call to the onstatbutton() after the while in run(). that didn't work either.
I'm very new to threads and mfc so my question is probably juvenile but i haven't a clue how to fix it.
P.s. I have programming windows 95 by petzold but i find that the code doesn't work unless you use this mak file that is c not c++ is there a good book that explains the win32 api for C++ USERS? AND YES I realize that c++ is c with classes. thats not the point.
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
Define a custom message such as:
#define UWM_THREAD_DONE WM_APP At the end of the thread function, post that message to the main window (you can pass the HWND to the thread, and then post to that handle). The handler for that message can then call UpdateData()
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
There is a saying in statistics that a million monkeys pounding on typewriters would eventually create a work of Shakespeare. Thanks to the Internet, we now know that this is not true.
|
|
|
|
|
I have read what your said over and over but i'm too green at this to understand how to do it.
any examples anywhere on this very subject so i can get an idea of whats going on?
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
Hey all.
I've been trying to build a small application that does communication from my PC via the comm port (I have the protocol for my HDTV receiver and want to build a little remote control app to change the channels and such)
I don't seem to have any luck whatsoever how to go about doing this. I can make it work in VC 6 and VB using the MS COMM controls, but for some reason, when I try to bring in the MS COMM controls in VC .NET 2003, it does not create the class correctly like it does in VC 6. I tried creating the project in VC 6, making it work, and then opening it up in VC .NET 2003. It compiles fine, but then crashes immediately upon running it.
I can't find any articles on how to do this (that actually work), if someone could point me in the right direction, I would be very thankful. I've been playing with this for two days now and am getting frustrated with myself at this point! I would also like to be able to fire off another thread that sits and waits for communication to come in from the comm port as well. (So I can keep up-2-date information on my program about which channel is currently active on the receiver)
PS: I have other code that is dependant on VC 2003 that I want to tie into this project, which is why I do not want to simply build it in VB or VC 6
Any help would be appreciated.
|
|
|
|
|
I dont use VC.NET just plain V6.00 I look at these
http://www.codeproject.com/system/serial_com.asp?target=Serial%7CPort
there are a lot of examples of how to use the serial port, in the end you just use it the same as reding and writing files.
|
|
|
|
|
I have an iterator that is pointing to a certain element. I want to overwrite this element with the next one following it.
*I is the current element. But if I do ++I to get to the next element I lose my place....
I dont think *I = *(++I) is quite going to do it. (what would this do anyways? )
thanks,
ns
|
|
|
|
|
|
|
Or: *I = *(I + 1);.
--
Unser Tanz ist so wild! Ein neuer böser Tanz.
Alle gegen Alle!
|
|
|
|
|
Only if I is a random-access iterator.
|
|
|
|
|
Yes, you are right. I thought forward iterator would be ok. I guess one will have to use std::advance instead then. But I'll have to copy the iterator, as std::advance mutates the iterator (passed by reference)
But I guess one could always do
template <typename Iterator, typename Distance>
Iterator my_advance(const Iterator& i, Distance d) {
Iterator tmp = i;
std::advance(tmp, d);
return tmp;
} and then
*I = *(my_advance(I, 1)); If the compiler is smart and inlines the function, there's no overhead penalty.
--
Unser Tanz ist so wild! Ein neuer böser Tanz.
Alle gegen Alle!
|
|
|
|
|
This is really a newbie question, sorry about that:
What does this mean?
<br />
clock_t start, finish;<br />
double duration;<br />
<br />
duration = (double)(finish - start) / 1000; <br />
Why do we put the data type in the braces?
start and finish are clock_t data type, but
the duration is a double tpye. Is it some
kind of conversion or what?
What other situation do we also need to do that?
Thanks
|
|
|
|
|
its called as the type conversion.
Since you use the 'equal to' operator, the identifier type should follow the general rule
LHS = RHS
the lhs is long while the rhs is of type clock_t so explicitly tell the compiler to make in equal to double so the assignment is satisfied.
This type conversion is used in no of different places.
but mostly w.r.t pointers.
here is an example.
char *pChar; //pointer to charecter
int *pInt; //pointer to integer.
//assuming they are valid.
pInt = (int*)pChar; //type conversion.
another example is of malloc if you see the return type of malloc its void*. suppose you are allocating char buffer
you would write this way
char *pChar;
pChar = (char*)malloc(...); //LHS = RHS
hope i answered ur question.
This space is empty.
|
|
|
|
|
I'm a newbie, too, but this one seems straighforward enough...
Most timer functions report results in milliseconds, but this app wants a duration in seconds. It also wants the duration value to be a type double. After taking the difference of two clock_t values it divides by 1000 to convert the result to seconds, then the prefix (double) casts the clock_t result to a double type. Curiously, MSDN describes clock_t as a struct defined in TIME.H,
"clock_t structure Stores time values; used by clock. TIME.H"
but looking through TIME.H reveals,
#ifndef _CLOCK_T_DEFINED
typedef long clock_t;
#define _CLOCK_T_DEFINED
#endif /* _CLOCK_T_DEFINED */
I just love inconsistencies - they make learning this stuff so interesting.
Will Build Nuclear Missile For Food - No Target Too Small
|
|
|
|
|
It's called a cast, and in this case it converts the integral result of (finish-start) to a double . This is important because without the cast, the division would be integer division, which would lose any remainder portion.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
Pinky, are you pondering what I'm pondering?
I think so Brain, but if we shaved our heads, we'd look like weasels!
|
|
|
|
|
Now there's an interesting tidbit - the cast takes precedence over the division, eh? I learn something every time I visit here.
Will Build Nuclear Missile For Food - No Target Too Small
|
|
|
|
|
me too, and also when mike talks.
This space is empty.
|
|
|
|
|
Excellent resource, our Michael is...
Will Build Nuclear Missile For Food - No Target Too Small
|
|
|
|
|