Home > Software engineering >  Under win32 a window class to create two Windows, such as winmain after and let the two Windows are
Under win32 a window class to create two Windows, such as winmain after and let the two Windows are

Time:10-09

 
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
HELLOWIN. C -- -- Displays "Hello, Windows 98!" In the client area
(c) Charles Petzold, 1998
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */

# include & lt; Windows. H>

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

Int WINAPI WinMain (HINSTANCE HINSTANCE, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
The static TCHAR szClassName []=TEXT (" MyWindow ");
The static TCHAR szWindowsName1 []=TEXT (" Window1 ");
The static TCHAR szWindowsName2 []=TEXT (" Window2 ");
HWND hwnd1 hwnd2;
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=szClassName;

if (! RegisterClass (& amp; Wndclass))
{
MessageBox (NULL, TEXT (" This program requires Windows NT!" ),
SzClassName, MB_ICONERROR);
return 0 ;
}

Hwnd1=CreateWindow (szClassName,//the window class name
The TEXT (" window1 "),//window caption
WS_OVERLAPPEDWINDOW,//the window style
CW_USEDEFAULT,//initial position x
CW_USEDEFAULT,//initial position y
CW_USEDEFAULT,//initial size x
CW_USEDEFAULT,//initial y size
NULL,//the parent window handle
Window menu handle NULL,//
HInstance,//program instance handle
NULL);//creation parameters
Hwnd2=CreateWindow (szClassName,//the window class name
The TEXT (" windows2 "),//window caption
WS_OVERLAPPEDWINDOW,//the window style
CW_USEDEFAULT,//initial position x
CW_USEDEFAULT,//initial position y
CW_USEDEFAULT,//initial size x
CW_USEDEFAULT,//initial y size
NULL,//the parent window handle
Window menu handle NULL,//
HInstance,//program instance handle
NULL);//creation parameters
ShowWindow (hwnd1 iCmdShow);
ShowWindow (hwnd2 iCmdShow);
UpdateWindow (hwnd1);
UpdateWindow (hwnd2);


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

//it is using in winmain to test whether two Windows closed
//the while (1)
//{
//if (GetMessage (& amp; MSG, NULL, 0, 0))
//{
//if (hwnd1==0 & amp; & Hwnd2==0)
//{
//if (MSG) message==WM_QUIT)
//{
//break;
//}
//}
//TranslateMessage (& amp; MSG);
//DispatchMessage (& amp; MSG);
//}
//}
Return MSG. WParam;
}

LRESULT a CALLBACK WndProc (HWND HWND, UINT message, WPARAM WPARAM, LPARAM LPARAM)
{
HDC HDC.
PAINTSTRUCT ps;
The RECT the RECT.

The switch (the message)
{
Case WM_CREATE message handler:
//PlaySound (TEXT (" hellowin. Wav "), NULL, SND_FILENAME | SND_ASYNC);
return 0 ;

In case the WM_PAINT:
HDC=BeginPaint (HWND, & amp; Ps);

GetClientRect (HWND, & amp; The rect);

DrawText (HDC, TEXT (" Hello, Windows 98!" ), 1, & amp; The rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);

EndPaint (HWND, & amp; Ps);
return 0 ;

Case WM_DESTROY:
//if (HWND==hwnd1)
//{
//hwnd1=0;
//}
//else
//{
//hwnd2=0;
//}
//it can also check whether two Windows in the callback function close
//if (hwnd1==0 & amp; & Hwnd2==0)
//{
//PostQuitMessage (0);
//}

The PostQuitMessage (0);
return 0 ;
Return DefWindowProc (HWND, message, wParam, lParam);
}
}

CodePudding user response:

 
# define WIN32_LEAN_AND_MEAN//just say no to the MFC

# include & lt; Windows. H>//include all the Windows headers
# include & lt; Windowsx. H>//include useful macros
# include & lt; Stdio. H>
# include & lt; Math. H>

//DEFINES////////////////////////////////////////////////

//defines the for Windows
# define WINDOW_CLASS_NAME "WINCLASS1
"
//GLOBALS////////////////////////////////////////////////
//

HWND m_hwnd1=0;
HWND m_hwnd2=0;

//FUNCTIONS provides//////////////////////////////////////////////
HBRUSH g_hYellow;
HBRUSH g_hPink;

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related