标题:一个绘图程序出了问题,各位高手来看看
取消只看楼主
八画小子
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:37
帖 子:705
专家分:2043
注 册:2010-11-11
结帖率:96.55%
已结贴  问题点数:0 回复次数:0 
一个绘图程序出了问题,各位高手来看看
程序代码:
#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



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-350800-1-1.html




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

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