Home > Software engineering >  Written in C two Windows, make its ability to have refused to close, but click closed two Windows ar
Written in C two Windows, make its ability to have refused to close, but click closed two Windows ar

Time:11-22

Here is the code I wrote, also please bosses give solution.
# include
# include "iostream"

LRESULT a CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT a CALLBACK ExeProc (HWND, UINT, WPARAM, LPARAM);
using namespace std;
//WINAPI used to indicate in Windows, is how to pass parameters, WinMain is equal to the standard language of the main () function entry
Int WINAPI WinMain (HINSTANCE HINSTANCE, HINSTANCE hPrevInstance, PSTR szCmdLine, int nCmdShow)
{

HWND HWND HWND;//with a variable for window handle
MSG MSG.//message is stored in the one variable
WNDCLASS wc, WCG;//window class
//1. Design a window class
Wc. Style=0;//the window style
Wc. LpfnWndProc=(WNDPROC WNDPROC);//a pointer to the window procedure function
Wc. CbClsExtra=0;//window class additional data
Wc. CbWndExtra=0;//window additional data
The wc. The hInstance=hInstance;//instance handle
Wc. HIcon=LoadIcon (NULL, IDI_WINLOGO);//icon handle
Wc. HCursor=LoadCursor (NULL, IDC_ARROW);//mouse handle
Wc. HbrBackground=(HBRUSH) (COLOR_WINDOW + 1);//background handle
Wc. LpszMenuName=NULL;//window menu
Wc. LpszClassName=TEXT (" MyWndClass ");//window class name

WCG. Style=0;//the window style
WCG. LpfnWndProc=(WNDPROC) ExeProc;//a pointer to the window procedure function
WCG. CbClsExtra=0;//window class additional data
WCG. CbWndExtra=0;//window additional data
WCG. HInstance=hInstance;//instance handle
WCG. HIcon=LoadIcon (NULL, IDI_WINLOGO);//icon handle
WCG. HCursor=LoadCursor (NULL, IDC_ARROW);//mouse handle
WCG. HbrBackground=(HBRUSH) (COLOR_WINDOW + 1);//background handle
WCG. LpszMenuName=NULL;//window menu
WCG. LpszClassName=TEXT (" MyWindow ");//window class name
//2. The registration window class
RegisterClass (& amp; Wc);
RegisterClass (& amp; WCG);
//3. Create a window
HWND=CreateWindow (
The TEXT (" MyWndClass "),//the window class name
The TEXT (" Hello SDK Application "),//the window title
WS_OVERLAPPEDWINDOW,//the window style
//window position (x, y) and size (the following are the default)
CW_USEDEFAULT,//the window position coordinates x
CW_USEDEFAULT,//the window position y
CW_USEDEFAULT,//the size of the window - width
CW_USEDEFAULT,//the size of the window - highly
NULL,//handle to the parent window window
NULL,//the window menu handle
HInstance,//instance handle
NULL//additional data
);
HWnd=CreateWindow (
The TEXT (" MyWindow "),//the window class name
The TEXT (" Hello World "),//the window title
WS_OVERLAPPEDWINDOW,//the window style
//window position (x, y) and size (the following are the default)
CW_USEDEFAULT,//the window position coordinates x
CW_USEDEFAULT,//the window position y
CW_USEDEFAULT,//the size of the window - width
CW_USEDEFAULT,//the size of the window - highly
NULL,//handle to the parent window window
NULL,//the window menu handle
HInstance,//instance handle
NULL//additional data
);
//4. The display and update window
ShowWindow (HWND, nCmdShow);
UpdateWindow (HWND);
ShowWindow (hWnd, nCmdShow);
UpdateWindow (hWnd);
//5. Message loop
While (GetMessage (& amp; MSG, NULL, 0, 0)) {
TranslateMessage (& amp; MSG);//translation keyboard message
DispatchMessage (& amp; MSG);//forwarded to the window procedure
}
Return MSG. WParam;
}

//write window procedure function
LRESULT a CALLBACK WndProc (HWND HWND, UINT message, WPARAM WPARAM, LPARAM LPARAM)
{
PAINTSTRUCT ps;//painting structure
HDC HDC.//handle to the DC
//to deal with all kinds of news
The switch (the message)
{
Case the WM_PAINT://draw news
HDC=BeginPaint (HWND, & amp; Ps);
TextOut (HDC, 100, 100, "the first Windows programs," L lstrlen (L "is the first Windows programs"));
EndPaint (HWND, & amp; Ps);
return 0;
Destroying the case WM_DESTROY://window messages (closed)
The PostQuitMessage (0);
break;
Case WM_CLOSE://popups closed Windows
If (IDCANCEL==MessageBox (HWND, L "whether to close the window?" , L "message", MB_OKCANCEL | MB_ICONQUESTION))
break;
The else
Return DefWindowProc (HWND, message, wParam, lParam);
Default:
Return DefWindowProc (HWND, message, wParam, lParam);
}
return 0;
}

LRESULT a CALLBACK ExeProc (HWND HWND, UINT message, WPARAM WPARAM, LPARAM LPARAM)
{
PAINTSTRUCT ps;//painting structure
HDC HDC.//handle to the DC
//to deal with all kinds of news
The switch (the message)
{
Case the WM_PAINT://draw news
HDC=BeginPaint (hWnd, & amp; Ps);
TextOut (HDC, 100, 100, L "Hello, World", lstrlen (L "Hello, World"));
EndPaint (hWnd, & amp; Ps);
return 0;
Destroying the case WM_DESTROY://window messages (closed)
The PostQuitMessage (0);
break;
Case WM_CLOSE://popups closed Windows
If (IDCANCEL==MessageBox (hWnd, L "do you really want to close the window?" , L "message", MB_OKCANCEL | MB_ICONQUESTION))
break;
The else
Return DefWindowProc (hWnd, message, wParam, lParam);
Default:
Return DefWindowProc (hWnd, message, wParam, lParam);
}
return 0;
}

CodePudding user response:

 
# include
# include "iostream"

LRESULT a CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT a CALLBACK ExeProc (HWND, UINT, WPARAM, LPARAM);
using namespace std;
//WINAPI used to indicate in Windows, is how to pass parameters, WinMain is equal to the standard language of the main () function entry
HWND g_hwnd g_hwnd;//with a variable for window handle
Int g_WinNum=0;

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

MSG MSG.//message is stored in the one variable
WNDCLASS wc, WCG;//window class
//1. Design a window class
Wc. Style=0;//the window style
Wc. LpfnWndProc=(WNDPROC WNDPROC);//a pointer to the window procedure function
Wc. CbClsExtra=0;//window class additional data
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related