Code:
#include <windows.h>
#include <iostream>
#include <string>
#include <process.h>
using namespace std;
class label
{
private:
HWND hwnd;
WNDCLASS wc;
WNDPROC m_pfnPrevWndProc;
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
WNDPROC oldproc =(WNDPROC)GetWindowLongPtr(GetParent(hwnd),GWLP_USERDATA);
UINT i=(UINT)GetWindowLongPtr(GetParent(hwnd),GWLP_USERDATA);
switch(msg)
{
case WM_NCCREATE:
{
CREATESTRUCT *createstruct = (CREATESTRUCT*)lParam;
SetWindowLong(hwnd, GWL_USERDATA, (long)createstruct->lpCreateParams);
}
break;
case WM_CREATE:
{
SetWindowText(hwnd,"hello world");
break;
}
case WM_MOUSEMOVE:
{
SetWindowText(hwnd,"mouse move");
break;
}
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return (CallWindowProc(oldproc, hwnd, msg, wParam, lParam));
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
public:
label(HWND value)
{
ZeroMemory(&wc, sizeof(WNDCLASS));
GetClassInfo((HINSTANCE)GetModuleHandle(NULL), "STATIC", &wc);
wc.hInstance = (HINSTANCE)GetModuleHandle(NULL);
wc.lpszClassName = "CSTATIC";
// store the old WNDPROC of the EDIT window class
m_pfnPrevWndProc = wc.lpfnWndProc;
// replace it with local WNDPROC
wc.lpfnWndProc = WndProc;
// register the new window class, "ShEdit"
if (!RegisterClass(&wc)) MessageBox(NULL,"error","error",MB_OK);
hwnd = CreateWindowEx(
WS_EX_LEFT| WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR,
"CSTATIC",
"hello",
SS_LEFT|WS_CHILD|WS_VISIBLE,
0, 0, 100, 100,
value,
NULL,
GetModuleHandle(NULL),
NULL);
if(hwnd==NULL) MessageBox(NULL,"error","error",MB_OK);
SetWindowLongPtr (GetParent(hwnd),GWLP_USERDATA,(LONG_PTR)m_pfnPrevWndProc);
ShowWindow(hwnd,SW_SHOW);
UpdateWindow(hwnd);
}
COORD GetSize()
{
RECT LabelSize;
GetWindowRect(hwnd,&LabelSize);
COORD crdSize={LabelSize.right-LabelSize.left,LabelSize.bottom-LabelSize.top};
return crdSize;
}
void SetText(string text)
{
char* chrText=(char*)text.c_str();
SetWindowText(hwnd, chrText);
}
};
the control is showed, but the window procedure isn't right... because i don't have access to WM_CREATE and others