我想编写一个应用程序,可以在屏幕上画一个矩形框,要求矩形框围于其他所有的窗口之上,并且不受其他程序的影响。也就是说:无论你在打开多少其他的窗口(甚至是看电影,玩游戏),所画的矩形始终浮在其上,并且不消失,除非关闭程序。有点类似于网上的一个叫《圣诞节礼物》的桌面程序一样。我使用了MFC中的GetDestopWindow,并且在OnDraw()函数中实现具体的操作。可是效果不行,当整个的屏幕刷新的时候,所画的矩形窗口就不见了,除非激活我的程序的窗口(其实我的程序不需要自己的窗口,只需一个最小化的图标控制程序的结束就可以了。但我是用MFC导向生成的基本框架,我又不会消除窗口的办法)。求各位大虾该如何实现这个功能。

解决方案 »

  1.   

    这个函数也许可以
    BOOL SetWindowPos(          HWND hWnd,
        HWND hWndInsertAfter,
        int X,
        int Y,
        int cx,
        int cy,
        UINT uFlags
    );hWndInsertAfter
    [in] Handle to the window to precede the positioned window in the Z order. This parameter must be a window handle or one of the following values.
    HWND_BOTTOM
    Places the window at the bottom of the Z order. If the hWnd parameter identifies a topmost window, the window loses its topmost status and is placed at the bottom of all other windows.
    HWND_NOTOPMOST
    Places the window above all non-topmost windows (that is, behind all topmost windows). This flag has no effect if the window is already a non-topmost window.
    HWND_TOP
    Places the window at the top of the Z order.
    HWND_TOPMOST
    Places the window above all non-topmost windows. The window maintains its topmost position even when it is deactivated.
    For more information about how this parameter is used, see the following Res section.
      

  2.   

    SetWindowPos()这个方法不行!
    还是会被覆盖
    用mfc的方法不怎么好解决这个问题!
    因为mfc是基于窗口的句柄而来实现的,这个跟windows编程有关系,所以,应该查查windows编程!
      

  3.   

    可能是我的问题太关注于浮动于其他的窗口了,这个还比较好办。另一个问题是当屏幕刷新时,矩形框(填充了颜色)始终存在。 一般来说,我们只有相应的窗口的在OnDraw中或WM_PAINT消息发出时,才会重绘相应的窗口,以保证所绘制的图形在窗口改变时仍然存在。因此,当有其他的程序刷新桌面时(如移动其他程序的窗口时,或仅仅是在桌面上点击右建选择“刷新”),由于不是我自己编写的程序的窗口在刷新,也不会去调用我的绘图程序,因此就会抹去我所绘的图形。所以我向问大家,这个问题如何解决。
      

  4.   

    其实很简单嘛.我以前也做过,先做一个非模态对话框,并置顶显示在屏幕上,然后在这个对话框的背景檫除函数里画画就行了.记得对话框的属性的边框改为none就行了.