Мучаюсь с шаблоном WinApi. в ссp файле у меня:
#include "stdafx.h"
#include "EDITOR.h"
#include "Windows.h"
EDITOR::EDITOR(
LPCWSTR _lpWindowName, HINSTANCE _hInst, int _nCmdShow,
LRESULT (WINAPI *_pWndProc)(HWND,UINT,WPARAM,LPARAM),
int _nShowOpt,
LPCTSTR _lpMenuName, DWORD _dwWindowStyle,
int _x, int _y, int _nWidth, int _nHeight,
UINT _uClassStyle, HWND _hParent)
{
lpWindowName = _lpWindowName;
hInst = _hInst;
nCmdShow = _nCmdShow;
pWndProc = _pWndProc;
nShowOpt = _nShowOpt;
lpMenuName = _lpMenuName;
dwWindowStyle = _dwWindowStyle;
x = _x;
y = _y;
nWidth = _nWidth;
nHeight = _nHeight;
uClassStyle = _uClassStyle;
hParent = _hParent;
InitWndClass("My Own Class");
RegisterWndClass("My Own Class");
CreateWnd("My Own Class");
ShowWindow(hWnd, nShowOpt);
}
void EDITOR::InitWndClass(LPCSTR szClassName) {
wc.cbSize = sizeof(wc);
wc.style = uClassStyle;
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.lpszMenuName = lpMenuName;
wc.hInstance = hInst;
wc.lpfnWndProc = pWndProc;
wc.lpszClassName = L"szClassName";
}
bool EDITOR::RegisterWndClass(LPCSTR szClassName) {
if (!RegisterClassEx(&wc)) {
char textMsg[] = "Cannot register class: ";
MessageBox(NULL, LPCWSTR(textMsg), LPCWSTR("Error"), MB_OK | MB_ICONERROR);
return false;
}
return true;
}
bool EDITOR::CreateWnd(LPCSTR szClassName) {
lpWindowName = L"Текстовый редактор";
hWnd = CreateWindow(
szClassName, LPCWSTR(lpWindowName), dwWindowStyle, x, y, 600, 350,
hParent, (HMENU)NULL, hInst, NULL);
if (!hWnd) {
char textMsg[] = "Cannot create window: ";
MessageBox(NULL, LPCWSTR(textMsg), L"Error", MB_OK | MB_ICONERROR);
return false;
}
return true;
}
в h. файле у меня
#pragma once
class EDITOR
{
public:
EDITOR(
LPCWSTR _lpWindowName, HINSTANCE _hInst, int _nCmdShow,
LRESULT (WINAPI *pWndProc)(HWND,UINT,WPARAM,LPARAM) = NULL,
int _nShowOpt = SW_SHOW,
LPCTSTR _lpMenuName = NULL,
DWORD _dwWindowStyle = WS_OVERLAPPEDWINDOW,
int _x = CW_USEDEFAULT, int _y = 0,
int _nWidth = CW_USEDEFAULT, int _nHeight = 0,
UINT _uClassStyle = CS_HREDRAW | CS_VREDRAW,
HWND _hParent = NULL );
public:
void InitWndClass(LPCSTR szClassName);
bool RegisterWndClass(LPCSTR szClassName);
bool CreateWnd(LPCSTR szClassName);
protected:
LPCWSTR lpWindowName;
HINSTANCE hInst;
int nCmdShow;
LPCTSTR lpMenuName;
DWORD dwWindowStyle;
int x, y;
int nWidth, nHeight;
UINT uClassStyle;
HWND hParent;
LRESULT (WINAPI *pWndProc)(HWND,UINT,WPARAM,LPARAM);
LRESULT (WINAPI *pWndProc2)(HWND,UINT,WPARAM,LPARAM) ;
int nShowOpt;
protected:
HWND hWnd;
WNDCLASSEX wc;
};"
Ошибка возникает в :
Ошибка 1 error C2664: CreateWindowExW: невозможно преобразовать параметр 2 из "LPCSTR" в "LPCWSTR"
Подскажите, пожалуйста, как можно решить эту проблему?