Home
Forums
New posts
Search forums
Articles
Latest reviews
Search resources
Members
Current visitors
Newsgroups
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Home
Forums
Newsgroups
Microsoft DotNet
Microsoft C# .NET
Get notification buttons info - c# & api
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="deciacco, post: 10722460"] I need some help trying to figure out why the code below does not work. I'm trying to cycle through the icons in the notification area and get button information. Everything runs fine, but my TBUTTONINFO struct does not get populated. iIndex:False is further evidence that things aren't working, and I think I'm not setting the dwMask correctly. Thanks!! ********************************************************** Here is the output of the log from Spy++ spying on ToolbarWindow32: ********************************************************** <00001> 000D0078 S TB_BUTTONCOUNT <00002> 000D0078 R TB_BUTTONCOUNT nCount:5 <00003> 000D0078 S TB_GETBUTTONINFOW iID:0 lptbbi:001E9610 <00004> 000D0078 R TB_GETBUTTONINFOW iIndex:False <00005> 000D0078 S TB_GETBUTTONINFOW iID:1 lptbbi:001E9610 <00006> 000D0078 R TB_GETBUTTONINFOW iIndex:False <00007> 000D0078 S TB_GETBUTTONINFOW iID:2 lptbbi:001E9610 <00008> 000D0078 R TB_GETBUTTONINFOW iIndex:False <00009> 000D0078 S TB_GETBUTTONINFOW iID:3 lptbbi:001E9610 <00010> 000D0078 R TB_GETBUTTONINFOW iIndex:False <00011> 000D0078 S TB_GETBUTTONINFOW iID:4 lptbbi:001E9610 <00012> 000D0078 R TB_GETBUTTONINFOW iIndex:False ********************************************************** ********************************************************** Here is the full code: ********************************************************** using System; using System.Collections.Generic; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Text; using System.ComponentModel; using System.Diagnostics; using System.Threading; namespace CloseExe { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { IntPtr shelltraywnd = Win32Api.FindWindow( "shell_traywnd", null); IntPtr traynotifywnd = Win32Api.FindWindowEx( shelltraywnd, IntPtr.Zero, "traynotifywnd", null); IntPtr traysyspager = Win32Api.FindWindowEx( traynotifywnd, IntPtr.Zero, "syspager", null); IntPtr toolbarwindow32 = Win32Api.FindWindowEx( traysyspager, IntPtr.Zero, "toolbarwindow32", null); int buttoncount = (int)Win32Api.SendMessage( new HandleRef(null, toolbarwindow32), Win32Api.TB_BUTTONCOUNT, IntPtr.Zero, IntPtr.Zero); Win32Api.TBBUTTONINFO[] buttons = new Win32Api.TBBUTTONINFO[buttoncount]; for (int i = 0; i < buttoncount; i++) { Win32Api.TBBUTTONINFO ti = new Win32Api.TBBUTTONINFO(); ti.dwMask = Win32Api.TBIF_BYINDEX | Win32Api.TBIF_TEXT; ti.cbSize = (uint)Marshal.SizeOf(ti); Win32Api.SendMessage( new HandleRef(null, toolbarwindow32), Win32Api.TB_GETBUTTONINFO, (IntPtr)i, ref ti); buttons[i] = ti; } }// Main } public static class Win32Api { public const int WM_USER = 0x0400; //**Tried using WM_USER + 65 but gives error** public const uint TB_GETBUTTONINFO = 0x043F; public const uint TB_BUTTONCOUNT = WM_USER + 24; public const int TBIF_IMAGE = 0x0001; public const int TBIF_TEXT = 0x0002; public const int TBIF_STATE = 0x0004; public const int TBIF_STYLE = 0x0008; public const int TBIF_LPARAM = 0x0010; public const int TBIF_COMMAND = 0x0020; public const int TBIF_SIZE = 0x0040; public const uint TBIF_BYINDEX = 0x0000; [StructLayout(LayoutKind.Sequential)] public struct TBBUTTONINFO { public uint cbSize; public uint dwMask; public int idCommand; public int iImage; public byte fsState; public byte fsStyle; public short cx; public IntPtr lParam; [MarshalAs(UnmanagedType.LPTStr)] public string lpszText; public int cchText; } [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] public static extern IntPtr SendMessage( HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam); [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr SendMessage( HandleRef hWnd, uint Msg, IntPtr wParam, ref TBBUTTONINFO lParam); } }[/i] [/QUOTE]
Verification
Post reply
Home
Forums
Newsgroups
Microsoft DotNet
Microsoft C# .NET
Get notification buttons info - c# & api
Top