Hi I have a class that creates an edit box, unfortunately it doesn't appear in my main window when I create it.
Code:
#include <windows.h>
#include "window.h"
#include "editcontrol.h"
EditControl::EditControl()
{
}
EditControl::~EditControl()
{
}
int EditControl::Create()
{
Window Window;
m_hEdit = CreateWindowEx(
WS_EX_CLIENTEDGE,
"EDIT",
NULL,
WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
Window.g_hMainWindow,
(HMENU)ID_TEXT,
Window.g_hThisInstance,
NULL
);
SendMessage(Window.g_hMainWindow, WM_SETFONT,
(WPARAM)GetStockObject(DEFAULT_GUI_FONT),
0);
}
Here is my other class which creates a window.
Code:
#include <windows.h>
#include "main.h"
#include "window.h"
Window::Window()
{
}
Window::~Window()
{
}
int Window::Register()
{
//g_szClassName[ ] = "Text Editor";
m_wclx.hInstance = g_hThisInstance;
m_wclx.lpszClassName = g_szClassName;
m_wclx.lpfnWndProc = WindowProcedure;
m_wclx.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
m_wclx.cbSize = sizeof(WNDCLASSEX);
m_wclx.hIcon = static_cast<HICON>(LoadImage(0, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE));
m_wclx.hIconSm = static_cast<HICON>(LoadImage(0, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE));
m_wclx.hCursor = static_cast<HICON>(LoadImage(0, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE));
m_wclx.lpszMenuName = NULL;
m_wclx.cbClsExtra = 0;
m_wclx.cbWndExtra = 0;
m_wclx.hbrBackground = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
if(!RegisterClassEx(&m_wclx))
{
MessageBox(NULL, "Can't register window class!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return -1;
}
return 0;
}
int Window::Create()
{
g_hMainWindow = CreateWindowEx(
WS_EX_APPWINDOW,
g_szClassName,
"Text Editor",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
HWND_DESKTOP,
NULL,
g_hThisInstance,
NULL
);
if(!g_hMainWindow)
{
MessageBox(NULL, "Can't create window!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return -1;
}
return 0;
}
int Window::Menu()
{
g_hMenu = LoadMenu(NULL, MAKEINTRESOURCE(IDM_MENU));
SetMenu(g_hMainWindow, g_hMenu);
}
int Window::Show(int iCmdShow)
{
ShowWindow(g_hMainWindow, iCmdShow);
}
Here is the WinMain()
Code:
#include <windows.h>
#include "editcontrol.h"
#include "window.h"
#include "main.h"
EditControl EditControl;
Window Window;
int WINAPI
WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG messages;
Window.Register();
Window.Create();
Window.Menu();
Window.Show(nCmdShow);
FindReplace.g_uFindReplaceMessage = RegisterWindowMessage(FINDMSGSTRING);
while(GetMessage(&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT messages,
WPARAM wParam, LPARAM lParam)
{
switch(messages)
{
case WM_CREATE:
{
EditControl.Create();
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, messages, wParam, lParam);
}
return 0;
}
If someone could help me I would appreciate it.