Home > Back-end >  When using Windows API createwindow ()
When using Windows API createwindow ()

Time:09-16

#include

Struct
{
Int iStyle;
TCHAR * szText;
}
The button []=
{
BS_DEFPUSHBUTTON, TEXT (" 1 "),
BS_DEFPUSHBUTTON, TEXT (" 2 "),
BS_DEFPUSHBUTTON, TEXT (" 3 "),
BS_DEFPUSHBUTTON, TEXT (" 4 "),
BS_DEFPUSHBUTTON, TEXT (" 5 "),
BS_DEFPUSHBUTTON, TEXT (" 6 "),
};
# define NUM (sizeof button/sizeof button [0])

LRESULT a CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);

LRESULT a CALLBACK WndProcChild (HWND, UINT, WPARAM, LPARAM);

WNDCLASSA wndclasschild;

TCHAR szAppNameChild []=TEXT (" zichuamhkou ");

The static TCHAR szAppName []=TEXT (" window1 ");

The static TCHAR szAppNameButton []=TEXT (" button ");

WNDCLASS WNDCLASS;
WNDCLASS wndchild;

MSG msgchild;

Int WINAPI WinMain (HINSTANCE HINSTANCE, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{



The HWND HWND;
MSG MSG.
//WNDCLASS WNDCLASS;
Wndclass. Style=CS_HREDRAW | CS_VREDRAW;
Wndclass. LpfnWndProc=WndProc;
Wndclass. CbClsExtra=0;
Wndclass. CbWndExtra=0;
Wndclass. HInstance=hInstance;
Wndclass. HIcon=LoadIcon (NULL, IDI_APPLICATION);
Wndclass. HCursor=LoadCursor (NULL, IDC_ARROW);
Wndclass. HbrBackground=(HBRUSH) GetStockObject (WHITE_BRUSH);
Wndclass. LpszMenuName=NULL;
Wndclass. LpszClassName=szAppName;

Wndchild=wndclass;

Wndchild. LpfnWndProc=WndProcChild;
Wndchild. HInstance=hInstance;
Wndchild. LpszClassName=szAppNameChild;
Wndchild. LpszMenuName=(HMENU) 234;




if (! RegisterClass (& amp; Wndclass))
{
MessageBox (NULL, TEXT (" fail!" ), TEXT (" TEXT "), MB_OK);
}


HWND=CreateWindow (szAppName,
The TEXT (" the first window "),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT CW_USEDEFAULT,
500, 500,
NULL, NULL, hInstance, NULL);

ShowWindow (HWND, iCmdShow);
UpdateWindow (HWND);

While (GetMessage (& amp; MSG, NULL, 0, 0))
{
TranslateMessage (& amp; MSG);
DispatchMessage (& amp; MSG);
}

Return MSG. WParam;

}

LRESULT a CALLBACK WndProc (HWND HWND, UINT message, WPARAM WPARAM, LPARAM LPARAM)
{
The static HWND hwndButton (NUM);
The static the RECT the RECT.
/* static TCHAR szTop []=TEXT (" the message wParam lParam "),
SzUnd []=TEXT ("......... "),
SzFormat []=TEXT (" % - 16 s % 4 x - 4 x - 4 x % % % 4 x "),
SzBuffer [50]. */

Static int cxChar, cyChar;
HDC HDC.
PAINTSTRUCT ps;
int i;

The switch (the message)
{
Case WM_CREATE message handler:
CxChar=LOWORD (GetDialogBaseUnits ());
CyChar=HIWORD (GetDialogBaseUnits ());


for (i=0; i {
HwndButton [I]=CreateWindow (szAppNameButton,
The button [I]. SzText,
WS_CHILD | WS_VISIBLE | button [I] iStyle,
2 * cxChar + 25, cyChar * (1 + 3 * I),
50 * cxChar, 7 * cyChar/3,
The HWND,
(HMENU) I,
(LPCREATESTRUCT lParam) - & gt; HInstance,
NULL);
}


return 0;

Case WM_SIZE:

The rect. Left=24 * cxChar;
The rect. Top=2 * cyChar;
The rect. Right=LOWORD (lParam);
The rect. Bottom=HIWORD (lParam);

return 0;

In case the WM_PAINT:

The InvalidateRect (HWND, & amp; The rect, FALSE);
HDC=BeginPaint (HWND, & amp; Ps);
SelectObject (HDC, GetStockObject (SYSTEM_FIXED_FONT));
//SetBKMode (HDC, TRANSPARENT);
//TextOut (HDC, 24 * cxChar, cyChar, szTop, lstrlen (szTop));
//TextOut (HDC, 24 * cxChar, cyChar, szUnd, lstrlen (szUnd));
EndPaint (HWND, & amp; Ps);
return 0;

//case WM_DRAWITEM:
Case WM_COMMAND:

//ScrollWindow (HWND, 0, - cyChar, & amp; The rect, & amp; The rect);
//HDC=GetDC (HWND);
//SelectObject (HDC, GetStockObject (SYSTEM_FIXED_FONT));
/* TextOut (HDC, 24 * cxChar,
CyChar * (the rect. The bottom/cyChar - 1),
SzBuffer,
Wsprintf (szBuffer szFormat, message==WM_DRAWITEM? The TEXT (" WM_DRAWITEM ") : the TEXT (" WM_COMMAND "),
HIWORD (wParam),
The LOWORD (wParam),
HIWORD (lParam),
The LOWORD (lParam))); */
//ReleaseDC (HWND, HDC);

if (! RegisterClass (& amp; Wndchild))
{
MessageBox (NULL, TEXT (" fail!" ), TEXT (" TEXT "), MB_OK);
}



The HWND hwndchild;

Hwndchild=CreateWindow (szAppNameChild,
The TEXT (" the second window "),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT CW_USEDEFAULT,
200, 200,
NULL, (HMENU) 1001, (LPCREATESTRUCT lParam) - & gt; HInstance, NULL);

ShowWindow (HWND, SW_SHOWNORMAL);
UpdateWindow (hwndchild);

While (GetMessage (& amp; Msgchild, NULL, 0, 0))
{
TranslateMessage (& amp; Msgchild);
DispatchMessage (& amp; Msgchild);
}

The ValidateRect (HWND, & amp; The rect);
break;

Case WM_DESTROY:

The PostQuitMessage (0);
return 0;

}

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related