| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 571 人关注过本帖
标题:一个绘图程序出了问题,各位高手来看看
只看楼主 加入收藏
八画小子
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:37
帖 子:709
专家分:2063
注 册:2010-11-11
结帖率:96.55%
收藏
已结贴  问题点数:0 回复次数:1 
一个绘图程序出了问题,各位高手来看看
程序代码:
#include <windows.h>
#include <cmath>

const int        NUM        = 32187;
const double    TWOPI    = (2 * 3.14159);

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
    static TCHAR        szAppName[] = TEXT ("SineWave");        // 添加
    HWND                hwnd;
    MSG                    msg;
    WNDCLASSEX            wndclassex = {0};

    wndclassex.cbSize                = sizeof(WNDCLASSEX);
    wndclassex.style                = CS_HREDRAW | CS_VREDRAW;
    wndclassex.lpfnWndProc            = WndProc;
    wndclassex.cbClsExtra            = 0;
    wndclassex.cbWndExtra            = 0;
    wndclassex.hInstance            = hInstance;
    wndclassex.hIcon                = LoadIcon (NULL, IDI_APPLICATION);
    wndclassex.hCursor                = LoadCursor (NULL, IDC_ARROW);
    wndclassex.hbrBackground        = (HBRUSH) GetStockObject (WHITE_BRUSH);
    wndclassex.lpszMenuName            = NULL;
    wndclassex.lpszClassName        = szAppName;
    wndclassex.hIconSm                = wndclassex.hIcon;
   
    if (!RegisterClassEx (&wndclassex))
    {
        MessageBox (NULL, TEXT ("RegisterClassEx failed!"), szAppName, MB_ICONERROR);
        return 0;
    }

    hwnd = CreateWindowEx (WS_EX_OVERLAPPEDWINDOW,
                           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)
{
    HDC                    hdc;
    PAINTSTRUCT            ps;
    POINT                apt[NUM];

    static int            cxClient, cyClient;

    switch (message)
    {
    case WM_CREATE:
        hdc    = GetDC (hwnd);
        ReleaseDC (hwnd, hdc);
        return 0;

    case WM_PAINT:
        hdc = BeginPaint (hwnd, &ps);
        MoveToEx (hdc, 0,        cyClient / 2, NULL) ;
        LineTo   (hdc, cxClient, cyClient / 2) ;
        for (int 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) ;
        EndPaint (hwnd, &ps);
        return 0;

    case WM_SIZE:
        cxClient = LOWORD(lParam);
        cyClient = HIWORD(lParam);
        return 0;

    case WM_DESTROY:
        PostQuitMessage (0);
        return 0;
    }
   
    return DefWindowProc (hwnd, message, wParam, lParam);
}

这个程序主要是输出正弦曲线。当我把NUM的值改为32187以上的时候就可能会出现程序出错的情况,值越大,概率越大。
我的问题是  这是为什么?查看了内存和CPU的使用情况,都没有发生异常。
搜索更多相关主题的帖子: message 
2011-09-25 04:03
czsbc
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:469
专家分:1700
注 册:2008-12-13
收藏
得分:20 
stack overflow!
用全局变量在堆里分配。
2011-09-25 18:20
快速回复:一个绘图程序出了问题,各位高手来看看
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016343 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved