|
okay thanks but for now how can i solve this problem?
|
|
|
|
|
You cannot solve this problem until you understand the basics. If I start to tell why you should not use PeekMessage there, I'll have to explain what a worker thread is, thread synchronization, applying everything together in your program, etc., Too much of stuff to be discussed in a thread like this. You are desperately in need of a book and go buy one or two. Your program can wait until you're good enough to solve it.
And no pal, I do not feel like providing you a quick-fix. Sorry about that.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
You should sometimes (e.g. after reading of 100 data) call a function like this.
If you remove the message from the queue, you should dispatch the message. You can call PeekMessage with other filters too (e.g. for a special window or other messages). But the last call should not use any filters!
void PeekMessages()
{
MSG msg;
// check for paint-messages ...
while ( PeekMessage(&msg, NULL, WM_PAINT, WM_PAINT, PM_REMOVE) )
{ // ... and dispatch these
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// only to prevent ghost-window on vista!
// we dont use the result and let the message
// in the queue (PM_NOREMOVE)
PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
}
|
|
|
|
|
Hallo,
I need to start a timer like the following to measure the time that my appliction requires to do someting:
void CMiniClass :: DoSomething()
{
theApp.m_pMainWnd ->SetTimer (MY_TIMER,1000,NULL);
while (i > 0)
{
DoStuff();
}
//theApp.m_pMainWnd ->KillTimer (MY_TIMER);
}
in the CMainFrame.cpp i overrode the OnTimer() from the baseclass:
void CMainFrame::OnTimer(UINT nIDEvent)
{
m_bFlagStartTimer = true;
CFrameWnd::OnTimer(nIDEvent);
CString strTimer(_T(""));
m_nSeconds++;
if(m_nSeconds == 60)
{
m_nMinutes++;
m_nSeconds = 0;
}
if(m_nMinutes == 60)
{
m_nHours++;
m_nMinutes = 0;
}
if(m_nHours == 24)
{
m_nHours = 0;
}
strTimer.Format("%d:%d:%d", m_nHours, m_nMinutes, m_nSeconds);
MessageBox(strTimer,0,0);
}
the problem is the application starts the Timer(in the Messagebox) after he finished the while-loop,so i can not know how long
my appliction was BUSY with this loop, and if i activate theApp.m_pMainWnd ->KillTimer (MY_TIMER);
the Timer would be KILLED and then the while-llop starts, i need to do this without using Thread.
Please help to fix this problem. Thanks.
|
|
|
|
|
You shouldn't be using a timer here.
You should ideally get the time first, start your job, get the time again after you're job completes and then compare the first and second time.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
i used this code but the problem it starts first when the appliction has finished the job.
CFrameWnd::OnTimer(nIDEvent);
CTime timer;
CString strTimer (_T(""));
timer = CTime::GetCurrentTime ();
if(((m_nSeconds = timer.GetSecond ()) == 0) && (m_bFlagTimer == true))
{
m_nMinutes++;
}
if(((timer.GetMinute ()) == 0) && (m_bFlagTimer == true))
{
m_nHours++;
}
wsprintf((LPTSTR)strTimer.GetString (),"%02i:%02i:%02i",m_nHours, m_nMinutes, m_nSeconds);
m_wndStatusBar.SetPaneText(5,LPCSTR(strTimer.GetString ()),true
i need to count parallel to the task when it runs.
|
|
|
|
|
susanne1 wrote: I need to start a timer like the following to measure the time that my appliction requires to do someting
You're using the wrong sort of timer - the windows timer sends one of your windows a WM_TIMER message when the time you wanted has expired.
You imply you want to measure how long something took to run. They way to do that is to find the time when the activity starts, the time when it ends and determine the difference between them. I generally use the high-resolution counter[^] for that.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
i used this code but the problem it starts first when the appliction has finished the job.
CFrameWnd::OnTimer(nIDEvent);
CTime timer;
CString strTimer (_T(""));
timer = CTime::GetCurrentTime ();
if(((m_nSeconds = timer.GetSecond ()) == 0) && (m_bFlagTimer == true))
{
m_nMinutes++;
}
if(((timer.GetMinute ()) == 0) && (m_bFlagTimer == true))
{
m_nHours++;
}
wsprintf((LPTSTR)strTimer.GetString (),"%02i:%02i:%02i",m_nHours, m_nMinutes, m_nSeconds);
m_wndStatusBar.SetPaneText(5,LPCSTR(strTimer.GetString ()),true
i need to count parallel to the task when it runs.
|
|
|
|
|
There is no point reposting the same code. there was an answer given by somebody. try that out. if you get stuck as again. you will get assistance
|
|
|
|
|
What you want to do is something like this (using code from you original post):
void CMiniClass :: DoSomething()
{
LARGE_INTEGER startTime, endTime;
QueryPerformanceCounter(&startTime);
while (i > 0)
{
DoStuff();
}
QueryPerformanceCounter(&endTime);
LARGE_INTEGER elapsedTime;
elapsedTime.QuadPart = endTime.QuadPart - startTime.QuadPart;
LARGE_INTEGER timerFreq;
QueryPerformanceFrequency(&timerFreq);
const double elapsedTimeInSeconds = (double)elapsedTime.QuadPart / (double)timerFreq.QuadPart;
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
hello all ,
I am writing student info on file by following way..
Struct Student
{
int Marks;
int RollNo;
};
Student Sobj;
int main()
{
//then i create file using ,CreateFile( ....);
//I store data for 10 student
for(int i=0;i<10;i++)
{
Sobj.Marks=10*i;
Sobj.RollNo=i;
WriteFile ( HandleFile , &sobj , sizeof ( struct Student ) ,...,...);
}
CloseHandle( ..) ;
}
--------------------------
This code work proper .
Then I read that data using ReadFile(Handle,&sobj,....) it also work
-----------------------------------
Now My problem is I am reading that file on some condition i want to change data of students eg. for roll no 3 marks 80;
how should i do this .
means i am reading and on some condition i have to Use WrteFile()
i try using SetFilePointer But i was not able to do that ,,how to go back in file.
Thanks All
Ashish P.
|
|
|
|
|
ashish8patil wrote: means i am reading and on some condition i have to Use WrteFile()
i try using SetFilePointer But i was not able to do that ,,how to go back in file.
Don't do this. A much better (and probably easier) way is to write the full file once again. The problem is that when writing you are not able to insert new characters. Which means that if your entry was 9 (1 character) before and has to be overwritten by 10 (2 characters), this is not possible.
So, when open the file for reading, specifying that the contents should be cleared and then write your full structure again.
|
|
|
|
|
Thanks for your reply
I just give you student as example ,but my data is very large and it may be very long way ,store that data in buffer n all..
|
|
|
|
|
SetFilePointer is the correct way to do it.
Before that you must open the file as GENERIC_READ|GENERIC_WRITE since you want to do both.
Each record in your case will take up sizeof(Student) bytes.
So it is just a matter of multiplication to find the offset of the record to modify.
So do a SetFilePointer to that offset with move method as FILE_BEGIN .
Then do a WriteFile with the new record.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
i also try to do same but it was not write there plz see code
ServerHandle = CreateFile ( L"server.dat" ,
GENERIC_READ | GENERIC_WRITE ,
FILE_SHARE_WRITE ,
NULL ,
OPEN_EXISTING ,
0 ,
NULL ) ;
if ( ServerHandle == INVALID_HANDLE_VALUE )
{
return ( 1 ) ;
}
ReadFile ( ServerHandle , & finfo , sizeof ( struct ServerFileInfo ) , &BytesRead , NULL ) ;
FilePointer.QuadPart =-sizeof(UpdateInfoOnServer);
for (i=0;i<finfo.NoUpdates ;i++)
{
ReadFile ( ServerHandle , & UpdateInfo , sizeof ( struct UpdateInfoOnServer ) , &BytesRead , NULL ) ;
if((UpdateInfo.IsApproved==1)&&(UpdateInfo.IsDownloaded==0) )
{
for(j=0;j<UpdateInfo.NumberOfPatches ;j++)
{
PatchFileID=UpdateInfo.PatchFileID[j] ;
iTmp=DownloadByPatchFileID();
if(iTmp==1)
{
return 1;
}
}
UpdateInfo.IsDownloaded=1;
SetFilePointerEx ( ServerHandle , FilePointer, NULL , FILE_CURRENT ) ;
WriteFile ( ServerHandle , & UpdateInfo , sizeof ( struct UpdateInfoOnServer ) , &BytesWritten , NULL ) ;
}
}
/////////////////////////////////////////////
where i make mistake..plz tell
|
|
|
|
|
You should be using your debugger here.
Set a breakpoint and single step through the code.
You'll surely catch the error.
And also you need to check return values of those APIs that you're calling.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
but logically are this things correct?
LARGE_INTEGER FilePointer ;
FilePointer.QuadPart =-sizeof(UpdateInfoOnServer);
SetFilePointerEx ( ServerHandle , FilePointer, NULL , FILE_CURRENT ) ;
|
|
|
|
|
as Cedrice said, unless you are going to have many people modifying the data at once; in which case you should store all the data in a database, and not worry about files at all.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
ashish8patil wrote: SetFilePointer
That sounds about right. Maybe you can tell us why you weren't able to use that? Because the following program, based on your (syntactically incorrect) code fragments, compiles and runs successfully. Here's a hint - check function returns values and GetLastError[^].
#include <Windows.h>
struct Student
{
int Marks;
int RollNo;
};
struct Student sobj;
int main()
{
HANDLE hFile = CreateFile("a.a", GENERIC_READ|GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
for(int i=0;i<10;i++)
{
sobj.Marks=10*i;
sobj.RollNo=i;
DWORD written;
WriteFile ( hFile , &sobj , sizeof ( sobj ) , &written, 0);
}
int i = 3;
sobj.Marks=5*i;
sobj.RollNo=i;
SetFilePointer(hFile, sizeof(sobj)*i, 0, FILE_BEGIN);
DWORD written;
WriteFile ( hFile , &sobj , sizeof ( sobj ) , &written, 0);
CloseHandle(hFile) ;
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi guys,
I am developing a MDI application (VS-2008) using dockable panes. mostly things are working fine but there is a problem when the pane is set to Autohide.
As it hides it, if there are more than one panes there autohidded, only the caption of one which is active, apears and the icon of all other apear. I think i did somthing wrong when creating the pane or i'll need to set its some property but have no idea.
Please help
Thanks in advance
Harsh Shankar
|
|
|
|
|
hello,
i want to copy the content of ip control and add it to a list control. so try to do this ----
void Cserver_side_mfcDlg::OnBnClickedOk2()
{
BYTE m_M1, m_M2, m_M3, m_M4;
DWORD s = 0;
char ss[20] = {0};
UpdateData();
m_ipAdd.GetAddress(m_M1, m_M2, m_M3, m_M4);
m_ipList.InsertItem(s++, LPCTSTR(m_M1));
}
it compiles without any error but when i run it and click ok, it shows the error ---
Unhandled exception at 0x746bc348 in server_side_mfc.exe: 0xC0000005: Access violation reading location 0x00000017.
i also tried ----
void Cserver_side_mfcDlg::OnBnClickedOk2()
{
BYTE m_M1, m_M2, m_M3, m_M4;
DWORD s = 0;
char ss[20] = {0};
UpdateData();
m_ipAdd.GetAddress(m_M1, m_M2, m_M3, m_M4);
sprintf_s(ss, "%s:%s:%s:%s", m_M1, m_M2, m_M3, m_M4);
m_ipList.InsertItem(s++, (LPCTSTR)ss);
}
error ---
Unhandled exception at 0x5cd3e9ee (msvcr90d.dll) in server_side_mfc.exe: 0xC0000005: Access violation reading location 0x0000006f.
i also tried something like this which is working without any problem ----
void Cserver_side_mfcDlg::OnBnClickedOk2()
{
BYTE m_M1, m_M2, m_M3, m_M4;
DWORD s = 0;
char ss[20] = {0};
UpdateData();
m_ipAdd.GetAddress(m_M1, m_M2, m_M3, m_M4);
m_ipList.InsertItem(s++, _T("ABC"));
}
please help.
|
|
|
|
|
rahuljin wrote: void Cserver_side_mfcDlg::OnBnClickedOk2()
{
BYTE m_M1, m_M2, m_M3, m_M4;
DWORD s = 0;
char ss[20] = {0};
UpdateData();
m_ipAdd.GetAddress(m_M1, m_M2, m_M3, m_M4);
sprintf_s(ss, "%s:%s:%s:%s", m_M1, m_M2, m_M3, m_M4);
m_ipList.InsertItem(s++, (LPCTSTR)ss);
}
You cannot simply typecast a char to LPCTSTR.
So use TCHAR ss[20] instead.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
thanks. but then how will i use ---
sprintf_s(ss, "%s:%s:%s:%s", m_M1, m_M2, m_M3, m_M4);
|
|
|
|
|
_stprintf_s(ss, _T("%d:%d:%d:%d"), m_M1, m_M2, m_M3, m_M4);
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Hello! I've developed an MFC application with VC++6.0. It still works for Vista32, but when I try to move a file to the recycle bin using SHFileOperation on Vista64 then I get the error code 120(ERROR_CALL_NOT_IMPLEMENTED). I know for Vista I should use IFileOperation, but I'm still using VC++6.0. Is there any way to move files to the recycle bin on Vista64 using VC++6.0?
Kind regards
Marcus
|
|
|
|
|