我写了一个托盘程序。
最下化,在任务栏中显示图标。然后双击图片,要激活窗口,并且比原来的窗口打一些。
代码如下:LRESULT CRunupScreenChartDlg::ShowTray(WPARAM wParam, LPARAM lParam)
{
if(wParam!=IDR_MAINFRAME)
return 1;
switch(lParam)
{
case WM_RBUTTONUP://右键起来时弹出快捷菜单,这里只有一个“关闭”
{
LPPOINT lpoint=new tagPOINT;
::GetCursorPos(lpoint);//得到鼠标位置
CMenu menu;
menu.CreatePopupMenu();//声明一个弹出式菜单
//增加菜单项“关闭”,点击则发送消息WM_DESTROY给主窗口(已 //隐藏),将程序结束。
menu.AppendMenu(MF_STRING,WM_CLOSE,L"关闭"); //确定弹出式菜单的位置
menu.TrackPopupMenu(TPM_LEFTALIGN,lpoint->x,lpoint->y,this); //资源回收
HMENU hmenu=menu.Detach();
menu.DestroyMenu();
delete lpoint;
}
break;
case WM_LBUTTONDBLCLK://双击左键的处理
{
this->ShowWindow(SW_SHOW);//简单的显示主窗口完事儿
DeleteTray();
this->MoveWindow(m_rPrimitiveRect.left,m_rPrimitiveRect.right,m_rPrimitiveRect.Width() + 300,m_rPrimitiveRect.Height()+300 + 25,SWP_SHOWWINDOW);
//this->SetWindowPos(NULL,m_rPrimitiveRect.left,m_rPrimitiveRect.right,m_rPrimitiveRect.Width() + 300,m_rPrimitiveRect.Height()+300 + 25,SWP_SHOWWINDOW); }
break;
default:
break;
}
return 0;
}
问题是,都没有激活窗口。并且窗口没有改变大小。为什么?
最下化,在任务栏中显示图标。然后双击图片,要激活窗口,并且比原来的窗口打一些。
代码如下:LRESULT CRunupScreenChartDlg::ShowTray(WPARAM wParam, LPARAM lParam)
{
if(wParam!=IDR_MAINFRAME)
return 1;
switch(lParam)
{
case WM_RBUTTONUP://右键起来时弹出快捷菜单,这里只有一个“关闭”
{
LPPOINT lpoint=new tagPOINT;
::GetCursorPos(lpoint);//得到鼠标位置
CMenu menu;
menu.CreatePopupMenu();//声明一个弹出式菜单
//增加菜单项“关闭”,点击则发送消息WM_DESTROY给主窗口(已 //隐藏),将程序结束。
menu.AppendMenu(MF_STRING,WM_CLOSE,L"关闭"); //确定弹出式菜单的位置
menu.TrackPopupMenu(TPM_LEFTALIGN,lpoint->x,lpoint->y,this); //资源回收
HMENU hmenu=menu.Detach();
menu.DestroyMenu();
delete lpoint;
}
break;
case WM_LBUTTONDBLCLK://双击左键的处理
{
this->ShowWindow(SW_SHOW);//简单的显示主窗口完事儿
DeleteTray();
this->MoveWindow(m_rPrimitiveRect.left,m_rPrimitiveRect.right,m_rPrimitiveRect.Width() + 300,m_rPrimitiveRect.Height()+300 + 25,SWP_SHOWWINDOW);
//this->SetWindowPos(NULL,m_rPrimitiveRect.left,m_rPrimitiveRect.right,m_rPrimitiveRect.Width() + 300,m_rPrimitiveRect.Height()+300 + 25,SWP_SHOWWINDOW); }
break;
default:
break;
}
return 0;
}
问题是,都没有激活窗口。并且窗口没有改变大小。为什么?
case WM_LBUTTONDBLCLK://双击左键的处理
{
this->SendMessage(WM_SYSCOMMAND,SC_RESTORE,0);//给窗口发送“还原”消息
Rect rc;//声明一个矩形结构
this->GetWindowRect(&rc);//获取当前窗口矩形
int w=rc.right-rc.left+300;//新的宽度
int h=rc.bottom-rc.-top+300;//新的高度
this->MoveWindow(rc.left,rc.Top,w,h,1);//移动窗口
this->SetFocus();//获取焦点
break;
}
void CRunupScreenChartDlg::OnWindowPosChanging(WINDOWPOS* lpwndpos)
{
CDialog::OnWindowPosChanging(lpwndpos); // TODO: 在此处添加消息处理程序代码
if(!m_isShowWindow) //定义m_isShowWindow为是否显示窗口的标志
{
lpwndpos->flags &=~SWP_SHOWWINDOW;
}
}