user-0 提问: 求帮助，C语言单纯用windowsAPI中的LineTo画条直线需要怎么声明啊？

回复:
user: user-0
content: 谢谢大家帮忙，真的很好用了

user: user-1
content: 楼上够简洁了。

user: user-2
content: int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { 	HDC hDC=GetDC(NULL); 	int x=GetSystemMetrics(SM_CXSCREEN); 	int y=GetSystemMetrics(SM_CYSCREEN); 	MoveToEx(hDC,0,0,NULL); 	LineTo(hDC,x,y); 	MoveToEx(hDC,0,y,NULL); 	LineTo(hDC,x,0); 	ReleaseDC(NULL,hDC); 	return 0; }

user: user-0
content: 辛苦各位了，有能在DEVc++上运行的吗，本人刚接触API细节不是很懂，单纯认为通过几行代码就能实现画一条线的功能，就像实现删除文件就这几行就行，有很简洁的吗？ #include <windows.h>  int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,                         LPSTR lpCmdLine, int nCmdShow) {         DeleteFile("E:\\test2.txt");         return 0; }

user: user-3
content: #include <windows.h>  LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;  int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, 					PSTR szCmdLine, int iCmdShow) { 	static TCHAR szAppName[] = TEXT ("LineDemo") ; 	HWND         hwnd ; 	MSG          msg ; 	WNDCLASS     wndclass ;  	wndclass.style         = CS_HREDRAW | CS_VREDRAW ; 	wndclass.lpfnWndProc   = WndProc ; 	wndclass.cbClsExtra    = 0 ; 	wndclass.cbWndExtra    = 0 ; 	wndclass.hInstance     = hInstance ; 	wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ; 	wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ; 	wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ; 	wndclass.lpszMenuName  = NULL ; 	wndclass.lpszClassName = szAppName ;  	if (!RegisterClass (&wndclass)) 	{ 		MessageBox (NULL, TEXT ("Program requires Windows NT!"),  			szAppName, MB_ICONERROR) ; 		return 0 ; 	}  	hwnd = CreateWindow (szAppName, TEXT ("Line Demonstration"), 		WS_OVERLAPPEDWINDOW, 		CW_USEDEFAULT, CW_USEDEFAULT, 		CW_USEDEFAULT, CW_USEDEFAULT, 		NULL, NULL, hInstance, NULL) ;  	ShowWindow (hwnd, iCmdShow) ; 	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) { 	static int  cxClient, cyClient ; 	HDC         hdc ; 	PAINTSTRUCT ps ;  	switch (message) 	{ 	case WM_SIZE: 		cxClient = LOWORD (lParam) ; 		cyClient = HIWORD (lParam) ; 		return 0 ;  	case WM_PAINT: 		hdc = BeginPaint (hwnd, &ps) ; 		/*        下面是画个矩形 		Rectangle (hdc,     cxClient / 8,     cyClient / 8, 		7 * cxClient / 8, 7 * cyClient / 8) ; 		*/        		MoveToEx  (hdc,        0,        0, NULL) ; 		LineTo    (hdc, cxClient, cyClient) ;  		MoveToEx  (hdc,        0, cyClient, NULL) ; 		LineTo    (hdc, cxClient,        0) ;  		//		  SelectObject(hdc, GetStockObject(NULL_BRUSH));	//透明刷子 		/*       下面是画个圆    		Ellipse   (hdc,     cxClient / 8,     cyClient / 8, 		7 * cxClient / 8, 7 * cyClient / 8) ;  		RoundRect (hdc,     cxClient / 4,     cyClient / 4, 		3 * cxClient / 4, 3 * cyClient / 4, 		cxClient / 4,     cyClient / 4) ; 		*/          		EndPaint (hwnd, &ps) ; 		return 0 ;  	case WM_DESTROY: 		PostQuitMessage (0) ; 		return 0 ; 	} 	return DefWindowProc (hwnd, message, wParam, lParam) ; }   这个是在vc6里面能跑的画图的demo,看看吧,希望对你有帮助.

user: user-1
content: #pragma comment(lib,"user32") #pragma comment(lib,"gdi32") #include <stdio.h> #include <stdlib.h> #include <time.h> #include <windows.h> HWND WINAPI GetConsoleWindow(); void HideTheCursor() {     CONSOLE_CURSOR_INFO cciCursor;     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);      if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {         cciCursor.bVisible = FALSE;         SetConsoleCursorInfo(hStdOut, &cciCursor);     } } void ShowTheCursor() {     CONSOLE_CURSOR_INFO cciCursor;     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);      if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {         cciCursor.bVisible = TRUE;         SetConsoleCursorInfo(hStdOut, &cciCursor);     } } int main() {     HWND  hwnd;     HDC   hdc;     HFONT hfont;     int i,x,y;       srand(time(NULL));     system("color F0");     system("cls");     HideTheCursor();     hwnd  = GetConsoleWindow();     hdc   = GetDC(hwnd);     hfont = CreateFont(48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "华文楷体");     SelectObject(hdc,hfont);     TextOut(hdc,10,10,"地球人都知道！",14);     MoveToEx(hdc,5,5,NULL);     LineTo(hdc,300,  5);     LineTo(hdc,300, 60);     LineTo(hdc,  5, 60);     LineTo(hdc,  5,  5);     for (i=0;i<100;i++) {         x=rand()%400;         y=rand()%300;         SetPixel(hdc,x,y,0);     }     DeleteObject(hfont);     ReleaseDC(hwnd,hdc);     getchar();     system("color 07");     system("cls");     ShowTheCursor();     return 0; }

user: user-4
content: http://msdn.microsoft.com/en-us/library/bb384843.aspx 说的很清楚  有不懂得再问