控制台程序如何实现点击窗体右上角的最小化后直接最小化进入托盘,而不在任务栏上显示?
//程序说明:下面的代码运行后,直接进入了托盘,在托盘处单击图标,可以将程序显示出来,再单击后则隐藏。我想要的效果是:在程序打开时,点击右上角的最小化后,直接进入托盘,不...
//程序说明:下面的代码运行后,直接进入了托盘,在托盘处单击图标,可以将程序显示出来,再单击后则隐藏。我想要的效果是:在程序打开时,点击右上角的最小化后,直接进入托盘,不在任务栏上显示,如何实现?
LRESULT CALLBACK TrayWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
BOOL isProcessFlag=0;
switch(uMsg)
{
case WM_NOTIFYICON:
switch(lParam)
{
case WM_RBUTTONUP:
ShowContextMenu(hWnd);
isProcessFlag=TRUE;
break;
case WM_LBUTTONUP:
if(IsWindowVisible(mainHwnd))
{
ShowWindow(mainHwnd,SW_HIDE);
}
else
{
ShowWindow(mainHwnd,SW_SHOWNORMAL);
SetFocus(mainHwnd);
}
isProcessFlag=TRUE;
break;
default:
break;
}
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case SWM_SHOW:
ShowWindow(mainHwnd,SW_SHOWNORMAL);
SetFocus(mainHwnd);
break;
case SWM_HIDE:
ShowWindow(mainHwnd,SW_HIDE);
break;
case SWM_EXIT:
Shell_NotifyIcon(NIM_DELETE, &NotifyIconData);
SendMessage(mainHwnd, WM_CLOSE, 0, 0 );
break;
default:
break;
}
break;
default:
break;
}
if(isProcessFlag)
return 0;
else
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
void ShowContextMenu(HWND hWnd)
{
POINT pt;
HMENU hMenu = CreatePopupMenu();
GetCursorPos(&pt);
if(hMenu)
{
if( IsWindowVisible(mainHwnd) )
InsertMenu(hMenu, -1, MF_BYPOSITION, SWM_HIDE, "隐藏");
else
InsertMenu(hMenu, -1, MF_BYPOSITION, SWM_SHOW, "显示");
InsertMenu(hMenu, -1, MF_BYPOSITION, SWM_EXIT, "关闭");
SetForegroundWindow(hWnd);
TrackPopupMenu(hMenu, TPM_BOTTOMALIGN,
pt.x, pt.y, 0, hWnd, NULL );
DestroyMenu(hMenu);
}
} 展开
LRESULT CALLBACK TrayWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
BOOL isProcessFlag=0;
switch(uMsg)
{
case WM_NOTIFYICON:
switch(lParam)
{
case WM_RBUTTONUP:
ShowContextMenu(hWnd);
isProcessFlag=TRUE;
break;
case WM_LBUTTONUP:
if(IsWindowVisible(mainHwnd))
{
ShowWindow(mainHwnd,SW_HIDE);
}
else
{
ShowWindow(mainHwnd,SW_SHOWNORMAL);
SetFocus(mainHwnd);
}
isProcessFlag=TRUE;
break;
default:
break;
}
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case SWM_SHOW:
ShowWindow(mainHwnd,SW_SHOWNORMAL);
SetFocus(mainHwnd);
break;
case SWM_HIDE:
ShowWindow(mainHwnd,SW_HIDE);
break;
case SWM_EXIT:
Shell_NotifyIcon(NIM_DELETE, &NotifyIconData);
SendMessage(mainHwnd, WM_CLOSE, 0, 0 );
break;
default:
break;
}
break;
default:
break;
}
if(isProcessFlag)
return 0;
else
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
void ShowContextMenu(HWND hWnd)
{
POINT pt;
HMENU hMenu = CreatePopupMenu();
GetCursorPos(&pt);
if(hMenu)
{
if( IsWindowVisible(mainHwnd) )
InsertMenu(hMenu, -1, MF_BYPOSITION, SWM_HIDE, "隐藏");
else
InsertMenu(hMenu, -1, MF_BYPOSITION, SWM_SHOW, "显示");
InsertMenu(hMenu, -1, MF_BYPOSITION, SWM_EXIT, "关闭");
SetForegroundWindow(hWnd);
TrackPopupMenu(hMenu, TPM_BOTTOMALIGN,
pt.x, pt.y, 0, hWnd, NULL );
DestroyMenu(hMenu);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |