3 Replies - 4262 Views - Last Post: 29 August 2009 - 11:48 PM Rate Topic: -----

#1 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Desktop icons, visible or hidden?

Posted 29 August 2009 - 04:17 PM

I know I'm breaking the rules here because I have no code for what I'm attempting to do. I can hide & show the desktop icons in code (that part is complete) but what I'm having a hard time with is determining if the icons are visible or hidden so I can check or uncheck the CheckBox when the form loads.

Anyone have any idea where I can start with this, I haven't found much documentation on it thus far (No I don't want the code, just a starting point here :) )

Is This A Good Question/Topic? 0
  • +

Replies To: Desktop icons, visible or hidden?

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2264
  • View blog
  • Posts: 9,470
  • Joined: 29-May 08

Re: Desktop icons, visible or hidden?

Posted 29 August 2009 - 05:51 PM

From my research the desktop icons are contained in listview inside the desktop window.
The listview has an handle which I think you may already have.
Somewhere in the framework there is method to do the reverse. (I not say which, not until you show code first. ;) )
Being a .net form object it should also has the .visible property.

This post has been edited by AdamSpeight2008: 29 August 2009 - 05:55 PM

Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Desktop icons, visible or hidden?

Posted 29 August 2009 - 09:12 PM

This is how I'm showing and hiding the icons. First the Win32 API

[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern long ShowWindow(long hWnd, long nCmdShow);

[DllImport("user32", EntryPoint = "FindWindowExA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern long FindWindowEx(long hWnd1, long hWnd2, string lpsz1, string lpsz2);

[DllImport("user32.dll")]
public static extern long SendMessageTimeout(
	int hWnd,
	int Msg,
	int wParam,
	string lParam,
	int fuFlags,
	int uTimeout,
	out int lpdwResult);



Then the constants

private const int HWND_BROADCAST = 0xffff;
private const int WM_SETTINGCHANGE = 0x001A;
private const int SPI_SETNONCLIENTMETRICS = 0x0002;
[code]

Then the show/hide method

[code]
public bool ShowHideDesktopIcons(bool show)
{
	try
	{
		//get a handle to the desktop ("Progman")
		long winHandle = Win32.FindWindowEx(0L, 0L, "Progman", null);
		int res = 0;
		//determine if we're showing or hiding
		switch (show)
		{
			case true:
				Win32.ShowWindow(winHandle, 0);
				break;
			case false:
				Win32.ShowWindow(winHandle, 5);
				break;
		}
		Win32.SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, string.Empty, SPI_SETNONCLIENTMETRICS, 1000, out res);
		return true;
	}
	catch (Win32Exception ex)
	{
		_message = ex.Message;
		return false;
	}
	
}



I know there's a registry key HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Explorer\Advanced\HideIcons but I'm not 100% sure yet that that's what I need. Still checking on that
Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2264
  • View blog
  • Posts: 9,470
  • Joined: 29-May 08

Re: Desktop icons, visible or hidden?

Posted 29 August 2009 - 11:48 PM

I was only joking about the code sample. :D

But any how. I was think of
  Dim dw As IntPtr = FindWindow("Progman", "Program Manager")
  Dim c = Windows.Forms.Form.FromChildHandle(dw)


but for some reason it returns Nothing

So I did a little more digging. I think its close enough for you to modify.
Possible Solution
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1