#include "alfpriv.h" TCHAR _alf_controlClass[28] = {0}; static LRESULT CALLBACK ALF_Control_InitialWindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { if (msg == WM_NCCREATE) { ALFControlCreateParams *params = (ALFControlCreateParams *)((CREATESTRUCT *)lparam)->lpCreateParams; SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)params->windowProc); return params->windowProc(hwnd, msg, wparam, lparam); } return DefWindowProc(hwnd, msg, wparam, lparam); } void ALF_RegisterControlClass(void) { WNDCLASS cls; ZeroMemory(&cls, sizeof(cls)); wsprintf(_alf_controlClass, TEXT("ALFControl.%p"), (ULONG_PTR)&_alf_controlClass[0]); cls.style = CS_DBLCLKS; cls.hInstance = ALF_HINSTANCE; cls.hCursor = LoadCursor(NULL, (LPTSTR)IDC_ARROW); cls.lpszClassName = _alf_controlClass; cls.cbWndExtra = sizeof(void*); cls.lpfnWndProc = ALF_Control_InitialWindowProc; ATOM classatom = RegisterClass(&cls); if (!classatom) MessageBox(NULL, TEXT("FATAL: Could not register control class"), NULL, MB_OK); } HWND ALF_CreateControlWindow(DWORD exstyle, const TCHAR *text, DWORD style, int x, int y, int w, int h, HWND parent, HMENU hmenu, WNDPROC windowProc, void *param) { ALFControlCreateParams p = { windowProc, param }; return CreateWindowEx(exstyle, _alf_controlClass, text, style, x, y, w, h, parent, hmenu, ALF_HINSTANCE, &p); }