Advertisement
Guest User

Maa

a guest
May 18th, 2011
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.21 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <string>
  4. #include <windows.h>
  5. #include <curl/curl.h>
  6.  
  7. using namespace std;
  8. string outData;
  9.  
  10.  size_t w_data(void *buffer, size_t size, size_t nmemb, void *userp)
  11.     {
  12.       outData.append((char*)buffer, size*nmemb);
  13.         return size*nmemb;
  14.     }
  15.      
  16. /*  Declare Windows procedure  */
  17. LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
  18.  
  19. /*  Make the class name into a global variable  */
  20. char szClassName[ ] = "WindowsApp";
  21.  
  22.  
  23.  
  24. int WINAPI WinMain (HINSTANCE hThisInstance,
  25.                     HINSTANCE hPrevInstance,
  26.                     LPSTR lpszArgument,
  27.                     int nFunsterStil)
  28.  
  29. {
  30.     HWND hwnd;               /* This is the handle for our window */
  31.     MSG messages;            /* Here messages to the application are saved */
  32.     WNDCLASSEX wincl;        /* Data structure for the windowclass */
  33.    
  34.     /* The Window structure */
  35.     wincl.hInstance = hThisInstance;
  36.     wincl.lpszClassName = szClassName;
  37.     wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
  38.     wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
  39.     wincl.cbSize = sizeof (WNDCLASSEX);
  40.  
  41.     /* Use default icon and mouse-pointer */
  42.     wincl.hIcon = LoadIcon(GetModuleHandle(0), NULL);
  43.     wincl.hIconSm = LoadIcon(GetModuleHandle(0), NULL);
  44.     wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
  45.     wincl.lpszMenuName = NULL;                 /* No menu */
  46.     wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
  47.     wincl.cbWndExtra = 0;                      /* structure or the window instance */
  48.     /* Use Windows's default color as the background of the window */
  49.    wincl.hbrBackground = (HBRUSH) (COLOR_BACKGROUND + 4);
  50.  
  51.    /* Register the window class, and if it fails quit the program */
  52.    if (!RegisterClassEx (&wincl))
  53.        return 0;
  54.  
  55.    /* The class is registered, let's create the program*/
  56.     hwnd = CreateWindowEx (
  57.            0,                         /* Extended possibilites for variation */
  58.            szClassName,               /* Classname */
  59.            "Title",                   /* Title Text */
  60.            WS_SYSMENU,                /* default window */
  61.            CW_USEDEFAULT,             /* Windows decides the position */
  62.            CW_USEDEFAULT,             /* where the window ends up on the screen */
  63.            330,                       /* The programs width */
  64.            390,                       /* and height in pixels */
  65.            HWND_DESKTOP,              /* The window is a child-window to desktop */
  66.            NULL,                      /* No menu */
  67.            hThisInstance,             /* Program Instance handler */
  68.            NULL                       /* No Window Creation data */
  69.            );
  70.  
  71.     /* Make the window visible on the screen */
  72.     ShowWindow (hwnd, nFunsterStil);
  73.    
  74. // CENTER WINDOW---------------------------------------------------------    
  75.    RECT rc;
  76.     int screenWidth = GetSystemMetrics(SM_CXSCREEN);
  77.     int screenHeight = GetSystemMetrics(SM_CYSCREEN);
  78.     GetWindowRect(hwnd, &rc);
  79.     SetWindowPos(hwnd, 0, (screenWidth - rc.right)/2,
  80.         (screenHeight - rc.bottom)/2, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
  81. //-----------------------------------------------------------------------
  82.  
  83.     /* Run the message loop. It will run until GetMessage() returns 0 */
  84.     while (GetMessage (&messages, NULL, 0, 0))
  85.     {
  86.         /* Translate virtual-key messages into character messages */
  87.         TranslateMessage(&messages);
  88.         /* Send message to WindowProcedure */
  89.         DispatchMessage(&messages);
  90.     }
  91.  
  92.     /* The program return-value is 0 - The value that PostQuitMessage() gave */
  93.     return messages.wParam;
  94. }
  95.  
  96.  
  97. /*  This function is called by the Windows function DispatchMessage()  */
  98.  
  99.  
  100. LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  101. {    
  102.                                        
  103.     switch (message)                  /* handle the messages */
  104.     {
  105.         case WM_CREATE: {
  106.         CreateWindow("button", "test",
  107.            WS_CHILD | WS_VISIBLE,
  108.            0, 0, 70, 30,
  109.            hwnd, (HMENU) 1,
  110.            NULL, NULL);  
  111.                  
  112.           }
  113.           break;
  114.          
  115.          case WM_COMMAND:
  116.              
  117.   if(LOWORD(wParam)==1) {
  118.  
  119.            CURL *curl;
  120.            CURLcode res;
  121.            curl = curl_easy_init();  
  122.                if(curl) {              
  123.                   curl_easy_setopt(curl, CURLOPT_URL, "http://edition.cnn.com/");
  124.                    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,w_data);
  125.                     res = curl_easy_perform(curl);    
  126.                      /* always cleanup */
  127.                             curl_easy_cleanup(curl);
  128.                   }
  129.                
  130.                }
  131.                          
  132.            break;
  133.         case WM_DESTROY:
  134.             PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
  135.             break;
  136.        
  137.        
  138.         default:                      /* for messages that we don't deal with */
  139.        
  140.            return DefWindowProc (hwnd, message, wParam, lParam);
  141.    }                
  142.  
  143.    return 0;
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement