Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2014
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. #include <windows.h>
  5.  
  6. const char g_szClassName[] = "myWindowClass";
  7. const char class2[] = "class2";
  8.  
  9. #define IDC_MAIN_BUTTON 101         // Button identifier
  10. #define IDC_MAIN_EDIT   102         // Edit box identifier
  11. HWND hEdit, hEdit2, w2;
  12.  
  13. LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  14. LRESULT CALLBACK WinProc2(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  15.  
  16. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  17.     LPSTR lpCmdLine, int nCmdShow)
  18. {
  19.     WNDCLASSEX wc, wc2;
  20.     HWND hwnd;
  21.     MSG Msg;
  22.  
  23.     //Step 1: Registering the Window Class
  24.     wc.cbSize = sizeof(WNDCLASSEX);
  25.     wc.style = 0;
  26.     wc.lpfnWndProc = WinProc;
  27.     wc.cbClsExtra = 0;
  28.     wc.cbWndExtra = 0;
  29.     wc.hInstance = hInstance;
  30.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  31.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  32.     wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
  33.     wc.lpszMenuName = NULL;
  34.     wc.lpszClassName = g_szClassName;
  35.     wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  36.    
  37.     wc2.cbSize = sizeof(WNDCLASSEX);
  38.     wc2.style = 0;
  39.     wc2.lpfnWndProc = WinProc2;
  40.     wc2.cbClsExtra = 0;
  41.     wc2.cbWndExtra = 0;
  42.     wc2.hInstance = hInstance;
  43.     wc2.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  44.     wc2.hCursor = LoadCursor(NULL, IDC_ARROW);
  45.     wc2.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
  46.     wc2.lpszMenuName = NULL;
  47.     wc2.lpszClassName = class2;
  48.     wc2.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  49.  
  50.     if (!RegisterClassEx(&wc) || !RegisterClassEx(&wc2))
  51.     {
  52.         MessageBox(NULL, "Window Registration Failed!", "Error!",
  53.             MB_ICONEXCLAMATION | MB_OK);
  54.         return 0;
  55.     }  
  56.    
  57.     // Step 2: Creating the Window
  58.     hwnd = CreateWindowEx(
  59.         WS_EX_CLIENTEDGE,
  60.         g_szClassName,
  61.         "The title of my window",
  62.         WS_OVERLAPPEDWINDOW,
  63.         CW_USEDEFAULT, CW_USEDEFAULT, 480, 480,
  64.         NULL, NULL, hInstance, NULL);
  65.  
  66.     if (hwnd == NULL)
  67.     {
  68.         MessageBox(NULL, "Window Creation Failed!", "Error!",
  69.             MB_ICONEXCLAMATION | MB_OK);
  70.         return 0;
  71.     }
  72.  
  73.     ShowWindow(hwnd, nCmdShow);
  74.     UpdateWindow(hwnd);
  75.  
  76.     // Step 3: The Message Loop
  77.     while (GetMessage(&Msg, NULL, 0, 0) > 0)
  78.     {
  79.         TranslateMessage(&Msg);
  80.         DispatchMessage(&Msg);
  81.     }
  82.     return Msg.wParam;
  83. }
  84. LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  85. {
  86.     switch (msg)
  87.     {
  88.         case WM_CREATE:
  89.         {                  
  90.             hEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
  91.                 "EDIT",
  92.                 "",
  93.                 WS_CHILD | WS_VISIBLE |
  94.                 ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
  95.                 50,
  96.                 100,
  97.                 200,
  98.                 25,
  99.                 hWnd,
  100.                 (HMENU) IDC_MAIN_EDIT,
  101.                 GetModuleHandle(NULL),
  102.                 NULL);
  103.            
  104.             HGDIOBJ hfDefault = GetStockObject(DEFAULT_GUI_FONT);
  105.             SendMessage(hEdit,
  106.                 WM_SETFONT,
  107.                 (WPARAM) hfDefault,
  108.                 MAKELPARAM(FALSE, 0));
  109.  
  110.             SendMessage(hEdit,
  111.                 WM_SETTEXT,
  112.                 NULL,
  113.                 (LPARAM)"Insert text here...");
  114.  
  115.             // Create a push button
  116.             HWND hWndButton = CreateWindowEx(NULL,
  117.                 "BUTTON",
  118.                 "OK",
  119.                 WS_TABSTOP | WS_VISIBLE |
  120.                 WS_CHILD | BS_DEFPUSHBUTTON,
  121.                 50,
  122.                 220,
  123.                 100,
  124.                 24,
  125.                 hWnd,
  126.                 (HMENU) IDC_MAIN_BUTTON,
  127.                 GetModuleHandle(NULL),
  128.                 NULL);
  129.             /*SendMessage(hWndButton,
  130.                 WM_SETFONT,
  131.                 (WPARAM) hfDefault,
  132.                 MAKELPARAM(FALSE, 0));*/
  133.  
  134.             w2 = CreateWindowEx(
  135.                 WS_EX_CLIENTEDGE,
  136.                 class2,
  137.                 "window 2",
  138.                 WS_TILEDWINDOW,
  139.                 CW_USEDEFAULT, CW_USEDEFAULT, 480, 480,
  140.                 hWnd, NULL, NULL, NULL);
  141.  
  142.             WINDOWINFO wi;
  143.             GetWindowInfo(hWnd, &wi);
  144.             //keep from overlapping
  145.             SetWindowPos(w2, NULL, wi.rcWindow.right + 25, wi.rcWindow.top, 480, 480, NULL);
  146.  
  147.             ShowWindow(w2, 1);
  148.         }
  149.         break;
  150.  
  151.     case WM_COMMAND:
  152.         switch (LOWORD(wParam))
  153.         {
  154.             case IDC_MAIN_BUTTON:
  155.             {
  156.                 char buffer[256];
  157.                 SendMessage(hEdit,
  158.                     WM_GETTEXT,
  159.                     sizeof(buffer) / sizeof(buffer[0]),
  160.                     reinterpret_cast<LPARAM>(buffer));
  161.                 SendMessage(hEdit2,
  162.                     WM_SETTEXT,
  163.                     sizeof(buffer) / sizeof(buffer[0]),
  164.                     reinterpret_cast<LPARAM>(buffer));                                     
  165.             }
  166.             break;
  167.         }
  168.         break;
  169.  
  170.         case WM_DESTROY:
  171.         {
  172.             PostQuitMessage(0);
  173.             return 0;
  174.         }
  175.         break;
  176.     }
  177.  
  178.     return DefWindowProc(hWnd, msg, wParam, lParam);
  179. }
  180. LRESULT CALLBACK WinProc2(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  181. {
  182.     switch (msg)
  183.     {
  184.         case WM_CREATE:
  185.         {
  186.             // Create an edit box
  187.             hEdit2 = CreateWindowEx(WS_EX_CLIENTEDGE,
  188.                 "EDIT",
  189.                 "",
  190.                 WS_CHILD | WS_VISIBLE |
  191.                 ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
  192.                 50,
  193.                 100,
  194.                 360,
  195.                 260,
  196.                 hWnd,
  197.                 (HMENU) IDC_MAIN_EDIT,
  198.                 GetModuleHandle(NULL),
  199.                 NULL);
  200.             HGDIOBJ hfDefault = GetStockObject(DEFAULT_GUI_FONT);
  201.  
  202.             SendMessage(hEdit2,
  203.                 WM_SETFONT,
  204.                 (WPARAM) hfDefault,
  205.                 MAKELPARAM(FALSE, 0));                                       
  206.         }
  207.         break;
  208.  
  209.         case WM_COMMAND:
  210.             switch (LOWORD(wParam))
  211.             {
  212.            
  213.             }
  214.             break;
  215.  
  216.         case WM_DESTROY:
  217.         {
  218.             PostQuitMessage(0);
  219.             return 0;
  220.         }
  221.         break;
  222.     }
  223.  
  224.     return DefWindowProc(hWnd, msg, wParam, lParam);
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement