|
Hi all. I was just curious on how to keep a function going until i close the window manually. I know i'll need a loop of some sort however i dont know what i should do. I made a test function to see if i could do it.
<br />
#include <fstream><br />
using namespace std;<br />
int main (){<br />
int loop;<br />
for(loop=0;loop<=10;loop++)<br />
{<br />
printf("Test looping\n");<br />
}<br />
system("pause");<br />
return 0;<br />
}<br />
Now anyone can clearly see that this function loops "Test looping" 10 times. But thats not my intention. Suppose i had a function that would check the time every 30 seconds, then print the time to a file. And it wouldnt stop until i forced it to stop. I hope im making sense, and that everyone understands. If im not being clear enough please let me know. Thanx in advance.
|
|
|
|
|
I think you need to use a timer...
|
|
|
|
|
dellthinker wrote: system("pause");
A much easier way to do that:
printf("Press enter to continue...");
char buff[2];
fgets(buff,sizeof(buff),stdin);
Software Zen: delete this;
|
|
|
|
|
If it does not need to be time based then
while (!g_done)
{
//do what ever
}
and when your app receives the WM_CLOSE message set g_done to true.
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I?
|
|
|
|
|
mate, that will hang the app, to do that he will need to check for new messages in the queue and dispatch them.
|
|
|
|
|
i was assuming he is checking for messages.
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I?
|
|
|
|
|
if it needs to be time based.
static int timer_id = SetTimer(NULL,11,30000,NULL);
and your app should recive an WM_TIMER event every 30 secounds with wParam as the event number (11 in this case). There you can run your code.
When your app recives WM_CLOSE use
KillTimer(timer_id);
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I?
|
|
|
|
|
or you can replace the last parameter with a pointer to a TIMERPROC function. This will then execute the function every 30sec and you will not need to check for messages. (assuming your app is still open)
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I?
|
|
|
|
|
This one is the best solution in my opinion
|
|
|
|
|
Wow, i didnt think i'd get these many replies. Thanx for the suggestions everyone, however i have a question. Is there a way i can loop the FindWindow function?
Here's a sample code:
<br />
#include <windows.h><br />
#include <stdio.h><br />
#include <fstream><br />
using namespace std;<br />
int main()<br />
{<br />
while(1){<br />
sleep(6);<br />
short ie;<br />
for(ie=0;ie<=200;ie++){<br />
HWND handle=FindWindow("IEFrame",0);<br />
HWND handle2=FindWindowEx(handle, 0, "WorkerW",0);<br />
HWND handle3=FindWindowEx(handle2, 0, "ReBarWindow32", 0);<br />
HWND handle4=FindWindowEx(handle3,0,"Address Band Root",0);<br />
HWND handle5=FindWindowEx(handle4,0,"ComboBoxEx32",0);<br />
HWND handle6=FindWindowEx(handle5,0,"ComboBox",0);<br />
HWND handle7=FindWindowEx(handle6,0,"Edit",0);<br />
char addy[MAX_PATH];<br />
SendMessage(handle7,WM_GETTEXT,MAX_PATH,(LPARAM)(LPCSTR)addy);<br />
if(strstr(addy,"http:")!=NULL){<br />
ofstream out;<br />
out.open("http.txt",ios::app);<br />
out << addy << endl;<br />
out.close();<br />
}<br />
else if(strstr(addy,"https:")!=NULL){<br />
ofstream in;<br />
in.open("https.txt",ios::app);<br />
in << addy << endl;<br />
in.close();<br />
}<br />
}<br />
} <br />
<br />
return 0;<br />
}<br />
This will keep looping but not the way that i want. It returns the address like 3000 times when all i want is once. The idea is to keep the program running and keep finding the window and return what it finds only once. And then if its something different log that too etc. Any suggestions?
|
|
|
|
|
Is this a GUI or console application?
dellthinker wrote: Now anyone can clearly see that this function loops "Test looping" 10 times.
Actually it loops 11 times!
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Wow, i didnt think i'd get these many replies. Thanx for the suggestions everyone, however i have a question. Is there a way i can loop the FindWindow function?
Here's a sample code:
<br />
#include <windows.h><br />
#include <stdio.h><br />
#include <fstream><br />
using namespace std;<br />
int main()<br />
{<br />
while(1){<br />
sleep(6);<br />
short ie;<br />
for(ie=0;ie<=200;ie++){<br />
HWND handle=FindWindow("IEFrame",0);<br />
HWND handle2=FindWindowEx(handle, 0, "WorkerW",0);<br />
HWND handle3=FindWindowEx(handle2, 0, "ReBarWindow32", 0);<br />
HWND handle4=FindWindowEx(handle3,0,"Address Band Root",0);<br />
HWND handle5=FindWindowEx(handle4,0,"ComboBoxEx32",0);<br />
HWND handle6=FindWindowEx(handle5,0,"ComboBox",0);<br />
HWND handle7=FindWindowEx(handle6,0,"Edit",0);<br />
char addy[MAX_PATH];<br />
SendMessage(handle7,WM_GETTEXT,MAX_PATH,(LPARAM)(LPCSTR)addy);<br />
if(strstr(addy,"http:")!=NULL){<br />
ofstream out;<br />
out.open("http.txt",ios::app);<br />
out << addy << endl;<br />
out.close();<br />
}<br />
else if(strstr(addy,"https:")!=NULL){<br />
ofstream in;<br />
in.open("https.txt",ios::app);<br />
in << addy << endl;<br />
in.close();<br />
}<br />
}<br />
} <br />
<br />
return 0;<br />
}<br />
This will keep looping but not the way that i want. It returns the address like 3000 times when all i want is once. The idea is to keep the program running and keep finding the window and return what it finds only once. And then if its something different log that too etc. Any suggestions?
|
|
|
|
|
could anyone please let me know when i use this code and print the buf it is not giving the values which i stored in. missing some values...
len=0;
unsigned char *buf;
buf=(unsigned char *)malloc(12);
*buf=0x01
*(buf+1)=0x02
*(buf+1)=0x03
*(buf+1)=0x04
len+=4;
for(k=0,k
|
|
|
|
|
ikbahrian wrote: *buf=0x01
*(buf+1)=0x02
*(buf+1)=0x03
*(buf+1)=0x04
shouldn't that be:
*buf=0x01
*(buf+1)=0x02
*(buf+2)=0x03
*(buf+3)=0x04
?
|
|
|
|
|
ikbahrian wrote:
*buf=0x01
*(buf+1)=0x02
*(buf+1)=0x03
*(buf+1)=0x04
Should be:
*buf=0x01
*(buf+1)=0x02
*(buf+2)=0x03
*(buf+3)=0x04
John P.
|
|
|
|
|
|
One final note: you should use
printf("0x%.2x",(unsigned)buf[k]); since the %x format-specifier expects an int -sized value in the argument list.
Software Zen: delete this;
|
|
|
|
|
unsigned char *buf = NULL;
buf = (unsigned char *) malloc( 12 );
if( buf )
{
*buf=0x01;
*(buf+1)=0x02;
*(buf+2)=0x03;
*(buf+3)=0x04;
*(buf+4)=NULL;
for(int k=0 ; buf[k] != NULL; k++)
{
printf("0x%.2x ",buf[k]);
}
free( buf );
}
I think this will work for u.
|
|
|
|
|
|
Im working in VC++ 2003, my project uses a .lib and a .dll generated in VC++ 2005
I get the following runtime error as soon as I execute the App
LDR: LdrpWalkImportDescriptor() failed to probe c:\Mapi\MAPIEx.dll for its manifest, ntstatus 0xc0150002
Can Anyone help me to solve this?
Thanks in advance
Sebastian
|
|
|
|
|
I had that exact same error yesterday with a resource only DLL. When I went into the project properties and changed the Linker->Manifest File->Generate manifest setting to "No", my error went away.
BUT changing that setting back to "Yes" did not reproduce the error message.
|
|
|
|
|
Yeap I dont know whats that error, finally I made a new project and re compiled it and now all is working right
Thanks for the feedback
|
|
|
|
|
Can anyone please help me to find out a simple way to read a text file line by line in Visual C++ 6. Thanks in advance.
Regards,
Vikram
|
|
|
|
|
|
You can try fgets which is C function
look the sample code snippet
FILE *fp = fopen("c:\\file.txt","r");
char ar[100];
while(fgets(ar,100,fp))
{
print (ar);
}
fclose(fp);
If u can Dream... U can do it
|
|
|
|