Home > Software engineering >  WINAPI interface, create a window class about yourself does not display window
WINAPI interface, create a window class about yourself does not display window

Time:01-05

Background: I want to be a child window dialog box, but since the goal is to do an interface library, so can't use to. Throw in rc dialog. Create a dialog when need initial control, if I use # 32770 when creating the window dialog box, does not handle WM_CREATE message handler, cannot create response and
So, I want to create your own window class should be response WM_CREATE message handler ( I don't know but I want to try, if you have better way can also
 namespace NormalTip {
HINSTANCE b_hInstance;
The HWND c_tip1;
The HWND c_tip2;
WNDPROC TipBoxProc;
WNDPROC BTold;

Typedef struct TagTipBox
{//
The HWND HWND;
BOOL x1;
BOOL x2.
LPWSTR in;
UINT style;
} TIP_PARAM;
Int NormalTipHeight=40;
Int nh=NormalTipHeight;
Void DrawFrameBtn (HDC HDC, HPEN HPEN, the RECT the RECT, BOOL wid, a COLORREF cl)
{
Hpen=CreatePen (PS_SOLID, wid, cl);
SelectObject (HDC, hpen);
SelectObject (HDC, (HBRUSH) GetStockObject (NULL_BRUSH));
//a Rectangle (HDC, 0, 0, the rect. Right - the rect. Left, the rect. The bottom - the rect. Top);
A Rectangle (HDC, 2, 2, the rect. Right - the rect. Left - 1, the rect. The bottom - the rect. Top - 1);
}

}


//
//
LRESULT a CALLBACK CTipProc (HWND HWND, UINT Msg, WPARAM WPARAM, LPARAM LPARAM)
{//
Using the namespace: : NormalTip;
PAINTSTRUCT ps;
HDC HDC=NULL;
The RECT rc;
GetClientRect (hWnd, & amp; Rc);
LOGFONT lf.
HFONT HFONT=0;
HBRUSH br;
TCHAR TXT [40].

LParam TIP_PARAM * PMMB=(TIP_PARAM *);
UNREFERENCED_PARAMETER (lParam);

The switch (Msg)
{//
Case WM_/* I get class purpose is to make it display controls when created, and the effect of the WM_CREATE message handler is almost */:
{
//Button (hWnd, 1, 1, L "closed", 999);
OutputDebugStringA (Button__ "Created");//
break;
}
In case the WM_PAINT:
{
HBRUSH gets=NULL;
HPEN HPEN=0;
HDC=BeginPaint (hWnd, & amp; Ps);


Gets=CreateSolidBrush (UICOLOR_BUTTON);
FillRect (HDC, & amp; Rc, gets);
GetWindowText (hWnd, TXT, 40);
SetTextColor (HDC, UICOLOR_BUTTON_TEXT);
SetBkMode (HDC, TRANSPARENT);
If (hFont==0)
{
Memset (& amp; Lf, 0, sizeof (LOGFONT));
Lf. LfHeight=- 16;
Wcscpy (lf) lfFaceName, L "bold");
HFont=CreateFontIndirect (& amp; Lf);//create the font
}
HFONT old=(HFONT) SelectObject (HDC, HFONT);
//TextOut (HDC, 16, 7, TXT, wcslen (TXT)/* & amp; Ps. RcPaint *//* DT_SINGLELINE | DT_CENTER | DT_VCENTER */);
DrawText (HDC, TXT, wcslen (TXT), & amp; Rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);

DrawFrameBtn (HDC, hpen, rc, 2, UICOLOR_BUTTON);

ReleaseDC (hWnd, HDC);
UpdateWindow (hWnd);
DeleteObject (gets);
DeleteObject (hpen);
EndPaint (hWnd, & amp; Ps);
OutputDebugStringA (Tip "Created");

break;
}
Case WM_LBUTTONDOWN:
{
//move window
SendMessage (hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);//send WM_NCLBUTTONDOWN message to the window, HTCAPTION title
break;
}
}
//
Return CallWindowProc (TipBoxProc hWnd, Msg, wParam, lParam);

}

WCHAR szWindowClasst []=L "TipBoxClass";
The ATOM _TipBoxRegisterClass (HINSTANCE HINSTANCE)
{
Using the namespace: : NormalTip;
WNDCLASSEXW wcex;

Wcex. CbSize=sizeof (modifed WNDCLASSEX);

Wcex. Style=CS_HREDRAW | CS_VREDRAW;
Wcex. LpfnWndProc=CTipProc;
Wcex. CbClsExtra=0;
Wcex. CbWndExtra=0;
Wcex. HInstance=b_hInstance;
Wcex. HIcon=LoadIcon (hInstance, 0).
Wcex. HCursor=LoadCursor (nullptr, 0).
Wcex. HbrBackground=CreateSolidBrush (RGB (239, 244, 255));
Wcex. LpszMenuName=MAKEINTRESOURCEW (0);
Wcex. LpszClassName=szWindowClasst;
Wcex. HIconSm=LoadIcon (wcex hInstance, MAKEINTRESOURCE (IDI_SMALL));

Return RegisterClassExW (& amp; Wcex);
}
//HWND main window, __x1 x coordinates, __x2 y, L "text", the corresponding message processing
//if the need for message processing, case IDC_XX:
Int VertexUITipBox (
The HWND HWND,//handle of the owner window
BOOL x1,
BOOL x2,
LPCTSTR in,
UINT style//
)
{
Using the namespace: : NormalTip;

Int len=wcslen (in);
If (len & gt; 3)
{
If (wcslen (in) % 2==0)
{
Len=len * 2 * 9 + 18;
}
The else
{
Len=len * 8 + 20;
}
}
The else
{
Len=60;
}
if (! _TipBoxRegisterClass (b_hInstance))
{
MessageBox (0, 0, 0, 0);//error detection, but this seems to be yes
}
The static HFONT HFONT;
TIP_PARAM tip;
Tip #. The hWnd=hWnd;
Tip #. Style=style;
C_tip1=CreateWindow (L "TipBoxClass", in the WS_VISIBLE | WS_CHILD,//the default button style
X1, x2, len, 90, the hWnd, (HMENU) style, b_hInstance, NULL);
TipBoxProc=(WNDPROC) SetWindowLongPtr (c_tip1 GWLP_WNDPROC, LONG_PTR CTipProc);

return -1;
}

 TipBox (hWnd, 114, 514, L "text", 0 x80); 

In order to convenient debugging can be put in the CreateWindow TipBoxClass temporarily changed back # 32770
Don't use the method of adding the Dialog resource file thank you
this is all the code, the goal is to solve the problem of class to create and implement in the child window to create the corresponding response.
  • Related