Win32 API and Google [HELP a noob out.]

Hey so I have been pondering this for a while and this is my conclusion.
I want to make a program that takes my Input and dose a search on Google and returns.
The individual links that contains my Search Words and will then come up as relevant results.

As I found out this is a bit to mutch for me to take on right now so I narrowed it down to.
Search on Google and outputs the links in the program for now.
After some days of trail end error I have made my GUI with the Win32 API and starting to understand it FINALLY.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <windows.h>

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "GoogleSearch";

#define ID_BTN1 1
#define ID_TXTBOX 2
#define ID_TXTBOXRESULTS 3

static HWND hwndURLBOX;
static HWND hwndRESULTBOX;

int WINAPI WinMain (HINSTANCE hThisInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpszArgument,
                     int nCmdShow)
{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default colour as the background of the window */
    wincl.hbrBackground = GetSysColorBrush(COLOR_3DSHADOW);

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Search Google",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           550,                 /* The programs width */
           350,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nCmdShow);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
        case WM_CREATE:
        {
        hwndURLBOX = CreateWindow(TEXT("EDIT"), TEXT("http://"),
                WS_VISIBLE | WS_BORDER | WS_CHILD | ES_AUTOHSCROLL,
                10, 10, 400, 25,
                hwnd, (HMENU) ID_TXTBOX, NULL, NULL
            );

            CreateWindow(TEXT("button"), TEXT("Click Me"),
                WS_VISIBLE | WS_BORDER | WS_CHILD | MB_OK,
                10, 40, 80, 25,
                hwnd, (HMENU) ID_BTN1, NULL, NULL
                );

        hwndRESULTBOX = CreateWindow(TEXT("STATIC"), TEXT(""),
                WS_VISIBLE | WS_BORDER | WS_CHILD,
                10, 80, 500, 200,
                hwnd, (HMENU) ID_TXTBOXRESULTS, NULL, NULL
            );

                break;
        }
        case WM_COMMAND:
        {
            if (LOWORD(wParam) == ID_BTN1){

                int nLenght = GetWindowTextLength(hwndURLBOX) +1;
                static char urlstr[500] = "";

                GetWindowText(hwndURLBOX, urlstr, nLenght);
                SetWindowText(hwndRESULTBOX, urlstr);
            }

            break;
        }

        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}


So what now I have been looking at WinINet.h but seems its not supported on Windows 7.
Allot of Google searches turned up ALLOT but i think [url=http://stackoverflow.com/questions/1397313/programatically-get-google-search-results]this[/url] is what I need to do next but I have no clue how. Can anyone shed some light on this for me becuse not a clue on how to use Google Spesifecly in C++?

Also dont know but can this be done using WinHTTP API?

Any help is greatly aprichiated..
Thanks
Last edited on
WinINET is supported in windows 7, who told you this ?
Look here for what header and libs is required to use wininet API. Download and install latest SDK if you have not done so already.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa385483(v=vs.85).aspx
Last edited on
Thanks for your reply so with some hard work and dedication i can do what i want with.
Win32 API and WinINet API ?,can you stear me in the right direction of what Functions i whode need?
To do some basic stuff with it?, I will have a look fore some tutorials.
Thanks again
Don't know if this will help but several weeks ago I posted an example of embedding the WebBrowser ActiveX Control (Microsoft Internet Controls 1.1 in ieframe.dll) in a Win32 Sdk window...

http://www.cplusplus.com/forum/windows/58312/

I kind of hijacked the thread a bit there - its about the 10th post down. To go to www.google.com you would just put that string in a BSTR and execute the IWebBrowser:Navigate method...

1
2
3
4
5
BSTR strUrl;

strUrl=SysAllocString(L"www.google.com");
if(pWebBrowser)
   pWebBrowser->Navigate(strUrl,NULL,NULL,NULL,NULL);


I had just figgured all that out 'on a lark' kind of, as I usually don't deal much with internet coding. The whole program compiled to about 10K. I thought that was neat. The COM part is hard to understand though.

Topic archived. No new replies allowed.