当前位置:编程学习 > VC++ >>

vc++编程问题

// 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!

补充:建立的是WIN32 application工作区,大家帮帮忙!
		
追问:

把CONST去掉后错误又10处,多6处了

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

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

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


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

上一个:VC++安装路径
下一个:vc++怎么学习

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,