|
why??? why must be static? u mean serval instances have only one thread function? then once again, how to call a member funtion in a thread function?
What's happening in backyard?
thanks
Extreme programming. Do the No.1
|
|
|
|
|
stevenson wrote:
why??? why must be static?
the thread proc can't be a non-static member function because there is no way to provide the "this" pointer to provide an object context for that member function to be called from. it's like this:
int i = CString::GetLength();
GetLength makes no sense without an actual CString object. a static member function doesn't require an actual object instance, so you can use it as a thread proc.
you can pass an object into the thread proc and use it indirectly:
volatile dataStruct data;
data.pMyObject = &TheObjectIWantToUse;
AfxBeginThread(ThreadProc, (void *)&data, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
...
UINT ThreadProc(void *p)
{
dataStruct *pData = (dataStruct *)p;
now you can use pData->pMyObject;
}
-c
Support regime change. Vote.
|
|
|
|
|
Hi,
I have launch the hh.exe ( help viewer) via CreateProcess(). I am trying to close this window when my main program exits. How do I do that?
Here's a snip of my code...
bSuccess = CreateProcess ("C:\\WINDOWS\\HH.EXE"," NATURAL.CHM",
NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS,
NULL, NULL, &si, &ppi );
helphnd = ppi.hProcess;
CloseHandle ( ppi.hThread );
CloseHandle ( ppi.hProcess );
The code is written as part of defining a 'Help' menuitem. Quite new to the idea of process, copy this idea from FAQ in this website. If CloseHandle is executed right after CreateProcess, that means the process should have finish and return to the executing program, therefore closehandle would do the cleaning up? Now, I am executing something in the ::OnCloseDocument(), how do I check whether the help program is still running,so that I wouldn't be trying to close the program?
|
|
|
|
|
unsigned long status;
int rv = GetExitCodeProcess(ppi.hProcess, &status);
Todd Smith
|
|
|
|
|
THanks for the reply. It's this function just checking whether the process is closed? How to close the process then?
|
|
|
|
|
|
Looks like we can only insert strings, so if i want to put in ints or floats, so I have to first atoi, atof them before inserting them? ?
Appreciate your help,
ns
|
|
|
|
|
Correct, but you need itoa or ltoa (ints to strs), not atoi (strs to ints)...
Not sure if there's a ftoa, so you may need to do an sprintf() or something similar...
Chris
"If at any time I announce that a nation or kingdom is to be uprooted, torn down and destroyed, and if that nation I warned repents of its evil, then I will relent and not inflict on it the disaster I had planned. And if at another time I announce that a nation or kingdom is to be built up and planted, and if it does evil in my sight and does not obey me, then I will reconsider the good I had intended to do for it." -- Jeremiah 18:7-10 (God, commenting on the value of the United Nations)
|
|
|
|
|
Hi,
It's possible to find a window by a incomplete name ??
Ex.: Finding a window that has the name "App Test", ::FindWindow ("App Tes?")
Other thing: How find a window by a class name ??
[]'s
Cris.
|
|
|
|
|
Cris wrote:
How find a window by a class name ?
According to MSDN, you should call FindWindow with lpszWindowName set to NULL.
rechi
|
|
|
|
|
But how I get the class name ??
I am using a dialg based app, how I registry the class name ??
|
|
|
|
|
Cris wrote:
how I registry the class name ?
This should be too complicated. Study RegisterClassEx for it.
Cris wrote:
But how I get the class name ??
Use Spy++.
rechi
|
|
|
|
|
You can use ::GetWindow() that will returns the HWND of the window, then you can use ::GetWindowText
Regards
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
Can u enumerate all the windows (and child windows if needed) and get the text in the window, and check if u can find ur text in it??
see EnumWindows and strstr or CString::Find
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
But I don't have the complete name. I know that the name begin with "App Name Te...". Can I make anything like this ???
[]'s
|
|
|
|
|
EnumWindows(EnumProc, 0);
and the enum proc:
BOOL CALLBACK EnumProc(HWND hWnd, LPARAM lParam)
{
char szWindowText[256];
memset (szWindowText,0,256);
GetWindowText (hWnd,szWindowText, 255)
if(strstr(szWindowText,"The part u want to find"))
{
// hWnd is ur window
}
return TRUE;
}
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
You need to use the function that enumerate the window like your string...
The Funtion GetWindowText extract the complete name...
If you are asking if exists a function that enum window with title like a specific string, I need to say, I'm Sorry....
The only method is to enum all the window looking for the window that you want...
Regards...
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
According to MSDN I am understanding that isDigit will recognise a number, but what if I want to find out that say char* abc = "1234.5678" is a number or not? THen if I'm stepping along the string checking each character, if I hit the decimal point, its not going to like that and it wil say its not a digit> so what can I use to figure out if my text is a double or float?
Appreciate your help,
ns
|
|
|
|
|
You can dig out using GetLocaleInfo, the regional versions of the decimal separator (and the thousands separator). You can then say if it's not a digit, is it one of those?
You might want to check out strtod (wcstod) as well.
Steve S
[This signature space available for rent]
|
|
|
|
|
Why can't you use atof (or the likes)?
If you want to parse the string yourself I'd check each char against a set of allowed characters (0-9, '.', ',') and break if an invalid character is met. You can check for multiple decimal points by setting a flag (a boolean) when the first '.' is met.
Of course, this would be dependent on the users choise of number representations. atof takes care of the locale-stuff for you.
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
simply modify your algorithm a smidge....
for each char in the string
{
if char is '.' then
{
if more than one '.' found
{
// invalid number format
}
else
{
// assumes '.' is decimal marker....other locales can use ','
continue
}
// note.... ',' could be valid too (but only to left of '.')
// note.... other locales will work differently here
}
else
if ( char is not digit )
{
// not a valid number....
}
}
Just trying to keep the forces of entropy at bay
|
|
|
|
|
atof would work, but it returns an ambiguous value of 0 if the text isnt numeric, and 0 if the text is 0....("0") as well. Besides, if its an int I'd have to use atoi and I dont know in advance which type it is. THe biggest problem is the ambiguity of the return value....
Appreciate your help,
ns
|
|
|
|
|
Yeah, I thought of that one too when looking atof i MSDN. Makes the function pretty useless, right?
Anyway, I'd still go for parsing the string myself, looking for digits, points and commas (used for thousand-separators), pluses and minuses. And other characters if you accept scientific representation. As someone suggested, get the characters used for decimal-point and thousand-delimiter from Windows, they can be set by the user individually.
I'd be happy to write you an example, but I'm out of time today.
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
I'm using MyStruct* f() like this:
if (f())
{
} MyStruct is an ordinary structure, containing basic types members.
If i modify the code above this way:
f();
f();
f();
if (f())
{
}
it doesn't crush but in the same place.
The error is about illegaly accessing 0x00000000 .
Do you know what should be wrong here?
rechi
|
|
|
|
|
Realy strange! How does the function f() look like?
Daniel
---------------------------
Never change a running system!
|
|
|
|