我想画线段啊
#include <windows.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
int nMode;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[]="映射模式";
char lpszTitle[]="P103";
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName=lpszClassName;
wndclass.lpszMenuName=NULL;
wndclass.style=0;
if(!RegisterClass(&wndclass))
{
MessageBeep(0);
return FALSE;
}
hwnd =CreateWindow
(
lpszClassName,
lpszTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
HBRUSH hB1,hB2,hB3,hB4,hB5;
HPEN hP;
switch(message)
{
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
SetMapMode(hdc,nMode);
hP = CreatePen(PS_DASHDOT,6,RGB(50,125,40));
SelectObject(hdc,hP);
MoveToEx(hdc,0,10,NULL);
LineTo(hdc,700,600);
hB1=(HBRUSH)GetStockObject(WHITE_BRUSH);
SelectObject(hdc,hB1);
Rectangle(hdc,0,0,360,900);
hB2=(HBRUSH)GetStockObject(BLACK_BRUSH);
SelectObject(hdc,hB2);
Rectangle(hdc,360,0,720,900);
hB3=(HBRUSH)GetStockObject(GRAY_BRUSH);
SelectObject(hdc,hB3);
Rectangle(hdc,720,0,1080,900);
hB4=(HBRUSH)GetStockObject(BLACK_BRUSH);
SelectObject(hdc,hB4);
Rectangle(hdc,1080,0,1440,900);
hB5=(HBRUSH)GetStockObject(BLACK_BRUSH);
SelectObject(hdc,hB5);
Pie(hdc,0,0,300,200,50,50,300,50);
EndPaint(hwnd,&ps);
return 0;
break;
case WM_DESTROY:
DeleteObject(hB1);
DeleteObject(hB2);
DeleteObject(hB3);
DeleteObject(hB4);
DeleteObject(hB5);
DeleteObject(hP);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}