GDI求助(为什么显示不了图形)
#include<windows.h>HDChDC;PAINTSTRUCTPs;HBRUSHNewBrush;HWNDhWnd;voidDrawContent(){hDC...
#include <windows.h>
HDC hDC;
PAINTSTRUCT Ps;
HBRUSH NewBrush;
HWND hWnd;
void DrawContent()
{ hDC = BeginPaint(hWnd, &Ps);
POINT Pt[3];
NewBrush = CreateSolidBrush(RGB(0, 125, 5));
Pt[0].x = 125; Pt[0].y = 10;
Pt[1].x = 95; Pt[1].y = 70;
Pt[2].x = 155; Pt[2].y = 70;
SelectObject(hDC, NewBrush);
Polygon(hDC, Pt, 3);
DeleteObject(NewBrush);
EndPaint(hWnd, &Ps);}
LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg,WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX WndCls;
MSG Msg;
WndCls.cbSize = sizeof(WndCls);
WndCls.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
WndCls.lpfnWndProc = WindProcedure;
WndCls.cbClsExtra = 0;
WndCls.cbWndExtra = 0;
WndCls.hInstance = hInstance;
WndCls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndCls.hCursor = LoadCursor(NULL, IDC_ARROW);
WndCls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndCls.lpszMenuName = NULL;
WndCls.lpszClassName = TEXT("MAIN");
WndCls.hIconSm = LoadIcon(hInstance, IDI_APPLICATION);
RegisterClassEx(&WndCls);
CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,TEXT("MAIN"),TEXT( "GDI Brushes Fundamentals"),WS_OVERLAPPEDWINDOW | WS_VISIBLE,CW_USEDEFAULT, CW_USEDEFAULT, 500, 500, NULL, NULL, hInstance, NULL);
while( GetMessage(&Msg, NULL, 0, 0) )
{TranslateMessage(&Msg);
DispatchMessage( &Msg);}
return static_cast<int>(Msg.wParam);}
LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg,WPARAM wParam, LPARAM lParam)
{switch(Msg)
{
case WM_PAINT:
DrawContent();
break;
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}return 0;}
为什么显示的总是白的没有内容的呢??? 展开
HDC hDC;
PAINTSTRUCT Ps;
HBRUSH NewBrush;
HWND hWnd;
void DrawContent()
{ hDC = BeginPaint(hWnd, &Ps);
POINT Pt[3];
NewBrush = CreateSolidBrush(RGB(0, 125, 5));
Pt[0].x = 125; Pt[0].y = 10;
Pt[1].x = 95; Pt[1].y = 70;
Pt[2].x = 155; Pt[2].y = 70;
SelectObject(hDC, NewBrush);
Polygon(hDC, Pt, 3);
DeleteObject(NewBrush);
EndPaint(hWnd, &Ps);}
LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg,WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX WndCls;
MSG Msg;
WndCls.cbSize = sizeof(WndCls);
WndCls.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
WndCls.lpfnWndProc = WindProcedure;
WndCls.cbClsExtra = 0;
WndCls.cbWndExtra = 0;
WndCls.hInstance = hInstance;
WndCls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndCls.hCursor = LoadCursor(NULL, IDC_ARROW);
WndCls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndCls.lpszMenuName = NULL;
WndCls.lpszClassName = TEXT("MAIN");
WndCls.hIconSm = LoadIcon(hInstance, IDI_APPLICATION);
RegisterClassEx(&WndCls);
CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,TEXT("MAIN"),TEXT( "GDI Brushes Fundamentals"),WS_OVERLAPPEDWINDOW | WS_VISIBLE,CW_USEDEFAULT, CW_USEDEFAULT, 500, 500, NULL, NULL, hInstance, NULL);
while( GetMessage(&Msg, NULL, 0, 0) )
{TranslateMessage(&Msg);
DispatchMessage( &Msg);}
return static_cast<int>(Msg.wParam);}
LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg,WPARAM wParam, LPARAM lParam)
{switch(Msg)
{
case WM_PAINT:
DrawContent();
break;
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}return 0;}
为什么显示的总是白的没有内容的呢??? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询