|
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
|
|
|
|
|
The value is only used/set when UpdateData() is called, this happens when the dialog box is initially shown and when the user clicks OK. Typical usage if the variable is called m_myDouble
double myValue = 23.2;
CMyDialog dlg;
dlg.m_myDouble = myValue;
if (dlg.DoModal() == IDOK)
{
myValue = dlg.m_myDouble;
}
This should have the edit box preloaded with 23.2 and when the user clicks on OK then dlg.m_myDouble should be set to whatever vale was entered
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."
|
|
|
|
|
You are typing the values in the edit box, but are you sendind the values to the variable?
I know UpdateData should be avoid, but try it. And if it works, try to use another way to get the data.
I saw the other answers after giving mine, so it is useless.
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
I followed the link and read about UpdateData. I don't have sufficient knowledge/experience to understand it all, but my application does not have much concern for preserving the initial values.
I use a value variable and UpdateData makes the values available. The value variable associated with the edit dialog returns the binary numeric value for the number. It still has a flaw. If I type in 1.2r6 instead of 1.2e6, it stops converting at the r and gives me 1.2 with no error. For now, I will continue on with the remainder of my application and get it working.
There are seven numeric fields and I am thinking of having a validate button that will get the binary numeric values, convert back to strings, and put those string representations of the values back on the screen for the user to review.
Maybe I will have to write my own function with a prototype that looks like:
bool = string_to_float( string, &float );
with the bool reporting good or bad conversion. Not real difficult, but the idea that I need to write my own low level conversion function is shocking. It still seems to me that this should be a standard function.
Thanks for your time
|
|
|
|