Моя проблема: я пытаюсь создать кнопку в окне.Звучит просто, но кнопка не появляется.Окно создано, но функция CreateWindow кнопки возвращает 1407: не удается найти класс окна.Я также создаю второе окно, но вы можете игнорировать это.Не могу понять, что не так.Помогите, пожалуйста!Код:
#include "windows.h"
#include "CanvasWndProc.h"
#include "resource.h"
#define IDB_LINE 1001
// Main window handle
HWND hMainWindow;
// Canvas window
HWND hCanvasWindow;
// Line button
HWND hButtonLine;
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case(WM_CREATE):
hButtonLine = CreateWindowEx(0,"ButtonLineClass", "Line", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
10, 10, 100, 100, hWnd, (HMENU)IDB_LINE, GetModuleHandle(0), NULL);
break;
case (WM_DESTROY):
DestroyWindow(hCanvasWindow);
DestroyWindow(hButtonLine);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// MainWindow class
WNDCLASSEX wc;
wc.cbSize = sizeof(wc);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = CreateSolidBrush(RGB(255, 168, 0));
wc.hInstance = hInstance;
wc.lpszClassName = "MainWindowClass";
wc.lpszMenuName = NULL;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MAINICON));
wc.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MAINICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
// CanvasWindow class
WNDCLASSEX wcCanvas;
wcCanvas.cbSize = sizeof(wcCanvas);
wcCanvas.style = CS_HREDRAW | CS_VREDRAW;
wcCanvas.lpfnWndProc = WndProcCanvas;
wcCanvas.cbClsExtra = 0;
wcCanvas.cbWndExtra = 0;
wcCanvas.hbrBackground = CreateSolidBrush(RGB(255, 255, 255));
wcCanvas.hInstance = hInstance;
wcCanvas.lpszClassName = "CanvasWindowClass";
wcCanvas.lpszMenuName = NULL;
wcCanvas.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wcCanvas.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
wcCanvas.hCursor = LoadCursor(NULL, IDC_ARROW);
// Register classes
if (!RegisterClassEx(&wc))
{
MessageBox(NULL, "It was not possible to register a class!", "Error", MB_OK);
return NULL;
}
if (!RegisterClassEx(&wcCanvas))
{
MessageBox(NULL, "It was not possible to register a canvas class!", "Error", MB_OK);
return NULL;
}
// Create and show main window
hMainWindow = CreateWindowEx(NULL,"MainWindowClass", "VPainter", WS_CLIPCHILDREN | WS_VISIBLE |
WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_OVERLAPPED | WS_SYSMENU,
CW_USEDEFAULT, NULL,CW_USEDEFAULT, NULL, NULL, NULL, hInstance, NULL);
if (!hMainWindow)
{
MessageBox(NULL, "It was not possible to create a window!", "Error", MB_OK);
return NULL;
}
ShowWindow(hMainWindow, nCmdShow);
UpdateWindow(hMainWindow);
SendMessage(hMainWindow, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
// Create and show canvas window
RECT MainWindowSize;
GetClientRect(hMainWindow, &MainWindowSize);
hCanvasWindow = CreateWindowEx(NULL, "CanvasWindowClass", NULL, WS_VISIBLE | WS_CHILD,
MainWindowSize.right - (MainWindowSize.right*0.8), MainWindowSize.bottom - (MainWindowSize.bottom*0.9),
MainWindowSize.right - (MainWindowSize.right*0.2), MainWindowSize.bottom - (MainWindowSize.bottom*0.1), hMainWindow,
NULL, hInstance, NULL);
if (!hCanvasWindow)
{
MessageBox(NULL, "It was not possible to create a canvas window!", "Error", MB_OK);
return NULL;
}
ShowWindow(hCanvasWindow, nCmdShow);
UpdateWindow(hCanvasWindow);
// MSC loop
MSG message;
while (GetMessage(&message, NULL, 0, 0))
{
DispatchMessage(&message);
}
return message.wParam;
}