Retrieving Images off the Web

This is a discussion on Retrieving Images off the Web within the C++ Programming forums, part of the General Programming Boards category; Hey everyone. We just had about 6 inches of rain here last night and it got me thinking about making ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    94

    Retrieving Images off the Web

    Hey everyone. We just had about 6 inches of rain here last night and it got me thinking about making a sort of desktop radar. Now, one solution to doing this would be to buy a radar and get extremley local weather for a lot of money, or make a program which regularly goes online and retrieves updated radar images and downloads them. My question is, how do I do this? I'd prefer some sort of thing for MFC, as I'm not very good at normal WinAPI, and console wouldn't be able to display it. Would I have to write my own function? If so, how can I get it to access the webpage and download the images every, say, 5 minutes or so? Thanks!

    Brendan
    Draco dormiens nunquam titillandus

  2. #2
    Xei
    Xei is offline
    Registered User Xei's Avatar
    Join Date
    May 2002
    Posts
    719

    This should help, MFC only.

    Well for MFC I believe you can just make a CAsyncSocket Object then in the class put your prototype functions? (In a class what would you call that?) Anyways its probably best if you learn the WinAPI way however Objects will work as well. Here is a sample of how you would probably download an image:

    Code:
    class CObjects : public CAsyncSocket
    {
    public:
    virtual void OnClose(int nErrorCode);
    virtual void OnConnect(int nErrorCode);
    virtual void OnReceive(int nErrorCode);
    };
    
    CObjects MySocket;
    
    void CObjects::OnClose(int nErrorCode)
    {
          MessageBox(NULL,"They closed the connection!",NULL,MB_OK);
    }
    
    void CObjects::OnConnect(int nErrorCode)
    {
          MessageBox(NULL,"Connected!",NULL,MB_OK);
    }
    
    void CObjects::OnReceive(int nErrorCode)
    {
         MessageBox(NULL,"Data Incoming!",NULL,MB_OK);
         //If this is the picture download it and write it to a file using Receive, and WriteFile.  Be careful, HTTP server may send unwanted data without asking for it!
    }
    
    //Now to connect you first have to create a socket, then connect to the domain.
    
    MySocket.Create(0,SOCK_STREAM,FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT | FD_CLOSE);  //All you really need in this case is FD_READ, FD_CLOSE, FD_CONNECT.
    
    MySocket.Connect("www.somedomain.com",80);  //Port 80 is default HTTP Protocol Port.
    
    //Now you'll want to send data to get your picture!:
    You'll have to use MySocket.Send(lpBuf, lpBufLen, 0);
    To get a picture I believe you send the following: "GET SomePicture.jpg" and NEVER forget your CRLF's in Data Transfer.
    
    //And when they send you something you'll retreive it through your CObjects::OnReceive function using MySocket.Receive or by simply using Receive.
    The above is for MFC only, don't forget to include stdafx.h and winsock.h and you'll probably have to Link to: Ws2_32.lib

    Good luck and I hope that I helped.

  3. #3
    Still A Registered User DISGUISED's Avatar
    Join Date
    Aug 2001
    Posts
    499
    Now, one solution to doing this would be to buy a radar and get extremley local weather for a lot of money, or make a program which regularly goes online and retrieves updated radar images and downloads them.
    Or you could just do it the really easy way and go to http://www.weather.com/ and look at their radar shots

  4. #4
    Registered User
    Join Date
    Jul 2002
    Posts
    94
    Thanks!
    Draco dormiens nunquam titillandus

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MS Web Services Question
    By mercury529 in forum Windows Programming
    Replies: 0
    Last Post: 11-14-2006, 06:36 PM
  2. Consuming same Web Service multiple times
    By cfriend in forum C# Programming
    Replies: 2
    Last Post: 01-10-2006, 09:59 AM
  3. SWEBS Web Server
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 09-22-2003, 03:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21