Home > Software engineering >  Win32. Create a window class registered window class, create a window, break the window. But the win
Win32. Create a window class registered window class, create a window, break the window. But the win

Time:09-21

 
#include
#include

LRESULT a CALLBACK WinSunProc (
HWND HWND, window handle/* */
UINT uMsg,/* information identification */
WPARAM WPARAM,
LPARAM LPARAM
);

Int WINAPI WinMain (
HINSTANCE HINSTANCE, handle to the current instance *//*
HINSTANCE hPrevInstance,/* handle to an instance on */
LPSTR lpCmdLine,/* command line */
Int nCmdShow/* display status */
)
{
Design a window class/* */
WNDCLASS wndcle;
Wndcle. CbClsExtra=0;
Wndcle. CbWndExtra=0;
Wndcle. HbrBackground=(HBRUSH) GetStockObject (BLACK_BRUSH);
Wndcle. HCursor=LoadCursor (NULL, IDC_CROSS);
Wndcle. HIcon=LoadIcon (NULL, IDI_ERROR);
Wndcle. HInstance=hInstance;
Wndcle. LpfnWndProc=WinSunProc;
Wndcle. LpszClassName=TEXT (" lpl2018 ");
Wndcle. LpszMenuName=NULL;
Wndcle. Style=CS_HREDRAW | CS_VREDRAW;

RegisterClass (& amp; Wndcle);


Char pszErrMsg [128]={0};

/* create a window, define a variable used to store the returned after successfully created window handle */
The HWND HWND;
HWND=CreateWindow (TEXT (" LCK2018 "), TEXT (" http://www.baidu.com "), WS_OVERLAPPEDWINDOW, 0, 0, 600, 400, NULL, NULL, hInstance, NULL);
If (HWND==NULL) {
Snprintf (pszErrMsg, sizeof (pszErrMsg), TEXT (" err [% d] "), GetLastError ());
OutputDebugString (pszErrMsg);
CreateWindow MessageBox (NULL, "Err", "Error", 0).
}

/* * display and refresh the window/
ShowWindow (HWND, SW_SHOWNORMAL);
UpdateWindow (HWND);

/* define the message structure, start message loop */
MSG MSG.
While (GetMessage (& amp; MSG, NULL, 0, 0))
{
TranslateMessage (& amp; MSG);
DispatchMessage (& amp; MSG);
}
Return MSG. WParam;

}

/* write */window procedure function
LRESULT a CALLBACK WinSunProc (
HWND HWND, window handle/* */
UINT uMsg,/* information identification */
WPARAM WPARAM,
LPARAM LPARAM
)
{

The switch (uMsg)
{
Case WM_CHAR:
Char szChar [20].
Sprintf_s (szChar, "char code is % d", wParam);
MessageBox (HWND szChar, TEXT (" char "), 0).
break;
Case WM_LBUTTONDOWN:
MessageBox (HWND, "mouse clicked", "message", 0).
HDC HDC.
HDC=GetDC (HWND);/* no longer WM_PAINT message when the corresponding */
TextOut (HDC, 0, 50, TEXT (" LOL HOME "), strlen (" LOL HOME "));
/* ReleaseDC (HWND, HDC); */
break;
In case the WM_PAINT:
HDC HDC.
PAINTSTRUCT ps;
HDc=BeginPaint (HWND, & amp; Ps);/* BeginPaint only in response to a WM_PAINT message when the */
TextOut (hDc, 0, 0, "http://www.csdn.com", strlen (" http://www.csdn.com "));
EndPaint (HWND, & amp; Ps);
break;
Case WM_CLOSE:
If (IDYES==MessageBox (HWND, "Is the End?" , the "message", MB_YESNO))
{
The DestroyWindow (HWND);
}
Case WM_DESTROY:
The PostQuitMessage (0);
break;
Default:
Return DefWindowProc (HWND, uMsg wParam, lParam);
}

return 0;
}


CreateWindow returns NULL, GetLastError is 1407. Is a class I fill in missing or fill in the wrong?

CodePudding user response:

 wndcle. LpszClassName=TEXT (" lpl2018 "); 
The HWND=CreateWindow (TEXT (" LCK2018 "), TEXT (" http://www.baidu.com "), WS_OVERLAPPEDWINDOW, 0, 0, 600, 400, NULL, NULL, hInstance, NULL);

You register the name of the class to create the name of the class

CodePudding user response:

"Lpl2018 registered name
""LCK2018 create name
"Don't match!

CodePudding user response:

1047 error code corresponding to the error message is: "can't find the window class,"

So 1 2 floor said, is your problem.

MSDN, there are detailed description
The HWND CreateWindow (LPCTSTR lpClassName,
LPCTSTR lpWindowName,
DWORD dwStyle,
Int x,
Int y,
Int nWidth,
Int nHeight,
The HWND hWndParent,
HMENU HMENU,
HINSTANCE HINSTANCE,
LPVOID lpParam
);
The Parameters

LpClassName
[in] Pointer to a null - terminated string or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low - order word of lpClassName; The high - order word must be zero. If lpClassName is a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, provided that the module that registers the class is also the module that creates the window. the class name can also be any of the predefined system class names. For a list of the system class names, see the few sections.

CodePudding user response:

The HWND=CreateWindow (TEXT (" LCK2018 "),,,, to create a registered window class name and window class name of the class, you create a window should be returned to failure, hWnd should be 0
  • Related