在下初学MFC,我做了桌面时钟的小程序,然后把对话框上的Title bar隐藏了,然后把时钟背景透明了,但是这样做后,用鼠标右击时钟,没有右键菜单,只能通过Esc才能把应用程序关闭。我想通过右击时钟显示右键菜单来关闭,但是试了好多方法,还是不行。请各位高手不吝赐教,在下谢过各位了MFC static控件 窗口 菜单

解决方案 »

  1.   

    你是怎么把对话框透明的?
    还有你说只剩下控件,是指这个clock?
      

  2.   

    原来的程序结果是:
    通过以下代码透明化的。然后就只剩下这个表盘了。
    typedef BOOL (WINAPI *lpfnSetLayeredWindowAttributes)(HWND hWnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags); 
    lpfnSetLayeredWindowAttributes SetLayeredWindowAttributes;     //设置成边缘透明     COLORREF maskColor=RGB(0,0,0);    HMODULE hUser32 = GetModuleHandle("user32.dll"); //加载动态链接库
        SetLayeredWindowAttributes = (lpfnSetLayeredWindowAttributes)GetProcAddress(hUser32,"SetLayeredWindowAttributes");           //取得SetLayeredWindowAttributes函数指针 
              //为窗口加入WS_EX_LAYERED扩展属性
    SetWindowLong(this->GetSafeHwnd(), GWL_EXSTYLE, GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE)^0x00080000);           //调用SetLayeredWinowAttributes函数
         SetLayeredWindowAttributes(this->GetSafeHwnd(), maskColor, 192, 0x00000001); FreeLibrary(hUser32);   //释放动态链接库
      

  3.   

    是在对话框中拖入的一个Static控件。然后通过映射变量来实现的。
      

  4.   

    先要更改那个static的ID, 然后才能处理它的消息.
      

  5.   

    CStatic控件本来是作为标签类型的控件,如果需要响应消息,你需把控件属性Notify勾上
      

  6.   

    自定义控件类继承CStatic,重写
    void CMyStatic::OnRButtonDown(UINT nFlags, CPoint point) 
    {
       CStatic::OnRButtonDown(nFlags, point);   CMenu* menu_bar = AfxGetMainWnd()->GetMenu();
       CMenu* file_menu = menu_bar->GetSubMenu(0);    
       ASSERT(file_menu);   file_menu->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, 
          point.y, this);
    }
      

  7.   

    标准的static控件是不响应鼠标单击的,要先为控件添加Notify属性,才能响应单击消息
      

  8.   

    Static控件的ID是一样的,如果你要对它进行特殊操作,则需要修改其ID