|
«_Superman_» wrote: You can hide the console if you use CreateProcess by setting the STARTF_USESHOWWINDOW flag and SW_HIDE in the wShowwindow members of the STARTUPINFO parameter
oh thank you. i will try it now.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
iam still unable to achieve it.
the return value of CreateProcess is 0.
can you please give some clues?
thank you.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
|
I often use ShellExecuteEx (look it up to know what libraries to link.) This wraps CreateProcess in an easier to use form. I've cut and paste a modified version here.)
To execute a copy; pass "cmd.exe" as the app and "/c command" as the args. Set pDir to the dir where you want the operation to take place. Pass false for show. (The /c tells cmd.exe to execute the command and then exit.)
bool Execute(LPCTSTR pApp, LPCTSTR pArgs, bool show, LPCTSTR pDir)
{
if (!pApp)
{
SetLastError(ERROR_FILE_NOT_FOUND);
return false;
}
SHELLEXECUTEINFO execInfo;
memset(&execInfo, 0, sizeof(execInfo));
execInfo.cbSize = sizeof(execInfo);
execInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
execInfo.lpFile = pApp;
execInfo.lpParameters = pArgs;
execInfo.nShow = show ? SW_SHOW : SW_HIDE;
char path[MAX_PATH];
if (pDir)
{
execInfo.lpDirectory = pDir;
}
else
{
lstrcpyn(path, pApp, MAX_PATH);
if (PathRemoveFileSpec(path))
{
if (path[0])
execInfo.lpDirectory = path;
}
}
if (execInfo.lpDirectory && !DTDirExists(execInfo.lpDirectory))
{
SetLastError(ERROR_PATH_NOT_FOUND);
return false;
}
if (!ShellExecuteEx(&execInfo))
return false;
if (execInfo.hProcess)
CloseHandle(execInfo.hProcess);
return true;
}
modified on Tuesday, August 4, 2009 11:15 AM
|
|
|
|
|
thank you,
i would try your logic also.
thanks again.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
Why does the statement:
printf("This is Raza. \r Who are you? ");
gives the following output.
Who are you?
What effect does the carriage return makes on the text to be printed out?
|
|
|
|
|
i think ,
carriage return(\r) brings the control to the 1st column and linefeed (\n) takes it to the new line.
so u should use \r\n
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
Add a new line to it.
printf("This is Raza. \r\n Who are you? ");
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Someone has down-voted you both. I balanced it... Probably you were suggesting \r\n, while it should have been \n ?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
thank you.
but, AFAIK, while using normal printf, \r\n and \n does the same. but for some consoles like(hyperterminal for example) what i have observed is
using only \n gives the output somehting like
hello
.....world
so i felt using both would be a standard way.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
modified on Monday, June 29, 2009 7:41 AM
|
|
|
|
|
\r brings the carriage back to the beginning of the current line (without inserting a line feed) and that erases the existing text. To understand what I mean, try this:
printf("ABCDEFGHIJ \r");
To solve this, use \n instead of \r .
\n will insert a line feed and will return to the beginning of the newly inserted line.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Hallo, i have the following function in SDI-application:
void CMyClass::Myfunction()
{
CString strOutput;
LPMSG *pmsg = NULL;
for(int i = 0; i < 3000; i++)
{
::PeekMessage(NULL,NULL,0,0,PM_NOYIELD | PM_REMOVE);
strOutput.Format ("%d",i);
m_ptrOutput->SetWindowTextA (strOutput);
}
}
as you see the for-loop goes 3000 times and should print the value of i, what happens when this function starts
is the appliction FREEZ. I do not have any idea why this happens and how to solve this problem.Please help.
|
|
|
|
|
What is that magic number 3000?
Why do you want to loop 3000 times?
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
loop 3000 to get the rows from a database :
select * from DB;
|
|
|
|
|
susanne1 wrote: LPMSG *pmsg = NULL;
What is the purpose of this pointer variable? You aren't using it anywhere in your code. Not to mention LPMSG is already a pointer to a MSG structure.
void Func()
{
CString szOutput;
MSG msg;
for(int i=0; i<3000; i++)
{
PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
szOutput.Format(_T("%d"), i);
OutputDebugString(szOutput);
}
Why would you do something like this? Are you trying to understand how PeekMessage works or ... ?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
i must do it because i have over 40000 rows in the database(wher can i find a tutorial that explain how peekmessgae works??)
do not i need to intialize the msg before i use it?
i used the PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);in the loop that retrives the rows but nothing changed positively??
|
|
|
|
|
You actually are in need of a good book. For book recommendations, see here[^].
Here[^] is a good tutorial on threading. But, that can hardly help you if you don't get a good grip of the basics at first.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
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.
|
|
|
|