|
I am not sure if windows stores such information for each process. If you want you can get the command line with which the process was run. Just out of curiosity why do you need this information?
-Saurabh
|
|
|
|
|
Thanks.
I am developing an dialog Based MFC application whic has two mode of operation. One is Configuration mode another one is Execution mode. Configuration mode is used by the Administrator where as Execution mode is used in the client. In configuration mode user admin is shown with configuration dialog but in execution mode the exe will run as a background process so the client user will not be provided with any interface.
In Configuration mode the admin has to explicitly run the exe by "Double click/ Right click and select ". But in execution mode exe will be invoked from the scheduler.
So if i know the Startup mode of an exe i can able to launch the application according to that. That is if the start up mode is "double click on exe " i will run the exe in configuration mode and show the dialog to the admin. If the startup mode is "Invoking from other process" then i will just run the exe as a background process.
Hope u might have understood my requirement.
Now pls tell me how can i go about it? Or tell me some other method in which i can meet my requirement.
Thanks in advance.
Hariharan R
|
|
|
|
|
Use command line parameters:
myprogram.exe -config run the program in comfiguration mode.
myprogram.exe -background runs the program as a background process.
or if you prefer
myprogram.exe -> run the program in configuration mode.
myprogram.exe -background -> runs the program as a background process.
This way when user double clicks program automatically runs in configuration mode.
-Saurabh
|
|
|
|
|
Thats looking Good.
I was worrying about if the client got the exe and double click it it will run in the configuration mode. But the client is not suppose to do that.
Pls let me know is there is any other method apart from file/command line operation.
If nothing works out i will go with ur command line method.
Thanks Saurabh
Hariharan R
|
|
|
|
|
You can achieve this with command line as well.
myprogram.exe -configuration -> run in configuration mode.
myprogram.exe -background -> run in background mode.
myprogram.exe -> report an error to user that program should not be run manually.
If you really really want to hide the details then try this. Create 3 executables.
1. client.exe
2. service.exe
3. configuration.exe
client.exe is the application you have written. It accepts following 2 command line parameters.
client.exe -somename1 -> configuration.
client.exe -somename2 -> background.
somenameX can be anything you want to obscure the parameters.
when run without the parameters client.exe reports an error that it should not be run manually.
service.exe using ShellExecute runs client.exe with -somename2.
configuration.exe using ShellExecute runs client.exe with -somename1.
So this way no one know the paramters except you. Bottom line is command line parameters are quite powerful and you can achieve whatever you want to do. Just have to think what exactly is you need.
-Saurabh
|
|
|
|
|
Will work around the solution and get back to if any help required.
Thanks Saurabh.
Hariharan R
|
|
|
|
|
I want to capture area where pen draw area on screen.It is easy to capture the desktop,windows,or rectangle area,but how to capture the area where pen draw and copy it to the clipboard?
I know a sofeware called Snippy can do what I want .
Thanks for your advice or method!
|
|
|
|
|
I am not sure if you want to be able to copy it to the clipboard, but I remember there were two functions which might help. See CDC::BeginPath() and CDC::EndPath().
|
|
|
|
|
Hi all,
I came across this quiz the other day. It goes something like: you have a string "aabbccddeffghijk" and you should find the foremost occurrence of an unique character in the string, so in this case letter 'e' should be the answer, and this should be done in just one traversing. The tip is that array index should be of interest.
I only came up with a single traversing that can only sorts out all the letters that occurred only once in the string, but how can I tell the sequence of those single occurrence of letters within single traversing, or is this possible practically:
int ar[26] = {0};
TCHAR* ptsz = "aabbccddeffghijk";
int nIndex = 0;
while (*(ptsz++))
{
nIndex = int(*ptsz) - 'a';
ar[nIndex]++;
}
Thanks,
modified on Tuesday, July 1, 2008 10:54 PM
|
|
|
|
|
LiYS wrote: you should find the first occurrence of a character that also appeared foremost in the string
This is a confusing statement. I assume you mean you need to find the first unique character in the string?
Steve
|
|
|
|
|
Sorry, it is confusing I should have corrected it.
it should be "you should find the foremost occurrence of an unique character in the string"
|
|
|
|
|
Hi,
why store the occurence count in an array, instead store the first position using two special
values, say -1 for never seen yet, and -2 for seen multiple times.
you would have to traverse your array to initialize it, traverse the string once, then traverse
the array again to find the lowest value >=0.
BTW IMO this belongs in the algo forum, not the C++ one.
|
|
|
|
|
I notice that the string is sorted. Is the algorithm permitted to assume this? If so the the following will do the trick:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
const char *pstr = "aabbccddeffghijk";
for (unsigned int i=1; pstr[i]!=0; ++i)
{
if (pstr[i]!=pstr[i-1] && pstr[i]!=pstr[i+1])
{
cout << "First unique character: " << pstr[i] << endl;
return 0;
}
}
cout << "No unique characters." << endl;
return 0;
}
Steve
|
|
|
|
|
The only thing I see wrong with your approach is that you are incrementing ptsz prematurely.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
As has been pointed out, the array is sorted. If that's true, and not just a coincidence...
(This assumes a /0 terminated string)
TCHAR findfirstuniquechar_sorted (TCHAR *sz)
{
if (!sz) return 0;
for (int n = 0; sz [n]; n++)
{
if (sz [n] == sz [n+1])
continue;
if ( (n > 0) && (sz [n] == sz [n-1]))
continue;
return sz [n];
}
return 0;
}
If the string is not sorted, the problem becomes harder. As you use TCHAR, I'm assuming unicode, so you can't just have a 26 array for placement...
TCHAR findfirstuniquechar_unsorted (TCHAR *sz)
{
if (!sz)
return 0;
; This line posts badly - it should be CMap less than TCHAR, TCHAR and, int, int and greater-then CharMap; hope that made sense... pre bug reported.
CMap<TCHAR, TCHAR &, int, int &> CharMap;
int nPos;
int nCharPos;
for (nPos = 0; sz [nPos]; nPos++)
{
if (CharMap.Lookup (sz [nPos], nCharPos))
{
CharMap [sz[nPos]] = -1;
}
else
{
CharMap [sz[nPos]] = nPos;
}
}
POSITION pos = CharMap.GetStartPosition ();
nPos = -1;
TCHAR c, cFirst = 0;
while (pos)
{
CharMap.GetNextAssoc (pos, c, nCharPos);
if (nCharPos < 0)
continue;
if ( (nPos == -1) || (nCharPos < nPos))
{
cFirst = c;
nPos = nCharPos;
}
}
return cFirst;
}
OK, I've just spent FAR too much time on that. I hope it wasn't homework!
Iain.
Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.
|
|
|
|
|
Environment: Windows XP, Visual Studio 2008, C++
Someone gave me a tip about getting a value from a dialog edit box. It gets me almost there, but not quite. Here is what I did:
Create an edit box in a dialog.
Right click on it and select “Add Variable”
The field named Category has the selections Control and Value.
Open the drop down and pick Value.
The field Variable type has changed to CString, and it has a pull down.
Open the pull down and from the options, select double.
In the variable name field enter: edit_double.
Back in the code, write this:
double temp;
temp = edit_double;
The compiler accepts it, links it, and runs it. I don’t have edit_double declared anywhere so it must be a valid variable, but the value is zero regardless of what I edit into the box.
What have I overlooked? What do I need to do to enter “1.12” or “1.2e4” into the dialog box and get the expected value in temp?
Thanks for your time
|
|
|
|
|
Yeah I have tried that before and it doesn't work. SO what I do is add a control variable. Then to get double value I do this.
char buffer[100];
editControl.GetWindowText(buffer, 100);
double d = atof(buffer);
-Saurabh
|
|
|
|
|
That works, but I am trying to avoid the old atof function.
The test code was not using the OK button. Someone told me to call
BOOL status = UpdateData( True );
and that made the data availble in tha variable. That way I can set the variable to be a double and windows makes the conversion for me.
Thanks for your time
|
|
|
|
|
Ah cool, didn't knew that. Thanks!
-Saurabh
|
|
|
|
|
FYI - another opinion:
Avoid UpdateData()[^]
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
bkelly13 wrote: I am trying to avoid the old atof function.
Would you rather use sprintf() ?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
RE: Would you rather use sprintf()?
That's the wrong direction. I want to convert from string to a binary value. (A double or float right now, but I also use integers.) The conversion function should flag a malformed input in some fashion other than returning a valid value. (Such as returning 0.0 to a double)
Since edit boxes return strings rather than numbers, I am at a loss as to why there seems to be no standard function to do this.
Thanks for your time
|
|
|
|
|
bkelly13 wrote: That's the wrong direction.
How so? It converts from a string to a double and reports any errors if necessary.
bkelly13 wrote: I want to convert from string to a binary value.
The computer sees all numbers as base-2. So this "conversion" makes no sense.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
A google search returned this site:
http://www.cplusplus.com/reference/clibrary/cstdio/sprintf.html[^]
Which says, in part:
Write formatted data to string
Writes into the array pointed by str a C string consisting on a sequence of data formatted as the format argument specifies.
To my knowledge, sprintf converts various inputs to string format, and never the other way around. If you use sprintf to convert from string to double, please show me how.
Regarding my use of binary number, we refer to "1.2" when printed on paper as a number, and in a string as a number, as well as in binary format as a number. When I say a binary value I refer to an int, float, etc rather than formated as digits in a string. That's probably not a good method, but I am open to suggestions.
Thanks for your time
|
|
|
|
|
bkelly13 wrote: If you use sprintf to convert from string to double, please show me how.
I meant to suggest sscanf() . Sorry about that.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|