|
The key of the table is time. The is table is like
time price
2007-01-01 10.00
2007-01-02 11.00
group like this (every 10 records)
group 0: 1st 2nd ...
group 1: 11th 12th ...
group 2: 21st 22nd ...
...
Now I want to get the sum of the first record of continuous groups, for example, 10 groups, so the values are from
records: 1st 11th 21st ... 91st
Is there any efficient way?
Thanks very much.
|
|
|
|
|
Does anyone know of an application or source code that can be used to walk down all the tree of all windows in a program?
I'd like to write some test code that runs at my program's exit that visits all the windows in the program and prints information about those windows -- for example:
1. print the resource id of the window
2. print the window text (or small part there of)
3. if the window is a dialog, frame, etc, visit the sub-windows thereof and repeat the above
I'm interested in doing some automated testing understand that the task of filtering windows from the list may be really high.
Thanks,
Lowell
|
|
|
|
|
There are win32 and MFC api's to get the top level window and to get a windows children. Combine those with some recursion and you'll be well on your way
|
|
|
|
|
You can use of EnumWindows for all top-level windows when you have handle to window you can use of other APIs.
|
|
|
|
|
Thanks for the hints! I was hoping to find some utility program to help me, but I guess I'll just have to roll up my sleeves and get to work.
thanks!
Lowell
|
|
|
|
|
I like Winspector[^]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A>
|
|
|
|
|
I've got a piece of software written by someone in my department years ago. (IE, I have no access to the source nor do I have a developer I can contact.) The problem is that this piece of software outputs information to a log.txt file that I would like to read in real time (in a console window) because when the program crashes the file stream gets closed before it can write its buffer to the actual file leaving me with 0kb log files, awesome.
My initial thought on how to do this is to first inject my own .dll in to the program (using InjLib). I could then use my own .dll to redirect any calls to CreateFile where the filename is log.txt to a new file stream. I thought at first I could just pass back a pointer to stdout, this obviously resulted in whatever was going to log.txt to write to the console window that the program already has open. This might work if the program wasn't already dumping alot of info. to that console. So I thought maybe I could create a second console window. Knowing that each .exe file can only have 1 open console I searched around code project and found a multiple console opening program that uses pipes. Here is where I am stuck. I know that fprintf writes to a buffer. The only way my 2nd console gets updated is when the original program closes the file stream. I've tried created a pipe with no buffer and hardware write through but to no avail.
I guess my question is: Is there a simpler way of redirecting a file stream to console window? Or, if not, is there some way for me to read from the buffer fprintf uses? I've tried using PeekPipe on my pipe but it doesn't see anything.
I'm not exactly sure what code snippets would help in my explanation.
modified 28-Aug-18 21:01pm.
|
|
|
|
|
How about trying to trap the file write operations and instead of redirecting them to a console window, calling flush to force the buffer to the file.
|
|
|
|
|
That's an idea but real-time access to the debugging information would be more helpful.
modified 28-Aug-18 21:01pm.
|
|
|
|
|
Tyfane wrote: when the program crashes
I detect a sense of inevitibility here. Sounds as if you have a tired piece of buggy software here. And you have no source code.
Far be it from me to tell you what to do, but speaking as one who has struggled in the past with such things, I would say that if I were you I'd byte the bullet and write a spanking new version in windows, using the latest ideas on the particular issues the software is supposed to address. That approach is probably less time consuming, and will probably give you more brownie points with management, not in the least because your name will be on the new version.
Regards, and may the Power be with you! (You'l Need it Eitherway)
Bram van Kampen
|
|
|
|
|
The function 'freopen' is about redirecting. But I don`t know whether it can help you; because I don`t know that [1]the detail of your method of to open second console window and [2]how to get handle of file stream of log.txt in your .dll.
Could you detailedly describe you method which how to open second Console window and how to get handle of file stream???
|
|
|
|
|
@Bram: Believe me the idea of rewriting this pile of garbage has been bandied about for almost a year now. The major hold up, as always, is cost and time. I can spare a month or 2 to test some theories to see if I can shore up some of the minor glitches. Barring that we'd have to hire a contractor to finish the product, our own programming staff is swamped.
@deng0jun:
[1] The multiple consoles concept comes directly from: http://www.codeproject.com/cpp/MultipleConsoles.asp
[2] Getting a handle to the file uses the InjLib for .dll injection and a method similar to this gentleman's article:
http://www.codeproject.com/system/Paladin.asp
1. Program Foo runs
2. I use InjDemo.exe to insert HookApi.dll in to Foo.
3. HookApi loads MyDll.dll to overload CreateFile
4. When CreateFile is called I check the incoming name for "log.txt", when found I return a pointer to my pipe for multiple consoles.
Even if I simplify the problem and remove multiple consoles I have a problem dumping whatever data is stored by Foo to a console window. The dump happens if Foo calls flush which apparently it does for some errors (this is only an assumption based on the log sometimes containing data). After taking a second look at my problem it now seems to me that I somehow need access whatever buffer is created by WriteFile... perhaps a custom StreamBuf? Maybe what I'm trying to do is impossible... I have no idea.
modified 28-Aug-18 21:01pm.
|
|
|
|
|
Dear Tyfane,
Now I have a ideal which may solve your problem; perhaps it`s too late.
My ideal is that you hook CreateFile and WriteFile at the same time.
In this way, you can get the HANDLE of log.txt firstly; then monitor the WriteFille. My means is following:
<br />
BOOL MyWriteFile(HANDLE hFile, ......)<br />
{<br />
BOOL res = OriginalWriteFile(HANDLE hFile, ......);<br />
if(hFile belong to Log.txt)<br />
{<br />
FlushFileBuffers(hFile);
}<br />
return res;<br />
}<br />
If writing file is not the cause which result in to crash, I think it is a way to solve your problem.
Good Luck!
JuneDeng
|
|
|
|
|
hey
i have an idea that i would like to make a program for and i wonder if anyone can help me. what my idea is :
i would like to be able to capture text off a specific area of the screen using something like optical character recognition software and then log how many tines the same message was shown ( there will be a variation of three message) and give me a total for each message. and maybe if possible also log the current time of each message and create some sort of graph to show the results.
like i said im new here so i hope i have posted this in the right section.
thanks
steve
-- modified at 16:55 Wednesday 14th November, 2007
|
|
|
|
|
yes.
There are numerous articles on the subject of OCR here on CP; have a look at them.
- Extracting the bitmap ( screen grab of some sort ) is easy.
- Sending the bitmap to the OCR and getting back the text might be difficult depending on the technology and how well it works.
- Counting the messages and keeping a log of everything is easy.
What have you done up to now ?
|
|
|
|
|
thanks for your reply,
i haven't made much of a start because i dont know the first thing about programing i have seen the ocr information on cp thats how i found it (google searched ocr) the first thing i wanted to know was it possible, which you say it is. i have downloaded a few types of ocr and played with them, so i have taken some screen grabs and turned them in to editable text. i think the hardest part for me is to get the text from the ocr to count and log, and automating the ocr to take a screen grab at the right time ( maybe on a timer every 2 seconds)
-- modified at 16:52 Wednesday 14th November, 2007
|
|
|
|
|
Hey all,
I want to use pseudo random functions in C++, such that they take input parameters, and based on this input give output. i.e. function(param1, param2).
My problem is that what I find on the internet are just simple random number generators based on seeds, which is not what I want. Does anyone know, if there is any class that I could use for above-stated purposes. ?
Thanks
|
|
|
|
|
boost::random[^]
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
What exactly are you trying to do here? There isn't any reason to think that two or more seed parameters will be any better than a single well chosen seed.
Since any random number generator basically produces a repeating (but repeating with a HUGE period) sequence that looks random, and since seeding the generator just tells the RNG where to begin iterating through that sequence, passing in multiple values won't get you anything better than passing in a single numerical value.
Without knowing more about what your goal is, I would say to just use one parameter, or combine them into a single seed value, or something like that.
|
|
|
|
|
I see what you mean Nathan. Yes, I could combine the values into one as well. What I need it for example following. I have a pseudorandom function F. And say F(x) = y. So that everytime I call the function with parameter x, it outputs y.
|
|
|
|
|
Then use a manually mathematic formulem as you want. You will always have the same output for the same input. I.E
y = ABS( (((((3 - (x+1)) * (x-1) / 1.5) + ((2 - (x/5) + (x - 2/3))) / ((1 - x/7) + 2 * (x+1)))
And if you want the result to be between 0 and 1, normalize the output or just divide y /= y+1;
Greetings.
--------
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
|
|
|
|
|
Your terminology is confusing, random is a property of a sequence not a function, so pseudo-random generators produce a pseudo-random stream of values, you can initialise this from a seed. It sounds that you are looking for a one-way or trapdoor function, where given x, the value f(x) appears random and difficult to invert to produce x. You could look at the standard hash functions (e.g. MD5), or alternatively something simple like exponentiation modulo some prime e.g.
f(x) = r^x (mod p) where r is a primitive root mod p.
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."
|
|
|
|
|
Hi
I'm facing some problem in standard MFC application. In my application, I'm able to run only 3 instances of my application simultaneously.That is, I'm able to open only three login screens at the same time, but I dont want this limitaton. I'm currently working in Windows XP. However, when I ran my application in Windows NT, only 4 instances can be run at a time.
When I tried to open it fourth time in Windows XP, it is failing at the following line of code.
//winfrm.cpp
BOOL CFrameWnd::Create(LPCTSTR lpszClassName,
LPCTSTR lpszWindowName,
DWORD dwStyle,
const RECT& rect,
CWnd* pParentWnd,
LPCTSTR lpszMenuName,
DWORD dwExStyle,
CCreateContext* pContext)
{
HMENU hMenu = NULL;
if (lpszMenuName != NULL)
{
// load in a menu that will get destroyed when window gets destroyed
HINSTANCE hInst = AfxFindResourceHandle(lpszMenuName, RT_MENU);
if ((hMenu = ::LoadMenu(hInst, lpszMenuName)) == NULL)
{
TRACE(traceAppMsg, 0, "Warning: failed to load menu for CFrameWnd.\n");
PostNcDestroy(); // perhaps delete the C++ object
return FALSE;
}}
m_strTitle = lpszWindowName; // save title for later
if (!CreateEx(dwExStyle, lpszClassName, lpszWindowName, dwStyle,
rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
pParentWnd->GetSafeHwnd(), hMenu, (LPVOID)pContext))
{
TRACE(traceAppMsg, 0, "Warning: failed to create CFrameWnd.\n");
if (hMenu != NULL)
DestroyMenu(hMenu);
return FALSE;
}
return TRUE;
}
Also, I have the following thing in my code:
//Inside ::InitInstance
if (pDocTemplate = new CMultiDocTemplate(IDR_mdiflsTYPE,
RUNTIME_CLASS(CmdiflsDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CmdiflsView) ) != NULL)
cout<<"Successful"
else
cout<<"Failure"
I am creating such 140 CMULTIDOCTEMPLATE (using new) objects for different menus.
Somebody suggested me why above function is failed might be due to the following reason:-
If you call the constructor(above Doctemplate) so many times, without freeing, then you probably reach a maximum space of Windows handles, if the constructor loads menu and other resources. That’s why next resource-allocation functions fails. Can you confirm that you really create and keep so many objects?
So to check resource allocation/storage limitation problem, I applied logs as shown above and I got 140 "Successful" messages when I ran 4th instance.
One more thing is that when I lessen the number of these doc templates to around 50, I am able to start 6-7 instances of my application.
So could anybody suggest me how to ensure if this much objects are successfully created?
Is there any better way to ensure if it is a resource allocation/ storage limitation problem? If yes. how can I overcome this?
Thanks in advance!
Chirag Kalra
|
|
|
|
|
Sounds to me like classic running out of resources. I've never seen a serious app which needed 50 MultidocTemplates, never mind 150, but there you go, there's always a first for everything. Then on top of that you try and run multiple instances of this. (More than 3 anyways). Sounds more like a test of how much abuse you can give the system before it breaks. BTW how many documents of each of the 150 types did you plan to have open at the same time in the multiple instances, and what would the average size of each document be.
It sounds to me like a case of 'Back to the Drawing Board'
Hope this is Helpful
Bram van Kampen
|
|
|
|
|
First... this is the 3rd or 4th time I see the question, if you are the same user repeating question, you could tae a look to the answers of your previous posts. If not... take a look on them, maybe you find the solution.
Second... Why do you want to make different instances of application? Can't you just make, different pairs Doc-View in just one instance of your application?
Greetings.
--------
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
|
|
|
|
|