473,414 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Get notification buttons info - c# & api

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:
************************************************** ********
<00001000D0078 S TB_BUTTONCOUNT
<00002000D0078 R TB_BUTTONCOUNT nCount:5
<00003000D0078 S TB_GETBUTTONINFOW iID:0 lptbbi:001E9610
<00004000D0078 R TB_GETBUTTONINFOW iIndex:False
<00005000D0078 S TB_GETBUTTONINFOW iID:1 lptbbi:001E9610
<00006000D0078 R TB_GETBUTTONINFOW iIndex:False
<00007000D0078 S TB_GETBUTTONINFOW iID:2 lptbbi:001E9610
<00008000D0078 R TB_GETBUTTONINFOW iIndex:False
<00009000D0078 S TB_GETBUTTONINFOW iID:3 lptbbi:001E9610
<00010000D0078 R TB_GETBUTTONINFOW iIndex:False
<00011000D0078 S TB_GETBUTTONINFOW iID:4 lptbbi:001E9610
<00012000D0078 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);
}
}
Jul 26 '07 #1
0 3268

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Grady | last post by:
Help. I need to create a simple database that tracks equipment arrivals (and departures) at my facility. What I want is to create a simple form, which the receptionist could fill out, every time...
6
by: Jon | last post by:
Hello, I have a datagrid and the data in it is dynamically created at runtime... For iCounter = 0 To dataset.Tables(0).Columns.Count - 1 Dim objbc As New BoundColumn() With objbc .DataField...
1
by: Hai Ly Hoang [MT00KSTN] | last post by:
Different between Notification & Message is a bit hazy for me. Anyone can explain in detail for me ? Thanks in advance !
0
by: Eric | last post by:
Hi, For my program I use the notification control to show the user at least an icon or if (s)he decides to, a balloon as wel with some info. In the balloon I have two linkbuttons en the problem...
5
by: Alex Maghen | last post by:
In ASPX 2.0 with MasterPages and all that, my entire page only has one actual <FORM>. But there are several different sections of the page that provide what are functionally separate forms with...
1
by: MikeY | last post by:
Hi Everyone, I'm having a problem trying to place text with in my custom buttons. The problem is that I'm trying to display my text just as if it were a regular 'win' button, I have tried using...
16
by: browntown | last post by:
so I have this application I'm nearly finished with. The only thing the client has requested is the ability to submit the form by pressing "enter". I didn't think this would be a huge pain in the...
1
by: ansc1 | last post by:
Hello, I'm new to using php coding. I need help with the following: 1. There is a submit button on the form and is saves information to my database. After clicking on "Save Measurement" it...
2
beacon
by: beacon | last post by:
Hi everybody, I've searched and searched for the answers to these questions until I've turned blue in the face, so I finally decided to come here for some assistance. Here's the info I'm...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.