如何获得Wind [4]的hdc? [英] How do I get the hdc of Wind[4]?

查看:74
本文介绍了如何获得Wind [4]的hdc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WinAPI in C.请不要C ++ !!

我正在使用这个被盗的代码:(部分只显示,漂亮的小平原C)

//创建主窗口

Wind [0] = CreateWindowEx(WS_EX_CONTROLPARENT,

TINY_UNICODE,微小的Unicode编辑器,

WS_OVERLAPPEDWINDOW,

CW_USEDEFAULT,0,500,300,NULL,NULL,Inst,NULL);

//按钮

Wind [1] = CreateWindow(BUTTON,Open ,

WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,

2,2,50,25,Wind [0],(HMENU)1001,Inst,NULL);

Wind [2] = CreateWindow(BUTTON,Save,

WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,

2,30,50,25,Wind [0],(HMENU)1002,Inst,NULL);

Wind [3] = CreateWindow(BUTTON,Quit,

WS_CHILD | WS_VISIBLE | BS_FLAT ,

2,60,50,25,Wind [0],(HMENU)1003,Inst,NULL);

//编辑窗口

Wind [4] = CreateWindowEx(WS_EX_CLIENTEDGE,EDIT,NULL,

WS_CHILD | WS_VISIBLE |

ES_MULTILINE,

60,2,200,200,Wind [0],NULL,Inst,NULL);



现在我想用静态控件替换编辑控件Wind [4]以使用SetPixel(hdc,x,y,z,0,0)绘制图形;

为此我需要得到窗口的hdc Wind [4]。

请问我该怎么做?

谢谢

Johan Smit


不,我自己没有解决这个问题。我可能在错误的地方询问了后续问题。

我不确定如何提出跟进问题。

WinAPI in C. Please no C++!!
I am using this stolen code:(part shown only, nice small plain C)
// create the main window
Wind[0] = CreateWindowEx( WS_EX_CONTROLPARENT,
"TINY_UNICODE","Tiny Unicode Editor",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,0,500,300,NULL,NULL,Inst,NULL);
// buttons
Wind[1] = CreateWindow("BUTTON","Open",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
2,2,50,25,Wind[0],(HMENU) 1001,Inst,NULL);
Wind[2] = CreateWindow("BUTTON","Save",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
2,30,50,25,Wind[0],(HMENU) 1002,Inst,NULL);
Wind[3] = CreateWindow("BUTTON","Quit",
WS_CHILD | WS_VISIBLE | BS_FLAT,
2,60,50,25,Wind[0],(HMENU) 1003,Inst,NULL);
// edit window
Wind[4] = CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT",NULL,
WS_CHILD | WS_VISIBLE |
ES_MULTILINE,
60,2,200,200,Wind[0],NULL,Inst,NULL);

Now I want to replace the edit control Wind[4] with a static control to draw graphs using SetPixel(hdc, x, y, z, 0, 0));
For that I need to get the hdc of the window Wind[4].
Please how do I do that?
Thank you
Johan Smit

No I have not solved this myself. I probably asked the follow-up question on the wrong place.
I am unsure how to place follow up questions.

推荐答案

参见< a href =https://msdn.microsoft.com/en-us/library/windows/desktop/dd144871%28v=vs.85%29.aspx> GetDC() [ ^ ]。 请务必致电 ReleaseDC() [ ^ ]完成后使用它。



/ ravi
See GetDC()[^].  Be sure to call ReleaseDC()[^] when done using it.

/ravi


在绘制窗口之前我建议你阅读GDI以了解windows图形界面,否则你会迷路...

加速此处您可以找到文档。仔细研究它,你就会得到你想要的解决方案。

无论如何,这是一个在窗口上绘制正弦线的简单代码:

Before drawing in a window I suggest you to read about GDI to have a good understanding of windows graphical interface, or you'll get lost...
To speed here you'll find documentation. Study it carefully and you'll get the solution you are looking for.
Anyway this is a simple code to draw a sinus line on a window:
void GraphSomething(HWND hwnd)
{
	RECT rWin;
	GetClientRect(hwnd, &rWin);		//Get window dimensions

	HDC hDc = GetDC(hwnd);

	HPEN hPen = CreatePen(PS_DASHDOT, 2, RGB(255, 0, 0));

	HPEN hOldPen = SelectObject(hDc, hPen);

	float f = 4.0*3.14 / (float)(rWin.right-rWin.left);

	MoveToEx(hDc, rWin.left, rWin.bottom/2 - ((float)rWin.bottom/2 * sin(0.0)), NULL);

	for (int i=rWin.left; i<rWin.right; i++)
	{
		int pt = (float)rWin.bottom/2 * sin(f * (float)(i));
		LineTo(hDc, i, rWin.bottom/2 - pt);
	}

	DeleteObject(SelectObject(hDc, hOldPen));

	ReleaseDC(hwnd, hDc);
}


谢谢Ravi。

我不懂GetDC [^]

当我做GetDC(Wind [4])我在Pelles C调试器中得到结构HDC_ * hdc = struct HDC_ = int unused *< f701644?>

,并且像素不是设置在任何地方。
Thank you Ravi.
I don't understand GetDC[^]
When I do GetDC(Wind[4]) I get struct HDC_*hdc = struct HDC_ = int unused *<f701644?>
in the Pelles C debugger, and the pixel are not set anywhere.


这篇关于如何获得Wind [4]的hdc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆