|
nibabug wrote: SetTimer(1,500,NULL);
What are you doing in response to the WM_TIMER message?
"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
|
|
|
|
|
get data from three different tables , and then do something , and then show them, look the flowing:
void CSerialRecieveDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CString strSql;
// int m=atoi(m_strNum);
_variant_t var;
CString str,strnum;
CString strSendFW,strSendFY,strSendQX;
CString strSend;
str="";
SQLNum++;
if(SQLNum==130)
SQLNum-=129;
strSql.Format("%d",SQLNum);
strnum=strSql;
strSql.Format("SELECT * FROM TB_FANGWEI WHERE ID = '%s'",strnum);
try
{
//先关闭已经打开的记录集对象
m_pRecordset->Close();
//根据新的Sql查询语句,重新打开记录集对象
m_pRecordset->Open(strSql.AllocSysString(),
theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
//在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
//因为它有时会经常出现一些想不到的错误。
var = m_pRecordset->GetCollect("Value");
if(var.vt != VT_NULL)
str = (LPCSTR)_bstr_t(var);
m_strAGFW=str;
var = m_pRecordset->GetCollect("HexValue");
if(var.vt != VT_NULL)
str = (LPCSTR)_bstr_t(var);
strSendFW=str;
// char* pszTest = (char*)(LPCTSTR)strSendFW;
// unsigned char* ptr=(unsigned char*)pszTest;
// unsigned char uchartemp;
// unsigned char m=4;
unsigned int intFW=(unsigned int)_tcstoul(strSendFW, 0, 16);
intFW&=0x3fff;
intFW<<=2;
intFW|=0x0000;
strSql.Format("SELECT * FROM TB_FUYANG WHERE ID = '%s'",strnum);
try
{
//先关闭已经打开的记录集对象
m_pRecordset->Close();
//根据新的Sql查询语句,重新打开记录集对象
m_pRecordset->Open(strSql.AllocSysString(),
theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
var = m_pRecordset->GetCollect("Value");
if(var.vt != VT_NULL)
str = (LPCSTR)_bstr_t(var);
m_strAGFY=str;
var = m_pRecordset->GetCollect("HexValue");
if(var.vt != VT_NULL)
str = (LPCSTR)_bstr_t(var);
strSendFY=str;
unsigned int intFY=(unsigned int)_tcstoul(strSendFY, 0, 16);
intFY&=0x3fff;
intFY<<=2;
intFY|=0x0001;
SQLNumQX++;
if(SQLNumQX==458)
SQLNumQX-=457;
strSql.Format("%d",SQLNum);
strnum=strSql;
strSql.Format("SELECT * FROM TB_QINGXIE WHERE ID = '%s'",strnum);
try
{
//先关闭已经打开的记录集对象
m_pRecordset->Close();
//根据新的Sql查询语句,重新打开记录集对象
m_pRecordset->Open(strSql.AllocSysString(),
theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
var = m_pRecordset->GetCollect("Value");
if(var.vt != VT_NULL)
str = (LPCSTR)_bstr_t(var);
m_strAGQX=str;
var = m_pRecordset->GetCollect("HexValue");
if(var.vt != VT_NULL)
str = (LPCSTR)_bstr_t(var);
strSendQX=str;
unsigned int intQX=(unsigned int)_tcstoul(strSendQX, 0, 16);
intQX&=0x3fff;
intQX<<=2;
intQX|=0x0002;
strSend="";
// strSend+="$";
str.Format("%4x",intFW);
strSend+=str;
str.Format("%4x",intFY);
strSend+=str;
str.Format("%4x",intQX);
strSend+=str;
// CString m_str;
unsigned int crc;
unsigned char* ptr;
unsigned char len;
str=strSend;
char* pszTest = (char*)(LPCTSTR)str;
ptr=(unsigned char*)pszTest;
len=str.GetLength();
crc=0;
crc=ban_crc(ptr,len);//计算校验值
strSend.Format("$");
strSend+=str;
// str=m_sSendData;
// m_str+=str;
str.Format("*");
strSend+=str;
str.Format("%04x",crc);
strSend+=str;
m_ctrlMSCommCOM1.SetOutput(COleVariant(strSend));//发送数据
UpdateData(FALSE);
// m_AccessList.AddString( strName + " --> "+strAge );
// m_pRecordset->MoveNext();
CDialog::OnTimer(nIDEvent);
}
wuhuaiji
|
|
|
|
|
You are doing WAY too much in response to a WM_TIMER message that occurs every 1/2 second.
"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
|
|
|
|
|
|
What, pray tell, are you finding amusing?
"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
|
|
|
|
|
it was just obvious, but i loved the way you said it
|
|
|
|
|
it has no businiss with the timer, because when i change it to 2second, it also appear error:
(step debug)
unhandled exception in SerialRecieve.exe(KERNEL32.DLL):0xE06D7363:Microsoft C++ EXCEPTION
no matter where the error appears, it appears always in the CSerialRecieveDlg::OnTimer(UINT nIDEvent)
wuhuaiji
|
|
|
|
|
nibabug wrote: it has no businiss with the timer...it appears always in the CSerialRecieveDlg::OnTimer(UINT nIDEvent)
Do you see the irony in this statement? Yes, the timer is the problem. Changing the frequency to 2 seconds won't necessarily solve the problem if it takes longer than that to process a single WM_TIMER request. Put a flag in the function indicating whether it is busy or not. Check that flag before continuing.
"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
|
|
|
|
|
It's not just the timer - a thread hosting Windows UI can only process one message at a time, after all. The problem is that the MessageBox call and the modal dialog create nested message loops, which will process timer messages and thereby cause recursion.
Most likely it's one of the AfxMessageBox calls in the exception handlers in the OnTimer routine which is causing OnTimer to go re-entrant.
DoEvents : Generating unexpected recursion since 1991
|
|
|
|
|
thanks a lot
wuhuaiji
|
|
|
|
|
Try single stepping through your code in the debugger, it should be obvious then.
|
|
|
|
|
Hello!
I am trying to monitor the hard drive LED via a program I am writing in C++ for Windows XP. I just need to know if the light is on/off (the hard drive running). The user will not be able to see the light because of the placement of the computer & we cannot crack open the computer to wire it someplace else because of warranty issues. I need to incorporate it directly into a program I am writing - I cannot use any off the shelf program to show me the LED in the corner of the windows page because my custom display will take up the whole screen.
Any suggestions of how to get to status of the hard drive LED from my c++ program?
Thanks!
Margaret
|
|
|
|
|
Why don't you just monitor disk activity itself, rather than mess with the LED (which is probably not accessible anyway)?
"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
|
|
|
|
|
Mine is not question .. I just the worker bee. They want to mimick the light for the panel I am creating. If there is another way to monitor that the hard drive is being used/written to - am way open to suggestions!
Thanks
|
|
|
|
|
isikorsky91 wrote: They want to mimick the light
Since the LED is just blinking in unison with disk activity, your panel can do the same thing.
isikorsky91 wrote: If there is another way to monitor that the hard drive is being used/written to - am way open to suggestions!
A device driver is the only way.
"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
|
|
|
|
|
Can you point me to any examples ? I am not clear on what you are referring to here. I have scoured the internet for hooks into windows to program into the code to monitor hard drive activity and come up with nothing ..
|
|
|
|
|
isikorsky91 wrote: Can you point me to any examples ?
See here and here.
"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
|
|
|
|
|
Thanks .. but
I don't see how I can use DiskMon in my code since it is a precompiled program. The other option see a little beyond my scope of what I was looking for.. I was just looking for a simpler call to windows to find out if there is hard disk activity...
Guess I am missing what you are pointing out..
Thanks
|
|
|
|
|
isikorsky91 wrote: I don't see how I can use DiskMon in my code since it is a precompiled program.
I never indicated you could. It was merely for you to read on how it was done, and the complexity involved.
isikorsky91 wrote: Guess I am missing what you are pointing out..
Did you read this:
Windows 2000 and Higher Implementation
On Windows 2000 and higher, Diskmon uses kernel event tracing. Event tracing is documented in the Microsoft Platform SDK and the SDK contains source code to TraceDmp, on which Diskmon is based.
"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
|
|
|
|
|
How to draw a table on a dialog in VC++ ??? I'm a newbie.....
Thnk u
|
|
|
|
|
gReaen wrote: How to draw a table...
That depends on what you mean by "table." There is a multicolumn list control, and a grid control that can be placed on a dialog, but not a table.
"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
|
|
|
|
|
|
you can add flexgrid from project>addtoproject>components and controls>registered Active X components
Suggestion to the members:
prefix your main thread subject with [SOLVED] if it is solved.
chandu.
|
|
|
|
|
how can i use constant member varible in simple class?
I want ot use it as private.
Thanks...
|
|
|
|
|
ashishbhatt wrote: how can i use constant member varible in simple class?
class ConstantTest
{
ConstantTest() : m_SomeConstant( 10 )
{}
private:
const int m_SomeConstant;
enum { AnotherConstant = 20 };
};
Nibu thomas
MVP For VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http:\\nibuthomas.wordpress.com
|
|
|
|