Click here to Skip to main content
15,915,019 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to effectively remove background of an image c# Pin
musefan12-Nov-10 2:23
musefan12-Nov-10 2:23 
AnswerRe: how to effectively remove background of an image c# Pin
fjdiewornncalwe12-Nov-10 4:02
professionalfjdiewornncalwe12-Nov-10 4:02 
QuestionMvvm - Validation [modified] Pin
manni198110-Nov-10 20:45
manni198110-Nov-10 20:45 
QuestionHow can i know what is the bitmap color size of each pixel ? Pin
Yanshof10-Nov-10 20:17
Yanshof10-Nov-10 20:17 
AnswerRe: How can i know what is the bitmap color size of each pixel ? Pin
David Ewen10-Nov-10 21:31
professionalDavid Ewen10-Nov-10 21:31 
AnswerRe: How can i know what is the bitmap color size of each pixel ? Pin
_Erik_11-Nov-10 1:46
_Erik_11-Nov-10 1:46 
Questionhow to generate toolstrip like glossy sky blue color for my forms back color? Pin
Tridip Bhattacharjee10-Nov-10 18:58
professionalTridip Bhattacharjee10-Nov-10 18:58 
QuestionDetecting display setting change like dual display ,resolution change etc. Pin
HalliHaida10-Nov-10 18:26
HalliHaida10-Nov-10 18:26 
I am trying to write a method which will get triggered whenever there is a display settings change like resolution change, dual monitor connected and enabled etc. For this I am relying on SystemEvents.DisplaySettingsChanged event.


In the event handler, I am doing the following to detect the active display devices (got this in google search).


[StructLayout(LayoutKind.Sequential)]
public struct DISPLAY_DEVICE
{
public int cb;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string DeviceName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string DeviceString;
public int StateFlags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string DeviceID;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string DeviceKey;

public DISPLAY_DEVICE(int flags)
{
cb = 0;
StateFlags = flags;
DeviceName = new string((char)32, 32);
DeviceString = new string((char)32, 128);
DeviceID = new string((char)32, 128);
DeviceKey = new string((char)32, 128);
cb = Marshal.SizeOf(this);
}
}


[DllImport("user32.dll")]
public static extern bool EnumDisplayDevices(
string lpDevice, int iDevNum,
ref DISPLAY_DEVICE lpDisplayDevice, int dwFlags);

const int DISPLAY_DEVICE_ACTIVE = 0x01;
const int DISPLAY_DEVICE_PRIMARY_DEVICE = 0x04;

foreach (Screen screen in Screen.AllScreens)
{
LogMsg("Display Device:" + screen.DeviceName + " " + "BPP:" + screen.BitsPerPixel.ToString() + " " + "Width:" + screen.Bounds.Width.ToString() + " " + "Height:" + screen.Bounds.Height.ToString());

DISPLAY_DEVICE monitor = new DISPLAY_DEVICE(0);

monitor.cb = System.Runtime.InteropServices.Marshal.SizeOf(monitor);

LogMsg("Cb:" + monitor.cb.ToString());

EnumDisplayDevices(screen.DeviceName, 0, ref monitor, 0);

LogMsg("State flags:" + monitor.StateFlags.ToString());


if ((monitor.StateFlags & DISPLAY_DEVICE_ACTIVE) == 0x01)
{
LogMsg("Display Device is active");
}
if ((monitor.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) == 0x04)
{
LogMsg("Display Device is primary one");
}
}

What I observed is, the StateFlags is always zero. Then how to check for the active display device?

Is there any other way to detect all the active physical display devices? Any idea whats wrong in the above method?

Also, in the event handler, how to know what caused this event? What I mean is, whether the resolution caused this event or changing to dual monitor caused this event?

Any help or pointer is appreciated.
AnswerRe: Detecting display setting change like dual display ,resolution change etc. Pin
Luc Pattyn10-Nov-10 23:37
sitebuilderLuc Pattyn10-Nov-10 23:37 
AnswerRe: Detecting display setting change like dual display ,resolution change etc. Pin
_Erik_11-Nov-10 0:05
_Erik_11-Nov-10 0:05 
QuestionNo problem.. just more of "What would you do" question.. Pin
Jacob D Dixon10-Nov-10 11:14
Jacob D Dixon10-Nov-10 11:14 
AnswerRe: No problem.. just more of "What would you do" question.. Pin
_Erik_11-Nov-10 0:44
_Erik_11-Nov-10 0:44 
GeneralRe: No problem.. just more of "What would you do" question.. Pin
Jacob D Dixon11-Nov-10 3:58
Jacob D Dixon11-Nov-10 3:58 
GeneralRe: No problem.. just more of "What would you do" question.. Pin
_Erik_12-Nov-10 3:14
_Erik_12-Nov-10 3:14 
GeneralRe: No problem.. just more of "What would you do" question.. Pin
Jacob D Dixon12-Nov-10 5:30
Jacob D Dixon12-Nov-10 5:30 
GeneralRe: No problem.. just more of "What would you do" question.. Pin
_Erik_12-Nov-10 6:01
_Erik_12-Nov-10 6:01 
GeneralRe: No problem.. just more of "What would you do" question.. Pin
Jacob D Dixon12-Nov-10 11:30
Jacob D Dixon12-Nov-10 11:30 
GeneralRe: No problem.. just more of "What would you do" question.. Pin
Jacob D Dixon14-Nov-10 14:23
Jacob D Dixon14-Nov-10 14:23 
GeneralRe: No problem.. just more of "What would you do" question.. Pin
_Erik_15-Nov-10 3:33
_Erik_15-Nov-10 3:33 
QuestionMonitor the phone state Pin
hoi110-Nov-10 10:39
hoi110-Nov-10 10:39 
Questionsending arguments to "Save As" Dialog box Pin
igalep13210-Nov-10 4:31
igalep13210-Nov-10 4:31 
AnswerRe: sending arguments to "Save As" Dialog box Pin
musefan10-Nov-10 5:56
musefan10-Nov-10 5:56 
AnswerRe: sending arguments to "Save As" Dialog box Pin
Richard MacCutchan10-Nov-10 6:19
mveRichard MacCutchan10-Nov-10 6:19 
GeneralRe: sending arguments to "Save As" Dialog box Pin
igalep13210-Nov-10 10:09
igalep13210-Nov-10 10:09 
GeneralRe: sending arguments to "Save As" Dialog box Pin
Richard MacCutchan10-Nov-10 22:36
mveRichard MacCutchan10-Nov-10 22:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.