在控制台中调用win32 API

#include <stdio.h>

#include <stdlib.h>

#include <windows.h>

HWND WINAPI GetConsoleWindow();

int main(int argc, char *argv[])

{

	HWND hwnd;

	HDC hdc;

	HPEN hpen;

	hwnd = GetConsoleWindow();

	hdc = GetDC(hwnd);

	system("color F0");

	system("cls");

	hpen = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));

	SelectObject(hdc, hpen);

	MoveToEx(hdc, 20, 20, NULL);

	LineTo(hdc, 200, 300);

	DeleteObject(hpen);

	ReleaseDC(hwnd, hdc);

	getchar();

	return 0;

}

  

在控制台调用win32只要include相应的头文件即可

运行效果:

posted @ 2019-02-16 10:42  巫居树  阅读(722)  评论(0编辑  收藏  举报