What could be wrong with this control? It show up in the dialog editor but when I rexecute it within a dialog it blocks the executable program from opening the dialog window...
#define __STDC_WANT_LIB_EXT1__ 1
#define WINDOWS_LEAN_AND_MEAN 1
#include <windows.h>
#include <commctrl.h>
#include <custcntl.h>
#include <stdbool.h>
#include <string.h>
#include <tchar.h>
#include "main.h"
/* *** MACROS *** */
#define LM_SETCOLOR WM_USER + 100
/* *** VARIABLES *** */
WNDCLASS ControlWindowClass;
HANDLE LabelLibraryHandle;
HDC DeviceContext;
HBRUSH DefaultBrush;
_TCHAR *LabelText;
/* *** FUNCTIONS *** */
static LRESULT CALLBACK LabelProcedure(HWND Window, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch (Message) {
case WM_CREATE:
DeviceContext = GetDC(Window);
DefaultBrush = GetCurrentObject(DeviceContext, OBJ_BRUSH);
return TRUE;
case WM_GETDLGCODE:
return DLGC_STATIC;
case WM_PAINT:
TextOut(DeviceContext, 12, 0, LabelText, _tcslen(LabelText));
return 0;
case LM_SETCOLOR:
SelectObject(DeviceContext, (HBRUSH)wParam);
return TRUE;
case WM_NCDESTROY:
DeleteObject(DefaultBrush);
return 0;
case WM_SETTEXT:
free(LabelText);
LabelText = _tcsdup((_TCHAR *)lParam);
UpdateWindow (Window);
return TRUE;
case WM_GETTEXT:
_tcscpy_s((_TCHAR *)lParam, wParam, LabelText);
return _tcslen((_TCHAR *)lParam);
case WM_GETTEXTLENGTH:
return _tcslen(LabelText) + 1;
default:
return DefWindowProc(Window, Message, wParam, lParam);
};
};
BOOL WINAPI DllMain(HANDLE Handle, DWORD Reason, LPVOID Reserved)
{
LabelLibraryHandle = Handle;
switch (Reason) {
case DLL_PROCESS_ATTACH:
InitCommonControls();
LabelText = _tcsdup (_T("Label"));
memset (&ControlWindowClass, 0, sizeof (ControlWindowClass));
ControlWindowClass.style = 0;
ControlWindowClass.hInstance = GetModuleHandle(NULL);
ControlWindowClass.lpszClassName = _T("LabelClass");
ControlWindowClass.lpfnWndProc = LabelProcedure;
if (!RegisterClass(&ControlWindowClass)) {
return FALSE;
};
return TRUE;
case DLL_PROCESS_DETACH:
if (!UnregisterClass(_T("LabelClass"), GetModuleHandle(NULL)))
return FALSE;
return TRUE;
default:
return TRUE;
};
};
UINT __declspec(dllexport) CALLBACK CustomControlInfoA(LPCCINFOA CustomControlArguments)
{
if (!CustomControlArguments)
return 2;
memset(&CustomControlArguments[0], 0, sizeof(CustomControlArguments[0]));
CustomControlArguments[0].cxDefault = 80;
CustomControlArguments[0].cyDefault = 8;
CustomControlArguments[0].flStyleDefault = WS_CHILD | WS_VISIBLE;
CustomControlArguments[0].cStyleFlags = 0;
CustomControlArguments[0].aStyleFlags = 0;
CustomControlArguments[0].lpfnStyle = 0;
CustomControlArguments[0].lpfnSizeToText = 0;
lstrcpyn(CustomControlArguments[0].szClass, _T("LabelClass"), CCHCCCLASS);
lstrcpyn(CustomControlArguments[0].szDesc, _T("LabelClass (label.dll)"), CCHCCDESC);
lstrcpyn(CustomControlArguments[0].szTextDefault, _T("Label"), CCHCCTEXT);
return 1;
};