Guest User

KWnd.cpp

a guest
Dec 21st, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define _CRT_SECURE_NO_WARNINGS // чтобы компайлер не ругался насчет небезопасности сишного strcat
  2.  
  3. #include "KWnd.h"
  4. #include <Windows.h>
  5.  
  6. KWnd::KWnd(LPCSTR windowName, HINSTANCE hInstance, int cmdShow,
  7.     LRESULT(WINAPI *WndProc)(HWND, UINT, WPARAM, LPARAM),
  8.     LPCSTR menuName, int x, int y, int width, int height,
  9.     UINT classStyle, DWORD windowStyle, HWND hParent)
  10. {
  11.     char szClassName[] = "Class Name";
  12.  
  13.     wc.cbSize = sizeof(wc);
  14.     wc.style = classStyle;
  15.     wc.cbClsExtra = 0;
  16.     wc.cbWndExtra = 0;
  17.     wc.hInstance = hInstance;
  18.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  19.     wc.hCursor = LoadIcon(NULL, IDC_ARROW);
  20.     wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  21.     wc.lpszMenuName = menuName;
  22.     wc.lpszClassName = szClassName;
  23.     wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  24.  
  25.     if (!RegisterClassEx(&wc)) {
  26.         char msg[100] = "Cannot register class: ";
  27.         strcat(msg, szClassName);
  28.         MessageBox(NULL, msg, "Error", MB_OK);
  29.         return;
  30.     }
  31.  
  32.     hWnd = CreateWindow(szClassName, windowName, windowStyle,
  33.         x, y, width, height, hParent, (HMENU)NULL, hInstance, NULL);
  34.  
  35.     if (!hWnd) {
  36.         char msg[100] = "Cannot create window: ";
  37.         strcat(msg, windowName);
  38.         MessageBox(NULL, msg, "Error", MB_OK);
  39.         return;
  40.     }
  41.  
  42.     ShowWindow(hWnd, cmdShow);
  43. }
Add Comment
Please, Sign In to add comment