C use IPicture to display online pictures (specified by URL)

Source: Internet
Author: User
Tags function prototype getmessage message queue
c use IPicture to display online pictures (specified by URL) Blog Category:Desktop Programs (VC, Dephi,. Net) VC + + MFC programming Windows data Structure/************************************************************/
VC IPicture
Display network picture display remote picture display URL specified picture
Download display images via HTTP to display online advertising images
Above is my list of key words, I find this article for several kinds of keyword writing, only to find,
In order to make it easier for people, I wrote all the keywords.
/************************************************************/
The article is very good, just solves my problem. Thanks to the author. This is a program developed using the SDK (without MFC).
If the SDK development method is not very familiar, just look at the Showpic function.
Reprinted article, original address: http://www.blogjava.net/Unmi/archive/2007/12/02/164605.html #include  <windows.h>   // Windows SDK      #include to use  <commdlg.h>  //  Open the File window to include this header file       //Use  IPicture  interface, to include the following two   header files     # include <ocidl.h>     #include  <olectl.h>       //  Declaration window function Prototype     lresult  callback mainwndproc  ( hwnd  ,  UINT ,  WPARAM ,  LPARAM );       //  declaration shows the function prototype of the picture     Hresult  showpic ( char  *lpstrFile,  Hwnd  hwnd)  ;      //Picture filename     char  lpstrfile[ max_path]=  ""  ;          int  winapi winmain  (  hinstance  hthisinstance,                          HINSTANCE  hPrevInstance,                           LPSTR  lpszArgument,                          int   nfunsterstil)                              {          //  window class name          char  szclassname[ ] =    "Showpicture"  ;                 wndclassex windclass;                 // Fill  WNDCLASSEX  structure with parameters describing the main window         windclass.cbSize =   sizeof  (windclass);    //structure size          windclass.hinstance = hthisinstance;    //instance clauses phenol          windclass.lpszClassName = szClassName;         windclass.lpfnwndproc = mainwndproc;    //window function Pointers          windclass.style = CS_DBLCLKS;            //capture Double-click event         windclass.cbSize =  sizeof    (wndclassex);                 windclass.hicon = loadicon  (NULL,&NBsp;idi_application)   //use pre-defined icons         windclass.hiconsm =  LoadIcon  (null, idi_application)   //use small icons for predefined classes          windclass.hCursor = LoadCursor  (Null, idc_arrow)   //using predefined cursors          windclass.lpszMenuName = NULL;                   //do not specify main menu          windclass.cbClsExtra = 0;                        //no additional class memory         windclass.cbWndExtra = 0;                        //no additional window memory      &NBSP;&NBSP;&NBsp;         windclass.hbrBackground =  ( HBRUSH )  color_background;  //using pre-defined background brushes                  //Register this window class if you fail to exit the program directly           if    (! registerclassex  (&windclass))               return  0;                  Create main window          HWND  hWnd = CreateWindowEx  (             0,                     //dwExStyle,  Extended Styles              szclassname,      & NBsp;   //lpclassname,  class name                "Show picture  --  mouse Double click Browse picture file       -- author:unmi"  ,   lpwindowname,  title             ws_overlappedwindow,   //dwStyle,  window style             cw_ usedefault,        //x,  initial  X  coordinate              cw_usedefault,        //y,   Initial  YX  coordinates             640,                   //nwidth,   Width             480,                   //nheight,  Height              HWND_DESKTOP,         //hWndParent,  parent Window Handle             NULL,                  //hMenu,  Menu Handles             hThisInstance,         hinstance,  Program Instance handle             NULL                   //lpparam,   User Data             );                  //Display window, Refresh window client area          showwindow&nbSP; (hwnd, nfunsterstil);                  //  take the message out of the message queue and give it to the window function processing          //  until   getmessage  the message is  wm_quit, or false, to end the message loop         MSG messages;              while   (getmessage  ( &messages, null, 0, 0)         {              //convert keyboard messages, convert virtual keys to character messages              translatemessage (&messages);                          //sends a message to the appropriate window function              dispatchmessage (&messages);        }                 //  getmessage  return  false, program end  postquitmessage ()   Send this message           return  messages.wParam;   }         //   window functions, messages from  DispatchMessage  distributed     Lresult  callback mainwndproc   ( hwnd  hwnd,  uint  message,  wparam  wparam,   lparam lparam)     {         switch    (message)   //processing messages         {          case  WM_DESTROY:              //post a  WM_QUIT  message to the message queue, prompting the  GetMessage  function to return 0, ending the message loop              postquitmessage  (0);              break ;         case  WM_LBUTTONDBLCLK:             {                 OPENFILENAME file = {0};                 file.lStructSize =  sizeof  ( File);                 file.lpstrtitle =   "Please select a picture file"  ;                 file.lpstrFile = lpstrFile;                 file.nMaxFile = MAX_PATH;                file.lpstrFilter =   "Pictures (*.jpg,*.gif,*.bmp) \0*.jpg;*. Gif;*.bmp\0\0 " ;                  if  (:: GetOpenFileName (&file))                  {                             //clear the original image                        HDC&NBSP;&NBSP;HDC=GETDC (hWnd);                      RECT rect;                     ::getwindowrect (HWnd,&rect);     &NBSP;&NBSP;&NBSP;              ::fillrect (Hdc,&rect, (  HBRUSH )  color_background);                                          ::sendmessage (hwnd,wm_paint,null,null);                 }             }              break ;         case  WM_PAINT:             showpic (Lpstrfile,hwnd);              break ;         default :                           //The messages we don't handle to the system   do the default processing              return   DefWindowProc  (hwnd, message, wparam, lparam);         }                 return   0;   }   //  Show picture, lpstrimgurl  as Picture URL address,hwnd  For window handles        hresult  utils::showpic ( char  *lpstrimgurl,  hwnd  hwnd)         {         &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;HDC&NBSP;&NBSP;HDC_TEMP=GETDC (hWnd);                     IPicture *pPic;             IStream *pStm;                      BOOL  bResult;                      DWORD   dwfilesize,dwbyteread;                     //read the picture file on the webpage, is actually a chttpfile pointer          Cinternetsession session (  "HttpClient"  );        CFile*  httpfile =  (cfile*) session. OpenURL (lpstrimgurl);                  if   (httpfile!=invalid_handle_value)              {               &nbsP;dwfilesize=  httpfile->getlength ();  //gets the number of file bytes                               if   (DWFILESIZE==0XFFFFFFFF)                       return &nbs
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.