Click here to Skip to main content
15,901,373 members
Home / Discussions / C#
   

C#

 
Questionsynchronise folder structures Pin
V.V.Thakur18-May-06 3:21
V.V.Thakur18-May-06 3:21 
Questiona few important questions about forms ? Pin
cmpeng3418-May-06 2:59
cmpeng3418-May-06 2:59 
AnswerRe: a few important questions about forms ? Pin
stancrm18-May-06 3:13
stancrm18-May-06 3:13 
AnswerRe: a few important questions about forms ? Pin
Leyu18-May-06 8:13
Leyu18-May-06 8:13 
QuestionThe Server is not operational when authenticating user to active directory Pin
krishna nimmalapudi18-May-06 2:46
krishna nimmalapudi18-May-06 2:46 
AnswerRe: The Server is not operational when authenticating user to active directory Pin
mav.northwind18-May-06 5:20
mav.northwind18-May-06 5:20 
QuestionRe:Palm Desktop software Pin
Smithasondur18-May-06 2:31
Smithasondur18-May-06 2:31 
Questiontrying to change screen resolution Pin
Alex Cutovoi18-May-06 2:21
Alex Cutovoi18-May-06 2:21 
Hi fellows
I've write a simple app that changes the screen resolution. This app must change the screen to 1024x768 or any that I want. Like you'll see in my code I have 2 private variables that receives the data to alter the resolution.
The resolution is altered but not that I would like. This code is changing the screen to 800x600 and set the color displaying to 4 not 32 32 bits.
Obs: I've already created the DEVMODE struct;
I have no idea what 's going onConfused | :confused: . Fellows help me, please.


<br />
<br />
public class ChangeResolution<br />
    {<br />
        private int m_iWidth;<br />
        private int m_iHeight;<br />
        //Parâmetros ChangeDisplaySettings<br />
        private const int CDS_UPDATEREGISTRY = 1;<br />
        private const int CDS_TEST           = 2;<br />
        //Retornos de ChangeDisplaySettings<br />
        public const int DISP_CHANGE_SUCCESSFUL = 0;<br />
        public const int DISP_CHANGE_RESTART    = 1;<br />
        public const int DISP_CHANGE_FAILED     = -1;<br />
        public const int DISP_CHANGE_BADMODE    = -2;<br />
        public const int DISP_CHANGE_NOTUPDATED = -3;<br />
        public const int DISP_CHANGE_BADFLAGS   = -4;<br />
        public const int DISP_CHANGE_BADPARAM   = -5;<br />
        public const int DM_PELSWIDTH  = 0x80000;<br />
        public const int DM_PELSHEIGHT = 0x100000;<br />
        public ChangeResolution(int iWidth, int iHeight)<br />
        {<br />
            m_iWidth = iWidth;<br />
            m_iHeight = iHeight;<br />
        }<br />
        [DllImport("user32.dll", CharSet = CharSet.Auto)]<br />
        public static extern int EnumDisplaySettings(string sDeviceName, int iModeNum, ref DEVMODE devMode);<br />
        [DllImport("user32.dll", CharSet = CharSet.Auto)]<br />
        public static extern int ChangeDisplaySettings(ref DEVMODE devMode, int iFlags);<br />
        public void AlterResolution()<br />
        {<br />
            DEVMODE devStruct = new DEVMODE();<br />
            devStruct.dmDeviceName = new string(new char[32]);<br />
            devStruct.dmFormName = new string(new char[32]);<br />
            devStruct.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));<br />
            devStruct.dmPelsWidth = m_iWidth;<br />
            devStruct.dmPelsHeight = m_iHeight;<br />
            devStruct.dmBitsPerPel = 24;<br />
            devStruct.dmDisplayFrequency = 75;<br />
            devStruct.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;<br />
            int i = 0;<br />
            StringBuilder sb = new StringBuilder();<br />
            while (true)<br />
            {<br />
                <br />
                if (EnumDisplaySettings(null, i, ref devStruct) != 0)<br />
                {<br />
                    sb.Append(i + "Width: " + devStruct.dmPelsWidth + " Height: " + devStruct.dmPelsHeight);<br />
                    i++;<br />
                }<br />
                else<br />
                {<br />
                    sb.Remove(0, sb.Length - 1);<br />
                    sb.Append(i + "Width: " + devStruct.dmPelsWidth + " Height: " + devStruct.dmPelsHeight);<br />
                    //MessageBox.Show(sb.ToString(), "Display2", MessageBoxButtons.OK, MessageBoxIcon.Information);<br />
                    break;<br />
                }<br />
            }<br />
            if (EnumDisplaySettings(null, i, ref devStruct) == DISP_CHANGE_FAILED)<br />
            {<br />
                MessageBox.Show("Não foi possivel obter infos do display", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);<br />
            }<br />
            if (EnumDisplaySettings(null, i, ref devStruct) == 0)<br />
            {<br />
                int iVal = ChangeDisplaySettings(ref devStruct, CDS_TEST);<br />
                switch(iVal)<br />
                {<br />
                    case DISP_CHANGE_SUCCESSFUL:<br />
                    {<br />
                       MessageBox.Show("Alterações feitas", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information);<br />
                       ChangeDisplaySettings(ref devStruct, CDS_UPDATEREGISTRY);<br />
                       break;<br />
                    }<br />
                    case DISP_CHANGE_RESTART:<br />
                    {<br />
                       MessageBox.Show("Reinicie sua máquina para que as novas configurações tenham efeito", "Infomação", MessageBoxButtons.OK, MessageBoxIcon.Information);<br />
                       break;<br />
                    }<br />
                    case DISP_CHANGE_FAILED:<br />
                    {<br />
                       MessageBox.Show("Falha ao tentar alterar a tela!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);<br />
                       break;<br />
                    }<br />
                    default:<br />
                    {<br />
                       MessageBox.Show("Nenhuma condição atendida", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information);<br />
                       break;<br />
                    }<br />
                }               <br />
            }<br />
        }<br />
    }<br />

QuestionRemoving stopwords Pin
Rizwan Rathore18-May-06 1:51
Rizwan Rathore18-May-06 1:51 
AnswerRe: Removing stopwords Pin
Robert Rohde18-May-06 2:36
Robert Rohde18-May-06 2:36 
GeneralRe: Removing stopwords Pin
Rizwan Rathore18-May-06 2:49
Rizwan Rathore18-May-06 2:49 
GeneralRe: Removing stopwords Pin
Robert Rohde18-May-06 3:00
Robert Rohde18-May-06 3:00 
GeneralRe: Removing stopwords Pin
Rizwan Rathore18-May-06 4:12
Rizwan Rathore18-May-06 4:12 
GeneralRe: Removing stopwords Pin
Robert Rohde18-May-06 4:21
Robert Rohde18-May-06 4:21 
GeneralRe: Removing stopwords Pin
Rizwan Rathore18-May-06 5:19
Rizwan Rathore18-May-06 5:19 
GeneralRe: Removing stopwords Pin
Robert Rohde18-May-06 5:52
Robert Rohde18-May-06 5:52 
Questionquestions for .NET compact Framework Pin
GDavy18-May-06 1:32
GDavy18-May-06 1:32 
Questionstatusstriplabels problem? :( Pin
cmpeng3418-May-06 1:17
cmpeng3418-May-06 1:17 
AnswerRe: statusstriplabels problem? :( Pin
Office Lineman18-May-06 6:33
Office Lineman18-May-06 6:33 
Questionhowto enable enter key active on a specific button ? Pin
cmpeng3418-May-06 1:11
cmpeng3418-May-06 1:11 
AnswerRe: howto enable enter key active on a specific button ? Pin
rah_sin18-May-06 1:35
professionalrah_sin18-May-06 1:35 
AnswerRe: howto enable enter key active on a specific button ? Pin
Rizwan Rathore18-May-06 1:57
Rizwan Rathore18-May-06 1:57 
QuestionThread.Abort() (Should I use try..catch?) Pin
Shy Agam18-May-06 1:02
Shy Agam18-May-06 1:02 
AnswerRe: Thread.Abort() (Should I use try..catch?) Pin
Robert Rohde18-May-06 1:34
Robert Rohde18-May-06 1:34 
AnswerRe: Thread.Abort() (Should I use try..catch?) Pin
Guffa18-May-06 1:36
Guffa18-May-06 1: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.