Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Function not working (http://www.go4expert.com/forums/function-not-working-t2317/)

dellthinker 22Dec2006 03:15

Function not working
 
Hi all first time poster on this forum, newbie C++ programmer in training and in need of some help. I made a frankenstien from projects i've found here and there to test the function WM_GETTEXT to get the ie addy bar and save to test.txt. The source compiles like a charm, however it doesnt work. And im staining myself to try and figure out the problem.

Heres the code i've came up with:

Code:

#include <windows.h>
#include <stdio.h>
#include <fstream.h>
HWND out;
char strm[300];
BOOL CALLBACK SearchProc(HWND hWnd, LPARAM lParam)
{
   
        int nLen = GetWindowTextLength(hWnd);
        LPSTR ie = new CHAR[nLen + 1];
        GetWindowText(hWnd, ie, nLen+1);
        if(strstr(ie, "Internet Explorer")!=NULL)
        if(GetAsyncKeyState(VK_RETURN))
        {
                ofstream out;
                out.open("test.txt",ios::app);
                out << strm;
                out.close();
        }
        return TRUE;


}

BOOL CALLBACK SearchProc2(HWND handle, LPARAM lparam)
{
        bool done;
        done=true;
        char stre[300];
        char serv[300]="Edit";
        char ter[100];
        char more[300];
        HWND hold;
        hold=handle;
        int yr=GetClassName(hold,stre,254);
        int erw=SendMessage(out,LB_GETCOUNT,0,0);
        int rt=SendMessage(hold,WM_GETTEXTLENGTH,0,0)+1;
        int kj;
        if(strstr(stre,serv)!=NULL)
                SendMessage(out,WM_GETTEXT,rt,(LPARAM)(LPCSTR)strm);
        if(rt>1)
                for(kj=0;kj<erw;kj++)
                {
                        itoa(kj,ter,10);
                        SendMessage(hold,kj,LB_GETTEXT,(LPARAM)(LPCSTR)more);
                        break;
                }
                if(strstr(more,strm)!=NULL)
                        done=false;
                if(GetAsyncKeyState(VK_RETURN))
                        if(done==true)
                                if(strstr(strm,"http:")!=NULL)
                                        SendMessage(out,LB_ADDSTRING,254,(LPARAM)(LPCSTR)strm);
                                else if(strstr(strm,"https:")!=NULL)
                                        SendMessage(out,LB_ADDSTRING,254,(LPARAM)(LPCSTR)strm);
                                return TRUE;
}

int main(int argc, char **argv)
{
    EnumWindows(SearchProc, NULL);
    return 0;
}

The objectives are:
find the window, then save the string of the address bar in test.txt
to keep the program running until i close it manually

Its doing neither and im stressing terribly. Any help with my code? I'd be very appreciative, thanx in advance!


All times are GMT +5.5. The time now is 05:19.