鱼C论坛

 找回密码
 立即注册
查看: 1709|回复: 1

polyline那个程序为啥我照着视频 但移动窗口后图形就不对了

[复制链接]
发表于 2019-4-7 21:11:29 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
初始窗口是正确的 但是一改变窗口大小 结果就不对了 没有重绘  上一次的图形和新的图形都存在
而视频里,随便移动窗口图形都是重绘一下


#include "stdio.h"
#include <windows.h>
#include <strsafe.h>
# include <math.h>
#define NUM 1000
#define twopi (2*3.14159)
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
        
        HDC hdc;
        PAINTSTRUCT        ps;
        //RECT rect;
        static int cxclient, cyclient;
        int i;

        POINT apt[NUM];

        switch (Message) {
        case WM_SIZE: {
                cxclient = LOWORD(lParam);
                cyclient = HIWORD(lParam);
                break;
        }
        
        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.x = i * cxclient / NUM;
                        apt.y = (int)cyclient/2 * (1- sin(twopi * i / NUM));
                }
                PolylineTo(hdc,apt,NUM);
               
                EndPaint(hwnd, &ps);

                break;
        }
        case WM_DESTROY: {
                PostQuitMessage(0);
                break;
        }
        default:
                return DefWindowProc(hwnd, Message, wParam, lParam);
        }
        return 0;
}

/* The 'main' function of Win32 GUI programs: this is where execution starts */
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
        WNDCLASSEX wc; /* A properties struct of our window */
        HWND hwnd; /* A 'HANDLE', hence the H, or a pointer to our window */
        MSG msg; /* A temporary location for all messages */

        /* zero out the struct and set the stuff we want to modify */
        memset(&wc, 0, sizeof(wc));
        wc.cbSize = sizeof(WNDCLASSEX);
        wc.lpfnWndProc = WndProc; /* This is where we will send messages to */
        wc.hInstance = hInstance;
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);

        /* White, COLOR_WINDOW is just a #define for a system color, try Ctrl+Clicking it */
        wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
        wc.lpszClassName = (LPCWSTR)"WindowClass";
        wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); /* Load a standard icon */
        wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); /* use the name "A" to use the project icon */

        if (!RegisterClassEx(&wc)) {
                MessageBox(NULL, (LPCWSTR)"Window Registration Failed!", (LPCWSTR) "Error!", MB_ICONEXCLAMATION | MB_OK);
                return 0;
        }

        hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, (LPCWSTR) "WindowClass", TEXT("paint"),
                WS_OVERLAPPEDWINDOW | WS_VISIBLE ,
                CW_USEDEFAULT, /* x */
                CW_USEDEFAULT, /* y */
                800, /* width */
                480, /* height */
                NULL, NULL, hInstance, NULL);

        if (hwnd == NULL) {
                MessageBox(NULL, (LPCWSTR)"Window Creation Failed!", (LPCWSTR)"Error!", MB_ICONEXCLAMATION | MB_OK);
                return 0;
        }

        /*
                This is the heart of our program where all input is processed and
                sent to WndProc. Note that GetMessage blocks code flow until it receives something, so
                this loop will not produce unreasonably high CPU usage
        */
        while (GetMessage(&msg, NULL, 0, 0) > 0) { /* If no error is received... */
                TranslateMessage(&msg); /* Translate key codes to chars if present */
                DispatchMessage(&msg); /* Send it to WndProc */
        }
        return msg.wParam;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2019-4-25 21:16:14 | 显示全部楼层
什么意思,你自己写了重绘函数了吗?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-29 16:20

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表