Home > Software engineering >  How don't C handwritten WIN32 window display
How don't C handwritten WIN32 window display

Time:10-01

Compile, but reaction after the operation, has been running in the process, but the form is not show

//WIN32 Application. CPP: Defines the entry point for the Application. The
//

# include "stdafx. H"
# include "resource. H"
#include
LRESULT a CALLBACK WndProc (HWND HWND, UINT message, WPARAM WPARAM, LPARAM lPram);
Int WINAPI WinMain (HINSTANCE HINSTANCE, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
//MyRegisterClass (& amp; Wcex);
The static TCHAR szAppName []=TEXT (" HelloWin32 ");
HWND HWND=NULL;
MSG MSG.
WNDCLASS WNDCLASS;
Wndclass. Style=CS_HREDRAW | CS_VREDRAW;
Wndclass. LpfnWndProc=WndProc;//callback function
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;//window class name

if (! RegisterClass (& amp; Wndclass))
{
MessageBox (NULL, "program has run under Windows NT, szAppName, MB_ICONERROR);
return 0;
}
CreateWindow (szAppName,//window class name
"Hello, ABC",//window title
WS_OVERLAPPEDWINDOW,//form style
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
HInstance,
NULL,
);
ShowWindow (HWND, SW_SHOW);
UpdateWindow (HWND);

While (GetMessage (& amp; MSG, NULL, 0, 0))
{
TranslateMessage (& amp; MSG);//message translation, dealing with the keyboard
DispatchMessage (& amp; MSG);//distribution of news, which forms used to handle
}
Return MSG. WParam;//distributed message return


return 0;

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

Case WM_CREATE message handler:
return 0;
In case the WM_PAINT:
HDC=BeginPaint (HWND, & amp; Ps);
GetClientRect (HWND, & amp; The rect);
DrawText (HDC, TEXT (" Hello "), 1, & amp; The rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
EndPaint (HWND, & amp; Ps);
return 0;
Case WM_DESTROY:
The PostQuitMessage (0);
return 0;
}
Return DefWindowProc (HWND, message, wParam, lPram);

}




CodePudding user response:

New project, type the Win32 Application

CodePudding user response:

Fyi:
 # pragma comment (lib, "user32") 
# pragma comment (lib, "gdi32")
#include
LRESULT a CALLBACK WndProc (HWND HWND, UINT message, WPARAM WPARAM, LPARAM LPARAM) {
PAINTSTRUCT ps;
HDC HDC.
HFONT HFONT ohfont;
The RECT r;
COLORREF oc;

The switch (the message) {
Case WM_CLOSE://Alt + F4 exit
The PostQuitMessage (0);
break;
In case the WM_PAINT:
BeginPaint (hWnd, & amp; Ps);
HDC=ps. HDC;//the device context to the draw in
GetClientRect (hWnd, & amp; R);//Obtain the window 's client rectangle
Hfont=CreateFont (200, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "tahoma");
Ohfont=(HFONT) SelectObject (HDC, HFONT);
Oc=SetTextColor (HDC, 0 x00c080ff);
SetBkMode (HDC, TRANSPARENT);
TextOut (HDC, r.l eft + r.r d.light/2-600, r.t op + r. b ottom/2-100, "the shortest drawing program", 12);
SelectObject (HDC, ohfont);
SetTextColor (HDC, oc);
DeleteObject (hfont);
EndPaint (hWnd, & amp; Ps);
break;
Default:
Return DefWindowProc (hWnd, message, wParam, lParam);
}
return 0;
}
Int WINAPI WinMain (HINSTANCE HINSTANCE, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
MSG MSG={0};
WNDCLASS wc={0};
HBRUSH HBRH;
HBRH=CreateSolidBrush (0 x00000000);
Wc. LpfnWndProc=WndProc;
The wc. The hInstance=hInstance;
Wc. HbrBackground=HBRH;
Wc. LpszClassName="minwindowsapp";
Wc. HCursor=LoadCursor (NULL, IDC_ARROW);
If (0==RegisterClass (& amp; Wc)) return 1;

If (NULL==CreateWindow (wc) lpszClassName,
"Minimal Windows Application,"
WS_POPUP | WS_VISIBLE,
0,
0,
GetSystemMetrics (SM_CXSCREEN),
GetSystemMetrics (SM_CYSCREEN),
0,
0,
HInstance,
NULL))
Return 2;

While (GetMessage (& amp; MSG, NULL, 0, 0) & gt; 0 {
DispatchMessage (& amp; MSG);
}
DeleteObject (HBRH);
return 0;
}

CodePudding user response:

reference 1/f, zhao teacher reply:
new project, type the Win32 Application
create a Win32

CodePudding user response:

reference 1/f, zhao teacher reply:
new project, type the Win32 Application
is a Win32 Application

CodePudding user response:

HWND assignment

CodePudding user response:

reference 5 floor ipqtjmqj reply:
HWND no assignment

CreateWindow (szAppName,//window class name
Instead of
HWND= CreateWindow (szAppName,//window class namenullnullnullnullnullnullnullnullnull
  • Related