Thanks - that worked a treat. However, it all seems to break down when I try to use strings in Win32 programs. Is there a tutorial on how I could go about doing this? For example, if I have this code:
Code:
#include <windows.h>
#include <cstdio>
#include "resource.h"
#include <urlmon.h>
#include <iostream>
#pragma comment(lib, "urlmon.lib")
#include <string>
#include <cstring>
#include <stdio.h>
string url = "http://";
BOOL CALLBACK ToolDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_DOWNLOAD: //Pressing download button.
{
int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_URL)); //Extracting the rest of the web address from a text box.
char* buf;
buf = (char*)GlobalAlloc(GPTR, len + 1);
GetDlgItemText(hwnd, IDC_URL, buf, len + 1); //Assigning the URL to 'buf'.
string final = url + atof(buf); //Adding the rest of the web address to 'http://'
const char *finalurl = final.c_str ( ); //Converting to c_str();
URLDownloadToFile( NULL, finalurl, "index.html", 0, NULL ); //Downloading it.
ShellExecute(NULL, "open", "index.html", NULL, NULL, SW_SHOWNORMAL); //Opening it.
GlobalFree(buf);
break;
}
case IDC_CLOSE:
EndDialog(hwnd, 0);
break;
}
break;
case WM_CLOSE:
EndDialog(hwnd, 0);
break;
default:
return FALSE;
}
return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
return DialogBox(hInstance, MAKEINTRESOURCE(IDD_DOWNLOADER), NULL, ToolDlgProc);
}
When I try to compile this, I get errors such as error C2784, error C2782 and error C2676. It looks like I am doing something very wrong (I am guessing that you need to use a different syntax for strings in Win32).
Thanks.