Advertisement
Guest User

Untitled

a guest
Aug 21st, 2014
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.91 KB | None | 0 0
  1. // word processor.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "word processor.h"
  6. #include "windows.h"
  7.  
  8. #define MAX_LOADSTRING 100
  9.  
  10. // Global Variables:
  11. HINSTANCE hInst;                                // current instance
  12. TCHAR szTitle[MAX_LOADSTRING];                  // The title bar text
  13. TCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
  14.  
  15. // Forward declarations of functions included in this code module:
  16. ATOM                MyRegisterClass(HINSTANCE hInstance);
  17. BOOL                InitInstance(HINSTANCE, int);
  18. LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
  19. INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
  20.  
  21. RECT coords;
  22. HWND textboxhandle;
  23.  
  24. int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
  25.                      _In_opt_ HINSTANCE hPrevInstance,
  26.                      _In_ LPTSTR    lpCmdLine,
  27.                      _In_ int       nCmdShow)
  28. {
  29.     UNREFERENCED_PARAMETER(hPrevInstance);
  30.     UNREFERENCED_PARAMETER(lpCmdLine);
  31.  
  32.     // TODO: Place code here.
  33.     MSG msg;
  34.     HACCEL hAccelTable;
  35.  
  36.     // Initialize global strings
  37.     LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  38.     LoadString(hInstance, IDC_WORDPROCESSOR, szWindowClass, MAX_LOADSTRING);
  39.     MyRegisterClass(hInstance);
  40.  
  41.     // Perform application initialization:
  42.     if (!InitInstance (hInstance, nCmdShow))
  43.     {
  44.         return FALSE;
  45.     }
  46.  
  47.     hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WORDPROCESSOR));
  48.  
  49.     // Main message loop:
  50.     while (GetMessage(&msg, NULL, 0, 0))
  51.     {
  52.         if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  53.         {
  54.             TranslateMessage(&msg);
  55.             DispatchMessage(&msg);
  56.         }
  57.     }
  58.  
  59.     return (int) msg.wParam;
  60. }
  61.  
  62.  
  63.  
  64. //
  65. //  FUNCTION: MyRegisterClass()
  66. //
  67. //  PURPOSE: Registers the window class.
  68. //
  69. ATOM MyRegisterClass(HINSTANCE hInstance)
  70. {
  71.     WNDCLASSEX wcex;
  72.  
  73.     wcex.cbSize = sizeof(WNDCLASSEX);
  74.  
  75.     wcex.style          = CS_HREDRAW | CS_VREDRAW;
  76.     wcex.lpfnWndProc    = WndProc;
  77.     wcex.cbClsExtra     = 0;
  78.     wcex.cbWndExtra     = 0;
  79.     wcex.hInstance      = hInstance;
  80.     wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WORDPROCESSOR));
  81.     wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
  82.     wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
  83.     wcex.lpszMenuName   = MAKEINTRESOURCE(IDC_WORDPROCESSOR);
  84.     wcex.lpszClassName  = szWindowClass;
  85.     wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  86.  
  87.     return RegisterClassEx(&wcex);
  88. }
  89.  
  90. //
  91. //   FUNCTION: InitInstance(HINSTANCE, int)
  92. //
  93. //   PURPOSE: Saves instance handle and creates main window
  94. //
  95. //   COMMENTS:
  96. //
  97. //        In this function, we save the instance handle in a global variable and
  98. //        create and display the main program window.
  99. //
  100. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  101. {
  102.    HWND hWnd;
  103.  
  104.    hInst = hInstance; // Store instance handle in our global variable
  105.  
  106.    hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  107.       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
  108.  
  109.    if (!hWnd)
  110.    {
  111.       return FALSE;
  112.    }
  113.  
  114.    ShowWindow(hWnd, nCmdShow);
  115.    UpdateWindow(hWnd);
  116.  
  117.    return TRUE;
  118. }
  119.  
  120. //
  121. //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  122. //
  123. //  PURPOSE:  Processes messages for the main window.
  124. //
  125. //  WM_COMMAND  - process the application menu
  126. //  WM_PAINT    - Paint the main window
  127. //  WM_DESTROY  - post a quit message and return
  128. //
  129. //
  130. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  131. {
  132.     int wmId, wmEvent;
  133.     PAINTSTRUCT ps;
  134.     HDC hdc;
  135.  
  136.     switch (message)
  137.     {
  138.     case WM_SIZE:
  139.    
  140.        
  141.         MoveWindow(textboxhandle, 0, 0, LOWORD(lParam), HIWORD(lParam), true);
  142.         break;
  143.    
  144.     case WM_CREATE:
  145.     {
  146.         GetWindowRect(hWnd, &coords);
  147.         int width = (coords.right - coords.left)-15;
  148.         int height = (coords.bottom - coords.top)-55;
  149.         textboxhandle =CreateWindowEx(NULL, L"EDIT", NULL, WS_VISIBLE | WS_CHILD | WS_BORDER | WS_SIZEBOX | ES_MULTILINE | ES_WANTRETURN | WS_VSCROLL | ES_AUTOVSCROLL, 0, 0, width, height, hWnd, NULL, hInst, NULL);
  150.         break;
  151.     }
  152.     case WM_COMMAND:
  153.         wmId    = LOWORD(wParam);
  154.         wmEvent = HIWORD(wParam);
  155.         // Parse the menu selections:
  156.         switch (wmId)
  157.         {
  158.         case IDM_ABOUT:
  159.             DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  160.             break;
  161.         case IDM_EXIT:
  162.             DestroyWindow(hWnd);
  163.             break;
  164.         default:
  165.             return DefWindowProc(hWnd, message, wParam, lParam);
  166.         }
  167.         break;
  168.     case WM_PAINT:
  169.         hdc = BeginPaint(hWnd, &ps);
  170.         // TODO: Add any drawing code here...
  171.         EndPaint(hWnd, &ps);
  172.         break;
  173.     case WM_DESTROY:
  174.         PostQuitMessage(0);
  175.         break;
  176.     default:
  177.         return DefWindowProc(hWnd, message, wParam, lParam);
  178.     }
  179.     return 0;
  180. }
  181.  
  182. // Message handler for about box.
  183. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  184. {
  185.     UNREFERENCED_PARAMETER(lParam);
  186.     switch (message)
  187.     {
  188.     case WM_INITDIALOG:
  189.         return (INT_PTR)TRUE;
  190.  
  191.     case WM_COMMAND:
  192.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  193.         {
  194.             EndDialog(hDlg, LOWORD(wParam));
  195.             return (INT_PTR)TRUE;
  196.         }
  197.         break;
  198.     }
  199.     return (INT_PTR)FALSE;
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement