Home > Software engineering >  Vc novice selectobject (HDC, hbrush); Use may be an uninitialized pointer variable local "HDC?&
Vc novice selectobject (HDC, hbrush); Use may be an uninitialized pointer variable local "HDC?&

Time:10-02

Error of the procedures section:
LRESULT a CALLBACK WndProc (HWND HWND, UINT message, WPARAM WPARAM, LPARAM LPARAM)
{

HDC HDC.
PAINTSTRUCT ps;
HBRUSH HBRUSH;///////////////////////
HPEN HPEN;
Static int dispmode=1;
LPCTSTR STR.
The switch (the message)
{... }
Hbrush=(hbrush) GetStockObject (DKGRAY_BRUSH);
Hpen=(hpen) GetStockObject (BLACK_PEN);

SelectObject (HDC, hbrush);///////////////error: using an uninitialized pointer variable local may have "HDC?"
SelectObject (HDC, hpen);
The RoundRect (HDC, 50, 120, 100, 200, 15, 15);
EndPaint (hWnd, & amp; Ps);
return 0;
}

The complete code:
//Win32Project1. CPP: defines the entry point of application,
//

Include "stdafx. H"
Include "Win32Project1. H"
Define MAX_LOADSTRING 100
//global variables:
HINSTANCE hInst,//the current instance
WCHAR szTitle [MAX_LOADSTRING];//title bar text
WCHAR szWindowClass [MAX_LOADSTRING];//the main window class name

//this code module contains functions to declare:
The ATOM MyRegisterClass (HINSTANCE HINSTANCE);
BOOL InitInstance (HINSTANCE, int);
LRESULT a CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About (HWND, UINT, WPARAM, LPARAM);

Int APIENTRY wWinMain (_In_ HINSTANCE HINSTANCE,


_In_opt_ HINSTANCE hPrevInstance,_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{

UNREFERENCED_PARAMETER (hPrevInstance);
UNREFERENCED_PARAMETER (lpCmdLine);

//TODO: placed in the code,

//initialize global string
LoadStringW (hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadStringW (hInstance, IDC_WIN32PROJECT1, szWindowClass, MAX_LOADSTRING);
MyRegisterClass (hInstance);

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

HACCEL hAccelTable=LoadAccelerators (hInstance, MAKEINTRESOURCE (IDC_WIN32PROJECT1));

MSG MSG.

//the main message loop:
While (GetMessage (& amp; MSG, nullptr, 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)
{

WNDCLASSEXW 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_WIN32PROJECT1));
Wcex. HCursor=LoadCursor (nullptr, IDC_ARROW);
Wcex. HbrBackground=(HBRUSH) (COLOR_WINDOW + 1);
Wcex. LpszMenuName=MAKEINTRESOURCEW (IDC_WIN32PROJECT1);
Wcex. LpszClassName=szWindowClass;
Wcex. HIconSm=LoadIcon (wcex hInstance, MAKEINTRESOURCE (IDI_SMALL));

Return RegisterClassExW (& amp; Wcex);
}

//
//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)
{
HInst=hInstance;//handle to the instance is stored in the global variable

HWND HWND=CreateWindowW (szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,

CW_USEDEFAULT CW_USEDEFAULT, 0, 0, nullptr nullptr, hInstance, nullptr);
if (! HWnd) {

Return FALSE;
}

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

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)
{

HDC HDC.
PAINTSTRUCT ps;
HBRUSH HBRUSH;///////////////////////
HPEN HPEN;
Static int dispmode=1;
LPCTSTR STR.
The switch (the message)
{
Case WM_COMMAND:
{
Int wmId=LOWORD (wParam);
//analysis menu choice:
The switch (wmId)
{
Case IDM_ABOUT:
DialogBox (hInst, MAKEINTRESOURCE (IDD_ABOUTBOX), hWnd, About);
break;
Case IDM_EXIT:
The DestroyWindow (hWnd);
break;
Default:
Return DefWindowProc (hWnd, message, wParam, lParam);
}
}
break;
Case WM_LBUTTONDOWN:
The InvalidateRect (hWnd, nullptr, TRUE);
break;
In case the WM_PAINT:
HDC=BeginPaint (hWnd, & amp; Ps);
Dispmode=0;
The switch (dispmode)
{
Case 0: STR=_T (" hi ");
SetMapMode (HDC, MM_TEXT);
TextOut (HDC, 0, 0, STR, _tcsclen (STR)); break;
Case 1: STR=_T (" hi 2 ");
SetMapMode (HDC, MM_ISOTROPIC);
SetWindowExtEx (HDC, 20, 20, nullptr);
TextOut (HDC, 0, 0, STR, _tcsclen (STR)); break;
}
break;
Case WM_DESTROY:
The PostQuitMessage (0);
break;
Default:
Return DefWindowProc (hWnd, message, wParam, lParam);
}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related