LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; RECT rect; HPEN hPen, hOldPen; switch (message) { case WM_PAINT: hdc = BeginPaint(hwnd, &ps); GetClientRect(hwnd, &rect); //1.获取画笔 //hPen=GetStockObject(BLACK_PEN); //2.本身新建画笔 //要领一: //关闭图像时,使用线宽中间作为界限,所以会比想要的巨细多出来一部分(线宽巨细) //hPen = CreatePen(PS_SOLID, 100, RGB(255,0,0)); //对付虚线而言,若是线宽大于1则会显示实现,本来线条的样式掉效 //hPen = CreatePen(PS_DASH ,0.1, RGB(255, 0, 0)); //hPen = CreatePen(PS_DASHDOT, 0.1, RGB(255, 0, 0)); //hPen = CreatePen(PS_DASHDOTDOT, 0.1, RGB(255, 0, 0)); //用于关闭图像的使用:在后面可以进行填充 边框向内压缩 //hPen = CreatePen(PS_INSIDEFRAME, 10, RGB(255, 0, 0)); //要领二: LOGPEN pen[10]; for (int i = 0; i < 10;i++) { pen[i].lopnStyle = PS_SOLID; pen[i].lopnWidth.x = (i + 1) * 5; pen[i].lopnColor = RGB(20 * i, 0, 0); } //设置多个画笔样式 //使用createpenindorect直接取出样式使用,,代码简洁明了,也越发具有可重用性 for (int i = 0; i < 10;i++) { hPen = CreatePenIndirect(&pen[i]); hOldPen = SelectObject(hdc, hPen); Ellipse(hdc, 100+30*i, 100, 300+30*i, 200); DeleteObject(hPen); } // MoveToEx(hdc, rect.left, (rect.bottom-rect.top) / 2, NULL); // LineTo(hdc, rect.right, (rect.bottom - rect.top) / 2); //只能删除本身界说的东西,系统带有的不允许删除 //DeleteObject(hPen); SelectObject(hdc, hOldPen); EndPaint(hwnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam); }