永发信息网

vc++编程问题

答案:2  悬赏:10  手机版
解决时间 2021-04-14 16:41

// canvas.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "resource.h"
#include <stdio.h>
#include <math.h>
#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;
HPEN hPen;
HBRUSH hBru;
CONST POINT poly1[4],poly2[4],poly3[4]; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text

// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;

// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_CANVAS, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_CANVAS);

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return msg.wParam;
}

//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage is only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = NULL;
wcex.hCursor = LoadCursor(NULL,IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "canvas";
wcex.hIconSm = NULL;

return RegisterClassEx(&wcex);
}

//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
void MyPaint(HDC hdc)
{
SelectObject(hdc,hPen);
SelectObject(hdc,hBru);
PolylineTo(hdc,poly1,5);
Polyline(hdc,poly2,5);
Polygon(hdc,poly3,5);

}


BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
HDC hdc;
LONG x,y;
int i;

const double pi=3.1415926535;
hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow("canvas", "绘图窗口", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}
MoveWindow(hWnd,10,10,650,450,true);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
for(i=0;i<=4;i++)
{
poly1[i].x=100+100*sin(i*72*pi/180);
poly1[i].y=100+100*cos(i*72*pi/180);

poly2[i].x=poly1[i].x+300;
poly2[i].y=poly1[i].y;

poly3[i].x=poly2[i].x+180;
poly3[i].y=poly2[i].y+200;

}
hPen=CreatePen(PS_SOLID,5,RGB(255,0,0));
hBru=CreateHatchBrush(HS_BDIAGONAL,RGB(0,255,0));

hdc=GetDC(hWnd);
MyPaint(hdc);
ReleaseDC(hWnd,hdc);

return TRUE;
}


//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
int i;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
MyPaint(hdc);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
for(i=0;i<=6;i++)
{
DeleteObject(hPen);
DeleteObject(hBru);
}
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;

case WM_COMMAND:
if (LOWORd(wParam) == IDOK || LOWORd(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORd(wParam));
return TRUE;
}
break;
}
return FALSE;
}

运行以上程序后出现下面的错误,warning的那项我明白,帮我解释一下错误的地方就OK!

最佳答案
之前CONST POINT poly1[4],poly2[4],poly3[4]; // current instance

你又poly1[i].x=100+100*sin(i*72*pi/180);

你怎么可以把变量的值给常量呢,把CONST去掉吧。。。就这点错了


全部回答

都看不到错误,图片太不清晰,还是复制上来比较好

我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
浩方的求生之路4
梦见被人追杀。一共是两个人,一个是杀猪的,
羽状物 针孔点 晶体哪个最影响钻石品质? 我
乳瓜的做法大全,乳瓜怎么做好吃
周正龙什么时候出生的
为什么好友买卖总资产会减少?
18层的小高层十五层双阳面好吗
2009年办信用卡要什么条件?
女人感叹岁月的句子
国友酒行地址在哪,我要去那里办事
谁知道这个玩偶叫什么
单选题父子今年共47岁,14年后父亲的年龄是儿
我们常说的四书指什么,五岳是指什么
湖南大学mba值得读么
丁家宜日化在什么地方啊,我要过去处理事情
推荐资讯
超长伤感心情说说句子,伤感说说心情短语
英语翻译还有ee星的性能好不好?我是高三的,用
单选题若∠a=79°25′,则∠a的补角是A.100
诛仙世界中刷石头的任务在那接
培训机构交什么税,培训机构都交什么税?
短租一个月,上海松江新桥3室整租,哪里能找
有没有java技术的QQ群啊
动漫:《大剑》断罪之花ED MTV,下载
官帽面馆匠心菜在哪里啊,我有事要去这个地方
关于头发受损但想继续烫的问题
按钮突破器如何用
寻仙中的剑客杂加天赋点
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?