菜鸟MFC 让对话框大小适合背景图片

    技术2022-05-19  21

          昨天在对话框贴了一张图,假设ID为IDB_TEST,问题是在创建对话框的时候开始是自己设定对话框的大小的,现在希望随着背景图的载入,窗口可以适应图片的大小。

          工程命名为TClock。

          在TClockDlog.h里面设定变量CRect rect,Point center。因为我想做个钟表,CPoint以后绘制的时候会用到但是暂时还没有。

          领建立一个函数

    InitialDlog()

    {

        GetClientRect(&rect);

        CBIitmap tempbg;

        BITMAP   tempbgInfo;

        tempbg.LoadBmp(IDB_TEST);

        tempbg.GetBmp(&tempbgInfo);

        rect.right=rect.left+tempbgInfo.bmWidth;

        rect.bottom=rect.top+tempbgInfo.bmHeight;

        center.x=rect.right/2;

        center.y=rect.bottom/2;

    }

     

    再在OnitialDlog里面加上如下代码

    InitialDlog();

    MoveWindow(0,0,rect.right,rect.bottom);

    这样得到的对话框就和背景图片的大小一样了。

     

     


    最新回复(0)