Advertisement
Guest User

Untitled

a guest
Nov 11th, 2015
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.79 KB | None | 0 0
  1. #if defined(UNICODE) && !defined(_UNICODE)
  2.     #define _UNICODE
  3. #elif defined(_UNICODE) && !defined(UNICODE)
  4.     #define UNICODE
  5. #endif
  6.  
  7. #include <tchar.h>
  8. #include <windows.h>
  9. #define ID_CHECKTXT 1
  10. #define ID_BUTTON 1
  11. #define ID_BUTTON1 1
  12. #define ID_BUTTON2 2
  13. #define TEXT_INPUT 100
  14. #include <fstream>
  15. #include <iostream>
  16. using namespace std;
  17.  
  18. /*  Declare Windows procedure  */
  19. LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
  20.  
  21. /*  Make the class name into a global variable  */
  22. TCHAR szClassName[ ] = _T("Simon");
  23.  
  24.  
  25. int WINAPI WinMain (HINSTANCE hThisInstance,
  26.                      HINSTANCE hPrevInstance,
  27.                      LPSTR lpszArgument,
  28.                      int nCmdShow)
  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 (NULL, IDI_APPLICATION);
  43.     wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
  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 colour as the background of the window */
  49.     wincl.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  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.            _T("Notepad by Simon"),       /* Title Text */
  60.            WS_OVERLAPPEDWINDOW, /* default window */
  61.            CW_USEDEFAULT,       /* Windows decides the position */
  62.            CW_USEDEFAULT,       /* where the window ends up on the screen */
  63.            544,                 /* The programs width */
  64.            375,                 /* 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, nCmdShow);
  73.  
  74.     /* Run the message loop. It will run until GetMessage() returns 0 */
  75.     while (GetMessage (&messages, NULL, 0, 0))
  76.     {
  77.         /* Translate virtual-key messages into character messages */
  78.         TranslateMessage(&messages);
  79.         /* Send message to WindowProcedure */
  80.         DispatchMessage(&messages);
  81.     }
  82.  
  83.     /* The program return-value is 0 - The value that PostQuitMessage() gave */
  84.     return messages.wParam;
  85. }
  86.  
  87.  
  88. /*  This function is called by the Windows function DispatchMessage()  */
  89.  
  90. LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  91. {
  92.     switch (message)                  /* handle the messages */
  93.     {
  94.         case WM_CREATE:{
  95.  
  96.  
  97.  
  98.                   CreateWindow( TEXT("BUTTON"),
  99.                     TEXT("TXT"),
  100.                     WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,
  101.                     400, 300, 80, 20,
  102.                     hwnd,
  103.                     (HMENU) ID_BUTTON1,
  104.                     NULL,
  105.                     NULL);
  106.  
  107.                     CreateWindow( TEXT("BUTTON"),
  108.                     TEXT("HTML"),
  109.                     WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,
  110.                     300, 300, 80, 20,
  111.                     hwnd,
  112.                     (HMENU) ID_BUTTON2,
  113.                     NULL,
  114.                     NULL);
  115.  
  116.  
  117.  
  118.     CreateWindow( TEXT("EDIT"),
  119.                   TEXT(""),
  120.                   WS_VISIBLE | WS_CHILD | WS_BORDER |ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL,
  121.                   10, 10, 510, 250,
  122.                   hwnd,
  123.                   (HMENU) TEXT_INPUT,
  124.                 NULL, NULL);
  125.  
  126.                 case WM_COMMAND:{
  127.                     if (LOWORD(wParam) == ID_BUTTON1){
  128.                     TCHAR tcInput [256];
  129.  
  130.                 GetWindowText (GetDlgItem (hwnd, TEXT_INPUT), tcInput, 256);
  131.                 MessageBox (hwnd, tcInput, "Your TXT file is sucsefully safed", NULL);
  132.  
  133.  
  134.                 ofstream myfile;
  135.                 myfile.open ("file.txt");
  136.                 myfile << tcInput;
  137.                 myfile.close();
  138.                 return 0;
  139.                     }
  140.  
  141.                                     if (LOWORD(wParam) == ID_BUTTON2){
  142.                                         TCHAR tcInput [256];
  143.  
  144.                 GetWindowText (GetDlgItem (hwnd, TEXT_INPUT), tcInput, 256);
  145.                 MessageBox (hwnd, tcInput, "Your HTML file is sucsefully safed", NULL);
  146.  
  147.  
  148.                 ofstream myfile;
  149.                 myfile.open ("file.html");
  150.                 myfile << tcInput;
  151.                 myfile.close();
  152.                 return 0;
  153.                     }
  154.                     break;
  155.  
  156.                 }
  157.  
  158.  
  159. }
  160.  
  161.         case WM_DESTROY:
  162.             PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
  163.             break;
  164.         default:                      /* for messages that we don't deal with */
  165.             return DefWindowProc (hwnd, message, wParam, lParam);
  166.     }
  167.  
  168.     return 0;
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement