控制台也是窗口,同样也有自己的DC,也可以画线的,用spy++看看控制台窗口的类名字,用GetWindow得到窗口句柄,获取它的DC,就可以画线。只是好像控制台窗口的重画是个问题。
解决方案 »
- 自己做了个小键盘,里面有数字键和左右移动光标键等,我想问的是怎么通过左右移动键移动编辑框的光标?
- 请教高手~~~给讲解一下这段程序每句代码的含义~~~多谢啦
- MFC中!从RichEdit空间得到字符串,然后如何将字符串转换成字符数组?
- 控件是不是一定要有窗口?
- 如何获取程序错误自行处理,并屏蔽系统错误报告?
- VC+ODBC+Oracle9i问题
- 用ct_library连接Sybase数据库,怎么把C:\Sybase\include下的库加进去啊!
- 高分急求microsoft odbc 3.0 sdk
- 在Win32应用程序中显示调用dll成功,同样的代码和dll在DLL中调用失败
- 我要做一个自动分发程序,请帮我考虑一下实现模型。.
- 一个读内存的超简单问题
- 有关VC+MAPX开发应用程序打包问题
HWND GetConsoleWindow(void);Parameters
This function has no parameters.
Return Values
The return value is a handle to the window used by the console associated with the calling process or NULL if there is no such associated console.Res
To compile an application that uses this function, define the _WIN32_WINNT macro as 0x0500 or later. For more information, see Using the Windows Headers.Requirements
Client: Requires Windows XP or Windows 2000 Professional.
Server: Requires Windows Server 2003 or Windows 2000 Server.
Header: Declared in Wincon.h; include Windows.h.
Library: Use Kernel32.lib.
#include <string.h>
#include <stdio.h>
#include <stdlib.h>int main(int argc, char* argv[])
{
char arg[50]={0};
arg[0]='\"';
strcpy(arg+1,argv[0]);
int len=int(strlen(arg));
arg[len]='\"';
HWND hWnd=FindWindow(NULL,arg); //找到程序运行窗口的句柄
HDC hDC=GetWindowDC(hWnd);//通过窗口句柄得到该窗口的设备场境句柄
HPEN hPen,hOldPen; //画笔
int i=0;for(;i<500;++i)hPen=CreatePen(PS_SOLID,2,0x00ff00);//生成绿色画笔
hOldPen=(HPEN)SelectObject(hDC,hPen);//把画笔引入设备场境
MoveToEx(hDC,20,50,NULL); //设置画线起点
LineTo(hDC,520,550); //画到终点Arc(hDC,200,200,300,300,350,500,350,500);//画圆SelectObject(hDC,hOldPen);
ReleaseDC(hWnd,hDC);return 0;
}