菜鸟求一段简单的C++的GDI+程序代码
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了菜鸟求一段简单的C++的GDI+程序代码相关的知识,希望对你有一定的参考价值。
初学 对于VC++里的GDI+不是很明白 对那些什么初始化啊什么清除啊都不太明白 想求个完整的程序代码让我了解下结构 要直接粘贴在CPP文件里就能编译运行的 谢谢了
不要太大了。。就什么简单但是结构完整的 比如画个坐标轴之类的
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
参考技术A 我有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;
本回答被提问者和网友采纳
求一段VBS压缩RAR或ZIP代码
求一段VBS压缩RAR或ZIP代码,我想将一个文件夹里面的所以内容利用VBS压缩成ZIP或RAR,然后利用日期时间命名。
一楼的代码好像运行不了,
错误:
行9 字符5 缺少对象“ws”
一个批处理就行了 参考技术B 批处理是可以很简单做到的 参考技术C BackUpFile("D:\Data")
Function BackUpFile(lstg_folder_name)
Dim fso, f, f1,fc,s,folder
Set fso=CreateObject("Scripting.FileSystemObject")
folder=fso.getfolder(ws.currentdirectory)
Set f=fso.GetFolder(lstg_folder_name)
Set fc=f.files
For Each f1 in fc
dim lf
lf=lstg_folder_name& "\" & f1.name
RarFile lf
Next
End Function
Function RarBackupFile(lastg_file_name)
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
Set fso=CreateObject("Scripting.FileSystemObject")
folder=fso.getfolder(WshShell.currentdirectory)
RarComponent =folder&"\RarComponent\rar.exe" rem 写rar具体地址
SourceFile = lastg_file_name
TargetFile = "D:\data\test.rar"
WshShell.Run RarComponent&" a -ep1 "&TargetFile&" "&SourceFile,0
End Function
以上是关于菜鸟求一段简单的C++的GDI+程序代码的主要内容,如果未能解决你的问题,请参考以下文章
求一段代码javascript 或JS代码 显示 今天 是几年几月星期几 我们已经认识几天了