|
Yes,
Please help
Thanks
Preeti
Preeti9
|
|
|
|
|
Assuming it's running Windows (is it?), then you can use the standard techniques for any displayed window. For example: Use FindWindow to locate the dialog box. Periodically check if the window still exists (IsWindow). There are other methods to detect the process and when it closes provided that the process doesn't keep running after calibration is complete.
|
|
|
|
|
Hi,
Yes, its running on windows. I wrote a code that opens up the window , I mean completes calibration. Same as you said, use FindWindow to locate the dialog box. Its working properly but I don't know when does it completes the calibration. I am not able to detect when that window closes.
I don't know how to use IsWindow. Can you give me more detail on that?
Also, what other methods can you use to detect a process ?
Thanks for your help.
Waiting for more details.
Thanks
Preeti
Preeti9
|
|
|
|
|
IsWindow simply returns TRUE or FALSE if the specified window handle is a valid window or not. So, if it suddenly returned FALSE, obviously the window is no longer around.
Example:
HWND hWnd = FindWindow(....);
while( true )
{
if( ! IsWindow(hWnd) )
break;
Sleep(1000);
};
This is the quick and crude method. Find the window handle and periodically poll to see if the window still exists.
You can also do the same thing without polling by using a window hook. Lookup SetWindowsHook and CBTProc for more information.
To wait for the process to complete rather than the window. You need to get a process handle that's associated with that window and wait for it to close. This method, of course, will only work if the process doesn't live on after the window is destroyed.
Pseudo Example (error checking removed for brevity):
HWND hWnd = FindWindow(...);
DWORD ProcID;
DWORD ThrdID = 0;
HANDLE hProcess;
ThrdID = GetWindowThreadProcessId( hWnd, &ProcID );
hProcess = OpenProcess( SYNCRONIZE, FALSE, ProcID );
WaitForSingleObject( hProcess, INFINITE );
CloseHandle(hProcess);
|
|
|
|
|
Thanks for your help...
I don't know but if I use here IsWindow, I am getting the same result as I was getting it earlier.
I am sending you my code ....have a look and let me know is this correct to detect the calibration , I mean when that window closes.
Here's the code:
{
CTouchScreenAPI* pTouch;
HWND hCalWin;
DWORD procId;
HANDLE hProcess;
DWORD dwWaitResult;
pTouch = CTouchScreenAPI::Create();
if (pTouch)
{
if (pTouch->Init())
pTouch->Recalibrate(FALSE);
else
MessageBox(NULL, "Created touchscreen interface OK, but Init() failed", "Info", MB_OK);
HWND hCalWin = ::FindWindow(pszABSPOINT_WND_CLASS_NAME, NULL);
while( true )
{
if( ! IsWindow(hCalWin) )
break; // window is gone;
Sleep(1000); // wait a second for window to close
};
GetWindowThreadProcessId(hCalWin, &procId);
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procId);
while (1)
{
dwWaitResult = MsgWaitForMultipleObjects(1, &hProcess, FALSE, 30*1000, QS_PAINT);
if (dwWaitResult == WAIT_OBJECT_0 + 1)
{
MSG xMsg;
while (PeekMessage(&xMsg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&xMsg);
DispatchMessage(&xMsg);
}
}
else if (dwWaitResult == WAIT_TIMEOUT)
{
SendMessage(hCalWin, WM_CLOSE, 0, 0);
TerminateProcess(hProcess, 0);
break;
}
else dwWaitResult == WAIT_OBJECT_0;
{
//Calibration process completed;
break;
}
}
Thanks
Preeti
Preeti9
|
|
|
|
|
A couple of things:
1. Does the pTouch->Recalibrate and/or CTouchScreenAPI::Create spawn another process? Or is the recalibrate function contained within your own process (separate thread maybe?) Does recalibrate return immediately?
2. You don't necessarily need to do both the IsWindow loop and the process loop. In any case you need to call GetWindowThreadProcessId before the IsWindow loop. Otherwise, what's the point? The window is gone so the call will always fail.
3. Don't use PROCESS_ALL_ACCESS unless you absolutely have to. Use the minimum security setting to get the job done. Depending on the circumstances and user's security level the call may fail trying for all access. SYNCHRONIZE is all you need for waiting on the handle. If you need to call TerminateProcess then add PROCESS_TERMINATE as well.
4. You might want to use QS_ALLINPUT rather than QS_PAINT so that all messages get processed. See "Waiting in a message_loop"" for an example.
5. Since you're apparently doing all this in a window oriented thread (probably you're main thread), you don't want to use Sleep(1000). This will just freeze up your window while you're waiting in the loop. It'd better doing only the process wait loop, peek message loop, or using a window hook to wait for close notification of the window.
6. It's kind of pointless to call TerminateProcess immediately after SendMessage. You're not exactly giving the process much time to clean up and exit normally. Don't call TerminateProcess except as last resort.
|
|
|
|
|
Hi there, First of all ,thank you for your help...
Now, coming to the code:
1. Recalibrate function is contained within the process. yes, recalibrate function return immediately.
2. Ok, I am gonna use IsWindow loop and calling GetWindowThreadProcessID before the loop.
3.Ok, I used Synchronize rather than Process_all_access.
4. is also Ok.
5. is also Ok.
6. Should I wait for some time and then call Terminate Process?
Thanks
Waiting for reply
Preeti
Preeti9
|
|
|
|
|
If the Recalibrate function is contained within your own process, then waiting for the process to complete won't work. You'll be waiting for yourself to exit. However, if recalibrate spawns off another thread (sounds possible since it returns immediately) then you can wait on the thread handle instead.
Use these tests to verify that another thread was launched.
Add code similar to:
pTouch->Recalibrate();
HWND hWnd = FindWindow(...);
DWORD RecalProcID;
DWORD RecalThreadID = GetWindowThreadProcessId( hWnd, &ProcID );
DWORD MyProcID = GetCurrentProcessId();
DWORD MyThreadID = GetCurrentThreadId();
HANDLE hRecalThread = OpenThread( SYNCHRONIZE, FALSE, RecalThreadID );
Put a breakpoint before the recalibrate call.
When breakpoint is hit, open the threads window (menu: Debug/Windows/Threads)
Monitor this window to see if another thread is created when recalibrate is executed.
If in the same process, then RecalProcID will match MyProcID.
If different thread, then RecalThreadID will be different than MyThreadID.
What you're looking for is that RecalThreadID is created fresh when Recalibrate is called (or when TouchScreen object is created) and that the thread goes away when the calibration is done.
If, on the other hand, RecalThreadID is the same as MyThreadID then you cannot use MsgWaitForMultipleObjects to wait on anything as you will be waiting on yourself. Then about the only you can do is check IsWindow periodically inside a PeekMessage loop. Undoubtedly you will need to process messages as the recalibrate itself will be depending on it.
What does the Recalibrate function return? Are there any other functions for checking for status?
Ultimately if the recalibrate spawns another thread and then the thread goes away when recalibration is complete, then you don't even need the IsWindow loop - just the MsgWaitForMultipleObjects.
|
|
|
|
|
Hi,
Yes, I am doubtful if I can use here Msgwaitformultipleobjects or not....
I wasn't able to implement this:
pTouch->Recalibrate();
HWND hWnd = FindWindow(...);
DWORD RecalProcID;
DWORD RecalThreadID = GetWindowThreadProcessId( hWnd, &ProcID );
DWORD MyProcID = GetCurrentProcessId();
DWORD MyThreadID = GetCurrentThreadId();
HANDLE hRecalThread = OpenThread( SYNCHRONIZE, FALSE, RecalThreadID );
This is giving me errors for OpenThread.
I am sending you my code again and please let me know how to proceed further to detect that calibration window.
Here's the code:
// TSCalibrate.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "CWin32AbsPointAPI.h"
void main ()
{
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
CTouchScreenAPI* pTouch;
HWND hCalWin;
DWORD SYNCRONIZE;
DWORD procId;
HANDLE hProcess;
DWORD dwWaitResult;
pTouch = CTouchScreenAPI::Create();
if (pTouch)
{
if (pTouch->Init())
pTouch->Recalibrate(FALSE);
else
MessageBox(NULL, "Created touchscreen interface OK, but Init() failed", "Info", MB_OK);
HWND hCalWin = ::FindWindow(pszABSPOINT_WND_CLASS_NAME, NULL);
GetWindowThreadProcessId(hCalWin, &procId); // retrieves the identifier of the thread that created this window.
hProcess = OpenProcess(SYNCHRONIZE, FALSE, procId);//returns a handle to an existing process object
while( true )
{
if( ! IsWindow(hCalWin) )
break; // window is gone;
// Sleep( 1000); // wait a second for window to close
};
while (1)
{
dwWaitResult = MsgWaitForMultipleObjects(1, &hProcess, FALSE, 30*1000, QS_ALLINPUT);
if (dwWaitResult == WAIT_OBJECT_0 + 1)
{
MSG xMsg;
while (PeekMessage(&xMsg, NULL, 0, 0, PM_REMOVE))
{
if (xMsg.message == WM_QUIT)
return 1;
TranslateMessage(&xMsg);
DispatchMessage(&xMsg);
}// end of PeekMessage while loop.
}
else if (dwWaitResult == WAIT_TIMEOUT)
{
SendMessage(hCalWin, WM_CLOSE, 0, 0);
//TerminateProcess(hProcess, 0);
break;
}
else dwWaitResult == WAIT_OBJECT_0;
{
//Calibration process completed;
break;
}
}
}
else
{
MessageBox(NULL, "Unable to get pointer to Touchscreen interface", "Info", MB_OK);
}
return 0;
}
Thanks
Wating for reply
Thanks Once again
I don't know if I can attach files to this email...otherwise I would have send you all the files to check....I am confused. PLease help.
Preeti9
|
|
|
|
|
I was forgetting that OpenThread is available only for Windows 2000 and up. What operating system is this running on? If this is on 2000 and up, then you can enable those functions by adding:
#define WINVER 0x0501
#define _WIN32_WINNT 0x0501
before including the Windows header files.
In any case you don't need the OpenThread call and its wait loop just to be able to step through the first few lines in order to determine what threads are created.
What does Recalibrate return? TRUE/FALSE or something else?
|
|
|
|
|
I have windows XP.....But its still giving me errors with OpenProcess.
Recalibrate function is returning False....
Thanks
Preeti
Preeti9
|
|
|
|
|
Hi,
What if I use SetForegroundWindow(hCalWin);
DWORD AllowSetForegroundWindow(procId);
OR
AnyPopup();
When I execute and type in the file name on command window, it starts doing calibration returning the cursor to next line, that means it is't able to detect it.
You said there are other methods for it. Let me know. Please help.
Thanks
Preeti9
|
|
|
|
|
AnyPopup is an archaic function. I don't see at the moment how SetForegroundWindow, etc. would help you.
I need more information about what the calibration process is doing. What is the result from the following code:
pTouch->Recalibrate();
HWND hRecalWnd = FindWindow(...);
DWORD RecalProcID = 0;
DWORD RecalThreadID = GetWindowThreadProcessId( hRecalWnd, &RecalProcID );
char MsgText[1024];
DWORD CurProcID = GetCurrentProcessId();
DWORD CurThreadID = GetCurrentThreadId();
sprintf( MsgText, "HWND = %p\nValid = %s\nRecalProcID = %x\nRecalThreadID = %x\nCurProcID = %x\nCurThreadID = %x",
hRecalWnd, IsWindow(hRecalWnd) ? "Yes" : "No",
RecalProcID, RecalThreadID, CurProcID, CurThreadID );
MessageBox( NULL, MsgText, "Test", MB_OK );
|
|
|
|
|
The code is doing calibration and doesn't shows anything. Its running the same way as earlier code was running.
Should I send you all the files again?
Thanks
Preeti
Preeti9
|
|
|
|
|
hi,
i am creating a FTP application in which i have used a progress bar for showing the status of the download. for doing this i used the CFtpConnection::OpenFile() method so that i will read the data in small number of bytes and then display the status. the problem here is that when i try to open the file using this method the return value which should be in the form of a CInternetFile is being returned as a null value. hence i am not able to read the file and there is an excepetion
the syntax i have used is as follows:
the completePath is a CString and contains the path as ftp://homepc/test.txt
i have used IIS to create a ftp site and stored some text files as well as other file in the ftp root directory
try
{
srcFile = pftp->OpenFile(completePath, GENERIC_READ,
INTERNET_FLAG_TRANSFER_BINARY, 1);
}
catch(CInternetException *IE)
{
display the exception
}
when i debugged the program i found out that the srcFile had nothing in it i.e it was NULL with some "?????" in the watch window. can anyone tell me why am i getting this problem or is there any other way to use the progress bar?
aditya
|
|
|
|
|
Do you have an alias for homepc set to 127.0.0.1 on your development machine? Have you checked the permissions of the file on the FTP server? Have you checked that the FTP server allows anonymous access (assuming you are not using a username and password) ?
HTH.
|
|
|
|
|
Hi,
I want to know is there any direct method in C to remove all the spaces in a string.
Thanks.
|
|
|
|
|
Sure. Several ways exist. One way looks like:
char str[] = "This string has spaces";
int x, y;
for (x = 0, y = 0; str[x] != '\0'; x++)
{
if (' ' != str[x])
{
str[y] = str[x];
y++;
}
}
str[y] = '\0';
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Surely:
str[y++] = str[x];
is a bit more efficient
|
|
|
|
|
Anonymous wrote:
str[y++] = str[x];
is a bit more efficient
Are you sure? It may be in theory, but in practice, the compiler will most likely optimize both versions of the source code into exactly the same object code.
I made a simple test with the following code:
#pragma auto_inline(off)
void Test(int x, int y, char* str)
{
str[y] = str[x];
y++;
}
void Test2(int x, int y, char* str)
{
str[y++] = str[x];
}
I wrote each of these functions in separate source files, and called each of them from a function in a third file.
In a Release build, with the default optimizations, the compiler not only detected they were the same thing, but in fact removed Test2 entirely, and changed the call to it, making it call Test instead.
This was the dissambly for Test()
void Test(int x, int y, char* str)
{
str[y] = str[x];
004016C0 mov eax,dword ptr [esp+0Ch]
004016C4 mov ecx,dword ptr [esp+4]
004016C8 mov dl,byte ptr [ecx+eax]
004016CB mov ecx,dword ptr [esp+8]
004016CF mov byte ptr [ecx+eax],dl
y++;
}
004016D2 ret
[Update]
After submitting this post I realized that I should have make the y parameter a reference:
void Test(int x, int& y, char* str)
{
str[y] = str[x];
y++;
}
In the previous version, it didn't make sense to increment y , because that increment won't be seen outside of the function. Of course, the compiler spotted this and didn't even bothered to generate code for it.
After the modifications, the results were exactly the same: Test2 was not generated, and Test was called instead. The only change was the generated code for Test
void Test(int x, int& y, char* str)
{
str[y] = str[x];
004016D0 mov eax,dword ptr [esp+8]
004016D4 mov ecx,dword ptr [esp+0Ch]
004016D8 mov edx,dword ptr [eax]
004016DA push ebx
004016DB push esi
004016DC mov esi,dword ptr [esp+0Ch]
004016E0 mov bl,byte ptr [esi+ecx]
004016E3 mov byte ptr [ecx+edx],bl
y++;
004016E6 add dword ptr [eax],1
004016E9 pop esi
004016EA pop ebx
}
004016EB ret
[End of Update]
In general, focusing on optimizing that kind of details in the source code is a waste of time, and in some cases it may even penalize code clarity for no real benefit.
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
My point was for clarity, not efficiency.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
|
It must have worked okay, cause all the spaces are gone.
Chris Meech
I am Canadian. [heard in a local bar]
Remember that in Texas, Gun Control is hitting what you aim at. [Richard Stringer]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
|
|
|
|
|
Looks like MS isn't going to update this anymore. What are the other available options?
ed
~"Watch your thoughts; they become your words. Watch your words they become your actions.
Watch your actions; they become your habits. Watch your habits; they become your character.
Watch your character; it becomes your destiny."
-Frank Outlaw.
|
|
|
|
|
This may help [^]
onwards and upwards...
|
|
|
|
|