easyx鼠标操作问题

0

win11 cb 20.03下安装easyx2021
做了鼠标放在选项上左侧出现箭头的功能,请问一下为啥箭头经常会瞎闪,如何解决。
另外我又在VC6.0,安装的easyx2022上运行,发现箭头瞎闪问题明显减少甚至没有问题,是cb的问题吗

#include <stdio.h>
#include <easyx.h>
#include <graphics.h>
int main()
{
    int n=0,m=0;
    initgraph(1080,720,EW_SHOWCONSOLE);
    ExMessage msg;
    settextcolor(YELLOW);
    settextstyle(70,0,"宋体",0,0,0,true,false,false);
    outtextxy(540-textwidth("主 菜 单")/2,80,"主 菜 单");
    settextcolor(WHITE);
    settextstyle(50,0,"宋体",0,0,0,false,false,false);
    outtextxy(540-textwidth("1.数学")/2,200,"1.数学");
    outtextxy(540-textwidth("2.英语")/2,300,"2.英语");
    outtextxy(540-textwidth("3.计算机")/2,400,"3.计算机");
    outtextxy(540-textwidth("4.总分")/2,500,"4.总分");
    outtextxy(540-textwidth("5.平均分")/2,600,"5.平均分");
    settextcolor(YELLOW);
    while(!n)
    {
        if(peekmessage(&msg,EM_MOUSE|EM_KEY))
        {
            switch(msg.message)
            {
                case WM_MOUSEMOVE:
                    if(540-textwidth("1.数学")/2-textwidth("→")<=msg.x&&msg.x<=540+textwidth("1.数学")/2&&200<=msg.y&&msg.y<=200+textheight("数学"))
                       outtextxy(540-textwidth("1.数学")/2-textwidth("→"),200,"→");
                    if(540-textwidth("2.英语")/2-textwidth("→")<=msg.x&&msg.x<=540+textwidth("2.英语")/2&&300<=msg.y&&msg.y<=300+textheight("英语"))
                       outtextxy(540-textwidth("2.英语")/2-textwidth("→"),300,"→");
                    if(540-textwidth("3.计算机")/2-textwidth("→")<=msg.x&&msg.x<=540+textwidth("3.计算机")/2&&400<=msg.y&&msg.y<=400+textheight("计算机"))
                       outtextxy(540-textwidth("3.计算机")/2-textwidth("→"),400,"→");
                    if(540-textwidth("4.总分")/2-textwidth("→")<=msg.x&&msg.x<=540+textwidth("4.总分")/2&&500<=msg.y&&msg.y<=500+textheight("总分"))
                       outtextxy(540-textwidth("4.总分")/2-textwidth("→"),500,"→");
                    if(540-textwidth("5.平均分")/2-textwidth("→")<=msg.x&&msg.x<=540+textwidth("5.平均分")/2&&600<=msg.y&&msg.y<=600+textheight("平均分"))
                       outtextxy(540-textwidth("5.平均分")/2-textwidth("→"),600,"→");
                    if(!(540-textwidth("1.数学")/2-textwidth("→")<=msg.x&&msg.x<=540+textwidth("1.数学")/2&&200<=msg.y&&msg.y<=200+textheight("数学")))
                       clearrectangle(540-textwidth("1.数学")/2-textwidth("→"),200,540-textwidth("1.数学")/2,200+textheight("→"));
                    if(!(540-textwidth("2.英语")/2-textwidth("→")<=msg.x&&msg.x<=540+textwidth("2.英语")/2&&300<=msg.y&&msg.y<=300+textheight("英语")))
                        clearrectangle(540-textwidth("2.英语")/2-textwidth("→"),300,540-textwidth("2.英语")/2,300+textheight("→"));
                    if(!(540-textwidth("3.计算机")/2-textwidth("→")<=msg.x&&msg.x<=540+textwidth("3.计算机")/2&&400<=msg.y&&msg.y<=400+textheight("计算机")))
                        clearrectangle(540-textwidth("3.计算机")/2-textwidth("→"),400,540-textwidth("3.计算机")/2,400+textheight("→"));
                    if(!(540-textwidth("4.总分")/2-textwidth("→")<=msg.x&&msg.x<=540+textwidth("4.总分")/2&&500<=msg.y&&msg.y<=500+textheight("总分")))
                        clearrectangle(540-textwidth("4.总分")/2-textwidth("→"),500,540-textwidth("4.总分")/2,500+textheight("→"));
                    if(!(540-textwidth("5.平均分")/2-textwidth("→")<=msg.x&&msg.x<=540+textwidth("5.平均分")/2&&600<=msg.y&&msg.y<=600+textheight("平均分")))
                        clearrectangle(540-textwidth("5.平均分")/2-textwidth("→"),600,540-textwidth("5.平均分")/2,600+textheight("→"));
                       break;
                case WM_LBUTTONDOWN:
                    if(540-textwidth("1.数学")/2<=msg.x&&msg.x<=540+textwidth("1.数学")/2&&200<=msg.y&&msg.y<=200+textheight("数学"))
                        n=1;
                    if(540-textwidth("2.英语")/2<=msg.x&&msg.x<=540+textwidth("2.英语")/2&&300<=msg.y&&msg.y<=300+textheight("英语"))
                        n=2;
                    if(540-textwidth("3.计算机")/2<=msg.x&&msg.x<=540+textwidth("3.计算机")/2&&400<=msg.y&&msg.y<=400+textheight("计算机"))
                        n=3;
                    if(540-textwidth("4.总分")/2<=msg.x&&msg.x<=540+textwidth("2.圆饼图")/2&&500<=msg.y&&msg.y<=500+textheight("总分"))
                        n=4;
                    if(540-textwidth("5.平均分")/2<=msg.x&&msg.x<=540+textwidth("5.平均分")/2&&600<=msg.y&&msg.y<=600+textheight("平均分"))
                        n=5;
                    break;
                case WM_KEYDOWN:
                    if(msg.vkcode==97||msg.vkcode==49)
                        n=1;
                    if(msg.vkcode==98||msg.vkcode==50)
                        n=2;
                    if(msg.vkcode==99||msg.vkcode==51)
                        n=3;
                    if(msg.vkcode==100||msg.vkcode==52)
                        n=4;
                    if(msg.vkcode==101||msg.vkcode==53)
                        n=5;
                    break;
                default:
                    break;
            }
        }
    }
    return 0;
}
ava
原谅龙

2023-4-24

0

我的测试环境:
Code Blocks 20.03,EasyX 20220901,你的代码并没有发现闪烁问题。

你在同学电脑上测试,会闪烁吗?

ava
慢羊羊

2023-4-25

在同学电脑上不闪烁。我的easyx版本是20211002,我装一下最新版本吧,谢谢了 -  原谅龙  2023-4-25
0

在绘图循环前后加个批量绘图就好了 EasyX 文档 - BeginBatchDraw

ava
xiongfj ◑◑

2023-4-25

试了下,在cb加了批量绘图依然瞎闪,而VC本来不加批量绘图就几乎不瞎闪。或许就是编译器问题 -  原谅龙  2023-4-25
@原谅龙 是这样加的不? BeginBatchDraw();    while(!n){ ...  FlushBatchDraw();}    EndBatchDraw(); -  xiongfj ◑◑  2023-4-25
@xiongfj ◑◑ 是这样加的,瞎闪还是很严重 -  原谅龙  2023-4-25
技术讨论社区