WINCE5 基于MFC,使用GDI+时,能通过编译,但是画不出来
WINCE5 EVC基于MFC的。使用GDI+时,能通过编译,但是画不出来
我从这个网站http://www.ernzo.com/LibGdiplus.aspx下载下来VC使用GID+的头文件以及LIB库。。按
照下面的要求
配置好GDI+ 使用环境。。
头文件:
#include
using namespace Gdiplus;
#pragma comment (lib, "LibGDIPlus.lib")
在Oncreat事件中,调用
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);进行初始化。
在Ondestory事件中调用
GdiplusShutdown(gdiplusToken);
在ondraw()函数中简单测试。
void CsmartPDAView::OnDraw(CDC* pDC)
{
CsmartPDADoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
Graphics g(pDC->m_hDC);//就是这个地方设置端点时,g地址值总是为0,是我不应该这么样创建么??
Pen pen1(Color::Blue ,2);
g.Clear(Color::Black );//Pen也是为0 ,说明没有创建成功,是不是缺少什么文件?
g.DrawLine(&pen1,20,20,100,100);
}
能够通过编译,但就是画不出来~~
http://arabiaherbal.com/IT/?p=1这个例子倒是弄出来了。。不知道是怎么回事,困恼一周了~~谢谢
回91program
是EVC,,是我自己不小心打错了,,刚刚那个帖子已经结贴,重新发过一个了
如果方便直接用MFC的图形编程的设备环境类和图像对象类来实现楼主的功能应该很容易。
给你个例子:
CDC *dc = new CClientDC(this);//得到绘图环境
Cpen gridPen;
gridPen.CreatePen(PS_DASH, 1, RGB(0,0,255));//创建一个蓝色画笔
Cpen *penPoint = dc->SelectObject(&gridPen);//选中画笔
CBrush gridBrush( RGB(0,0,255));//创建一个蓝色画刷
CBrush *brushPoint = dc->SelectObject(&gridBrush);//选中画刷
CRect rect;
GetClientRect(&rect);
dc->Rectangle(rect);//绘制矩形
dc->SelectObject(penPoint);//恢复绘图对象
dc->SelectObject(brushPoint);//
gridPen.DeleteObject();//释放画笔
gridBursh.DeleteObject();//释放画刷
if(dc != NULL)//释放绘图环境
{
delete dc;
}
回huabinsir,
我用GDI画,就能够画出来~~
回seth1104
谢谢~~~但是我现在是想用到GDI+这个东西~呵呵
我看你那网站链接
创建应该是用这几个函数
Graphics::Graphics(Image*)
说明:Creates a Graphics object that is associated with an Image object.
Graphics::Graphics(HDC)
说明:Creates a Graphics object that is associated with a specified device context.
Graphics::Graphics(HDC,HANDLE)
说明:Creates a Graphics object that is associated with a specified device context and a specified device.
Graphics::Graphics(HWND,BOOL)
说明:Creates a Graphics object that is associated with a specified window.
画线用这个
Graphics::DrawLine(Pen*,Point&,Point&)
说明:The DrawLine method draws a line that connects two points.
Graphics::DrawLine(Pen*,PointF&,Point&)
说明:The DrawLine method draws a line that connects two points.
Graphics::DrawLine(Pen*,REAL,REAL,REAL,REAL)
说明:The DrawLine method draws a line that connects two points.
Graphics::DrawLine(Pen*,INT,INT,INT,INT)
说明:The DrawLine method draws a line that connects two points.
Graphics::DrawLines(Pen*,Point*,INT)
说明:The DrawLines method draws a sequence of connected lines.
Graphics::DrawLines(Pen*,PointF*,INT)
说明:The DrawLines method draws a sequence of connected lines.
楼主自己看看
回wliaoc
我是用了Graphics::Graphics(HDC) 创建,Graphics::DrawLine(Pen*,INT,INT,INT,INT) 画线
引用: 引用楼主 sereve 的回复:
WINCE5 EVC基于MFC的。使用GDI+时,能通过编译,但是画不出来
Graphics g(pDC->m_hDC);//就是这个地方设置端点时,g地址值总是为0,是我不应该这么样创建么??
应该是Graphics g(pDC);就可以了
弄个整体实例给你,也是网站提供的。
Copy Code
#define UNICODE
#include
#include
using namespace Gdiplus;
VOID OnPaint(HDC hdc)
{
Graphics graphics(hdc);
Pen pen(Color(255, 0, 0, 255));
graphics.DrawLine(&pen, 0, 0, 200, 100);
}
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, INT iCmdShow)
{
HWND hWnd;
MSG msg;
WNDCLASS wndClass;
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
// Initialize GDI+.
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
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 = TEXT("GettingStarted");
RegisterClass(&wndClass);
hWnd = CreateWindow(
TEXT("GettingStarted"), // window class name
TEXT("Getting Started"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL); // creation parameters
ShowWindow(hWnd, iCmdShow);
UpdateWindow(hWnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
GdiplusShutdown(gdiplusToken);
return msg.wParam;
} // WinMain
LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
switch(message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
OnPaint(hdc);
EndPaint(hWnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
} // WndProc
回wliaoc
谢谢支持~
这个例子在我发帖时的链接网站http://arabiaherbal.com/IT/?p=1中也有这样的一个。。呵呵
只是我是在Ondraw()时调用,你的例子是在onpaint()时调用
是不是那个网站提供的C++库有些问题啊,,但是C#版本的却能使用