Home > Software engineering >  Win32 application to register a second window class failed
Win32 application to register a second window class failed

Time:10-31

A brief introduction, create a WIn32 application in vs, I want to register a window class inside, and displayed, but found the second window class registered always fail, please answer





//Win32Project3. CPP: defines the entry point of application, 
//

# include "stdafx. H"
# include "Win32Project3. H"

# define MAX_LOADSTRING 100

//global variables:
HINSTANCE hInst,//the current instance
TCHAR szTitle [MAX_LOADSTRING];//title bar text
TCHAR szWindowClass [MAX_LOADSTRING];//the main window class name
//this code module contains functions to declare:
HWND HWND, hWnd1 hWnd2;
//TCHAR La=TCHAR (" LOVE ");
TCHAR szname []=TEXT (" classname ");
The ATOM MyRegisterClass (HINSTANCE HINSTANCE);
BOOL InitInstance (HINSTANCE, int);
LRESULT a CALLBACK WndProc1 (HWND, UINT, WPARAM, LPARAM);
LRESULT a CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About (HWND, UINT, WPARAM, LPARAM);

Int APIENTRY _tWinMain (_In_ HINSTANCE HINSTANCE,

_In_opt_ HINSTANCE hPrevInstance,_In_ LPTSTR lpCmdLine,
_In_ int nCmdShow)
{
UNREFERENCED_PARAMETER (hPrevInstance);
UNREFERENCED_PARAMETER (lpCmdLine);

//TODO: placed in the code,
MSG MSG.
HACCEL hAccelTable;

//initialize global string
LoadString (hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString (hInstance, IDC_WIN32PROJECT3, szWindowClass, MAX_LOADSTRING);
MyRegisterClass (hInstance);

//perform application initialization:
if (! InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

HAccelTable=LoadAccelerators (hInstance, MAKEINTRESOURCE (IDC_WIN32PROJECT3));

//the main message loop:
While (GetMessage (& amp; MSG, NULL, 0, 0))
{
if (! TranslateAccelerator (MSG. The HWND hAccelTable, & amp; MSG))
{
TranslateMessage (& amp; MSG);
DispatchMessage (& amp; MSG);
}
}

Return (int) MSG. WParam;
}



//
//function: MyRegisterClass ()
//
//purpose: registered window class,
//
The ATOM MyRegisterClass (HINSTANCE HINSTANCE)
{
Modifed WNDCLASSEX wcex;


Wcex. CbSize=sizeof (modifed WNDCLASSEX);

Wcex. Style=CS_HREDRAW | CS_VREDRAW;
Wcex. LpfnWndProc=WndProc;
Wcex. CbClsExtra=0;
Wcex. CbWndExtra=0;
Wcex. HInstance=hInstance;
Wcex. HIcon=LoadIcon (hInstance, MAKEINTRESOURCE (IDI_WIN32PROJECT3));
Wcex. HCursor=LoadCursor (NULL, IDC_ARROW);
Wcex. HbrBackground=(HBRUSH) (COLOR_WINDOW + 1);
Wcex. LpszMenuName=MAKEINTRESOURCE (IDC_WIN32PROJECT3);
Wcex. LpszClassName=szWindowClass;
Wcex. HIconSm=LoadIcon (wcex hInstance, MAKEINTRESOURCE (IDI_SMALL));
////////////////////////
Wcex. CbSize=sizeof (modifed WNDCLASSEX);
Modifed WNDCLASSEX wcex2a;
Wcex2a. Style=CS_HREDRAW | CS_VREDRAW;
Wcex2a. LpfnWndProc=WndProc1;
Wcex2a. CbClsExtra=0;
Wcex2a. CbWndExtra=0;
Wcex2a. HInstance=hInstance;
Wcex2a. HIcon=LoadIcon (hInstance, MAKEINTRESOURCE (IDI_WIN32PROJECT3));
Wcex2a. HCursor=LoadCursor (NULL, IDC_ARROW);
Wcex2a. HbrBackground=(HBRUSH) (COLOR_WINDOW + 24);
Wcex2a. LpszMenuName=MAKEINTRESOURCE (IDC_WIN32PROJECT3);
Wcex2a. LpszClassName=szname;
Wcex2a. HIconSm=LoadIcon (wcex hInstance, MAKEINTRESOURCE (IDI_SMALL));
if(! RegisterClassEx (& amp; Wcex2a))
{
MessageBox (hWnd, L "why?" , "L", MB_OK);
}
Return (RegisterClassEx (& amp; Wcex));//& amp; & RegisterClassEx (& amp; Wcex2a));
}

//
//function: InitInstance (HINSTANCE, int)
//
//purpose: save the instance handle and create the main window
//
//comment:
//
//in this function, we save the instance handle in a global variable and
//create and display the main program window,
//
BOOL InitInstance (HINSTANCE HINSTANCE, int nCmdShow)
{
HWND HWND, hWnd1 hWnd2;

HInst=hInstance;//handle to the instance is stored in the global variable

HWnd=CreateWindow (szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT CW_USEDEFAULT, 0, 0, NULL, NULL, hInstance, NULL);
HWnd1=CreateWindow (szname, L "different class", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT CW_USEDEFAULT, 0, 0, NULL, NULL, hInstance, NULL);
HWnd2=CreateWindow (szWindowClass, L "of" the same class, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT CW_USEDEFAULT, 0, 0, NULL, NULL, hInstance, NULL);
if (! The hWnd | |! HWnd2)//| |! HWnd1)
{
return FALSE;
}

ShowWindow (hWnd, nCmdShow);
UpdateWindow (hWnd);
ShowWindow (hWnd1, nCmdShow);
UpdateWindow (hWnd1);
ShowWindow (hWnd2, nCmdShow);
UpdateWindow (hWnd2);

return TRUE;
}

//
//function: WndProc (HWND, UINT, WPARAM, LPARAM)
//
//purpose: to deal with the news of the main window,
//
//WM_COMMAND - processing application menu
//WM_PAINT - draw the main window
//WM_DESTROY - send out messages and return
//
//
LRESULT a CALLBACK WndProc (HWND HWND, UINT message, WPARAM WPARAM, LPARAM LPARAM)
{
Int wmId wmEvent;
PAINTSTRUCT ps;
HDC HDC.

The switch (the message)
{
Case WM_COMMAND:
WmId=LOWORD (wParam);
WmEvent=HIWORD (wParam);
//analysis menu choice:
The switch (wmId)
{
Case IDM_ABOUT:
DialogBox (hInst, MAKEINTRESOURCE (IDD_ABOUTBOX), hWnd, About);
break;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related