资源简介
Win32 API编写一个系统托盘。实现的功能有:显示提示框、气泡、上下文菜单
代码片段和文件信息
#include
#include“resource.h“
#define WMU_NOTIFY WM_USER+1
TCHAR szAppName[] = TEXT (“TuoPan“) ;
LRESULT CALLBACK WndProc (HWND UINT WPARAM LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance HINSTANCE hPrevInstance
PSTR szCmdLine int iCmdShow)
{
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (hInstance MAKEINTRESOURCE(IDI_ICON1)) ;
wndclass.hCursor = LoadCursor (NULL IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockobject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL TEXT(“This Program requires Windows7!“) szAppName MB_OK) ;
return 0 ;
}
hwnd = CreateWindow ( szAppName
szAppName
WS_OVERLAPPEDWINDOW
CW_USEDEFAULT
CW_USEDEFAULT
CW_USEDEFAULT
CW_USEDEFAULT
NULL
NULL
hInstance
NULL) ;
ShowWindow (hwnd iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg NULL 0 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd UINT message WPARAM wParam LPARAM lParam)
{
NOTIFYICONDATA nid ;
static HMENU hMenu ;
POINT point ;
HINSTANCE hInstance ;
switch (message)
{
case WM_CREATE:
hInstance = (HINSTANCE) GetWindowLong (hwnd GWL_HINSTANCE) ;
hMenu = LoadMenu (hInstance TEXT(“TuoPan“)) ;
hMenu = GetSubMenu (hMenu 0) ;
nid.cbSize = sizeof (NOTIFYICONDATA) ;
nid.hWnd = hwnd ;
nid.uID = IDI_ICON1 ;
nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP | NIF_INFO;
nid.hIcon = LoadIcon (hInstance MAKEINTRESOURCE(IDI_ICON1)) ;
nid.uCallbackMessage = WMU_NOTIFY ;
//提示框内容
wcscpy_s(nid.szTip szAppName) ;
//气泡通知
wcscpy_s(nid.szInfo szAppName);
wcscpy_s(nid.szInfotitle L“:)“);
nid.uTimeout = 10000;
nid.dwInfoFlags = NIIF_NONE;
Shell_NotifyIcon (NIM_ADD &nid) ;
return 0 ;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDM_EXIT:
SendMessage (hwnd WM_DESTROY wParam lParam) ;
return 0 ;
case IDM_HIDE:
ShowWindow(hwnd SW_HIDE);
return 0;
}
return 0 ;
case WMU_NOTIFY:
if(lParam == WM_RBUTTONDOWN)//托盘消息中lParam接受鼠标的行为
{
GetCursorPos(&point) ;
SetForegroundWindow(hwnd) ;
TrackPopupMenu(hMenu TPM_RIGHTBUTTON point.x point.y 0 hwnd NULL) ;
}
else if(lParam == WM_LBUTTONDOWN)
{
ShowWindow(hwnd SW_SHOW);
}
return 0 ;
case WM_DESTROY:
nid.uID = IDI_ICON1 ;
nid.hWnd = hwnd ;
Shell_NotifyIcon (NIM_DELETE &nid) ;
PostQuitMessage (0) ;
return 0 ;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2013-04-10 22:44 TuoPan\
目录 0 2013-04-10 22:28 TuoPan\Debug\
文件 32768 2013-04-10 22:53 TuoPan\Debug\TuoPan.exe
文件 392848 2013-04-10 22:53 TuoPan\Debug\TuoPan.ilk
文件 519168 2013-04-10 22:53 TuoPan\Debug\TuoPan.pdb
目录 0 2013-04-11 00:34 TuoPan\TuoPan\
文件 885 2012-05-01 20:44 TuoPan\TuoPan.sln
文件 11264 2013-04-10 22:50 TuoPan\TuoPan.suo
文件 3085 2013-04-10 22:53 TuoPan\TuoPan\main.cpp
文件 1276 2013-04-10 22:50 TuoPan\TuoPan\resource.h
文件 1078 2013-04-10 22:43 TuoPan\TuoPan\TaskbarDemo.ICO
文件 35380 2013-04-10 22:50 TuoPan\TuoPan\TuoPan.aps
文件 3800 2013-04-10 22:50 TuoPan\TuoPan\TuoPan.rc
文件 4168 2013-04-10 22:43 TuoPan\TuoPan\TuoPan.vcxproj
文件 1399 2013-04-10 22:43 TuoPan\TuoPan\TuoPan.vcxproj.filters
文件 143 2012-05-01 20:44 TuoPan\TuoPan\TuoPan.vcxproj.user
- 上一篇:合工大 编译原理课程设计 LR(1)
- 下一篇:linux下的ddos工具
评论
共有 条评论