菜鸟求一段简单的C++的GDI+程序代码
初学对于VC++里的GDI+不是很明白对那些什么初始化啊什么清除啊都不太明白想求个完整的程序代码让我了解下结构要直接粘贴在CPP文件里就能编译运行的谢谢了不要太大了。。就...
初学 对于VC++里的GDI+不是很明白 对那些什么初始化啊什么清除啊都不太明白 想求个完整的程序代码让我了解下结构 要直接粘贴在CPP文件里就能编译运行的 谢谢了
不要太大了。。就什么简单但是结构完整的 比如画个坐标轴之类的 展开
不要太大了。。就什么简单但是结构完整的 比如画个坐标轴之类的 展开
2个回答
展开全部
/*-------------------------------------------------------------------
SINEWAVE.C -- Sine Wave Using Polyline
(c) Charles Petzold, 1998
---------------------------------------------------------------------*/
#include <windows.h>
#include <math.h>
#define NUM 1000
#define TWOPI (2 * 3.14159)
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("SineWave") ;
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 ("Sine Wave Using Polyline"),
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 ;
int i ;
PAINTSTRUCT ps ;
POINT apt [NUM] ;
switch (message)
{
case WM_SIZE:
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
MoveToEx (hdc, 0, cyClient / 2, NULL) ;
LineTo (hdc, cxClient, cyClient / 2) ;
for (i = 0 ; i < NUM ; i++)
{
apt[i].x = i * cxClient / NUM ;
apt[i].y = (int) (cyClient / 2 * (1 - sin (TWOPI * i / NUM))) ;
}
Polyline (hdc, apt, NUM) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
运行结果:
代码出处:
《Windows程序设计(第五版)》P130
展开全部
我有VC++ WTL版本的GDI+代码工程,在我的博客里。
一个是时钟控件,一个是有动画效果的进度条,采用的是双缓冲绘制,以防止窗口抖动,你可以将GDI+代码部分用在MFC上面。
http://blog.csdn.net/renstarone/article/details/9089835
http://blog.csdn.net/renstarone/article/details/9230763
下面是画正选和余弦曲线的GDI+代码:
LRESULT CSineCurveView::OnPaint(UINT/*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
CPaintDCdc(m_hWnd);
Graphicsgraphic(m_hWnd);
CRectrect;
GetClientRect(&rect);
RectFrcBKG;
rcBKG.X = rect.left;
rcBKG.Y = rect.top;
rcBKG.Width = rect.Width();
rcBKG.Height = rect.Height();
SolidBrushbrush( Color(255, 48, 48, 48) );
graphic.FillRectangle(&brush,rcBKG);
PointF ptLineStart( (REAL)(rect.left), (REAL)(rect.bottom / 2) );
PointF ptLineEnd( (REAL)(rect.right), (REAL)(rect.bottom / 2) );
Pen penLine( Color(255, 255, 255, 255), 3 );
graphic.DrawLine(&penLine,ptLineStart, ptLineEnd);
PointFszSinePoint[NUM] = {};
PointFszCosPoint[NUM] = {};
intnWidth = rect.Width();
intnHeight = rect.Height();
for(int i = 0; i < NUM; ++i)
{
szSinePoint[i].X= (REAL) (i * nWidth / NUM) ;
szSinePoint[i].Y= (REAL) (nHeight / 2 * (1 - sin (TWOPI * i / NUM))) ;
szCosPoint[i].X= (REAL) (i * nWidth / NUM) ;
szCosPoint[i].Y= (REAL) (nHeight / 2 * (1 - cos (TWOPI * i / NUM))) ;
}
Pen penSine( Color(255, 0, 255, 0), 3 );
Pen penCos( Color(255, 128, 128, 255), 3 );
graphic.DrawLines(&penSine,szSinePoint, 10000);
graphic.DrawLines(&penCos,szCosPoint, 10000);
return0;
}
一个是时钟控件,一个是有动画效果的进度条,采用的是双缓冲绘制,以防止窗口抖动,你可以将GDI+代码部分用在MFC上面。
http://blog.csdn.net/renstarone/article/details/9089835
http://blog.csdn.net/renstarone/article/details/9230763
下面是画正选和余弦曲线的GDI+代码:
LRESULT CSineCurveView::OnPaint(UINT/*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
CPaintDCdc(m_hWnd);
Graphicsgraphic(m_hWnd);
CRectrect;
GetClientRect(&rect);
RectFrcBKG;
rcBKG.X = rect.left;
rcBKG.Y = rect.top;
rcBKG.Width = rect.Width();
rcBKG.Height = rect.Height();
SolidBrushbrush( Color(255, 48, 48, 48) );
graphic.FillRectangle(&brush,rcBKG);
PointF ptLineStart( (REAL)(rect.left), (REAL)(rect.bottom / 2) );
PointF ptLineEnd( (REAL)(rect.right), (REAL)(rect.bottom / 2) );
Pen penLine( Color(255, 255, 255, 255), 3 );
graphic.DrawLine(&penLine,ptLineStart, ptLineEnd);
PointFszSinePoint[NUM] = {};
PointFszCosPoint[NUM] = {};
intnWidth = rect.Width();
intnHeight = rect.Height();
for(int i = 0; i < NUM; ++i)
{
szSinePoint[i].X= (REAL) (i * nWidth / NUM) ;
szSinePoint[i].Y= (REAL) (nHeight / 2 * (1 - sin (TWOPI * i / NUM))) ;
szCosPoint[i].X= (REAL) (i * nWidth / NUM) ;
szCosPoint[i].Y= (REAL) (nHeight / 2 * (1 - cos (TWOPI * i / NUM))) ;
}
Pen penSine( Color(255, 0, 255, 0), 3 );
Pen penCos( Color(255, 128, 128, 255), 3 );
graphic.DrawLines(&penSine,szSinePoint, 10000);
graphic.DrawLines(&penCos,szCosPoint, 10000);
return0;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询