Hello,
I would like to try to build a very simple editor but I have some
problems.
I followed:
http://winprog.org/tutorial/simple_window.html
http://www.scintilla.org/Steps.html
However, I don't understand - according to "Steps" I just load
"SciLexer.DLL" and then call CreateWindowEx() with "Scintilla" in
arguments - but how to plug-in the "Window Procedure"? I mean, how to
register the event callbacks if I just call CreateWindowEx() without
RegisterClass(WNDCLASSEX.lpfnWndProc = ...)?
Do I have to create *two* windows? One which provides my custom event
callbacks and other which becomes child of the first one
and .lpszClassName = "Scintilla"?
I'm attaching a small sample, it sort of works (except for window
resizing) but I would like to know if it's possible to make it use
just one window:
Thanks a lot in advance!
#include <windows.h>
const char resourceName[] = "Editor";
const char className[] = "EditorWindow";
static HINSTANCE h;
static HWND editor;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
lParam)
{
switch(msg)
{
case WM_CREATE:
editor = CreateWindow(
"Scintilla",
"Source",
WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_CLIPCHILDREN,
0, 0, 100, 100,
hwnd,
0,
h,
0
);
ShowWindow(editor, SW_SHOW);
SetFocus(editor);
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nCmdShow)
{
h = hInstance;
HINSTANCE hmod;
hmod = LoadLibrary("SciLexer.DLL");
if (hmod==NULL)
{
MessageBox(
NULL,
"The Scintilla DLL could not be loaded.",
"Error loading Scintilla",
MB_OK | MB_ICONERROR
);
}
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszMenuName = resourceName;
wc.lpszClassName = className;
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
HWND hwnd;
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
className,
"Editor",
// WS_OVERLAPPEDWINDOW,
WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX |
WS_MAXIMIZEBOX | WS_MAXIMIZE | WS_CLIPCHILDREN,
CW_USEDEFAULT, CW_USEDEFAULT, 400, 300,
NULL, NULL, hInstance, NULL
);
if(hwnd == NULL)
{
MessageBox(
NULL,
"Window Creation Failed!",
"Error!",
MB_ICONEXCLAMATION | MB_OK
);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
FreeLibrary(hmod);
return msg.wParam;
}