//检测当前分辨率  
    int Width = GetSystemMetrics(SM_CXSCREEN);  
       int Height = GetSystemMetrics(SM_CYSCREEN);  
    DEVMODE lpDevMode0;  
    lpDevMode0.dmBitsPerPel=32;  
    lpDevMode0.dmPelsWidth=Width;  
    lpDevMode0.dmPelsHeight=Height;  
    lpDevMode0.dmSize=sizeof(lpDevMode0);  
    lpDevMode0.dmFields =DM_PELSWIDTH|DM_PELSHEIGHT|DM_BITSPERPEL;  
    //修改  
    DEVMODE lpDevMode;  
    lpDevMode.dmBitsPerPel=32;  
    lpDevMode.dmPelsWidth=1024;  
    lpDevMode.dmPelsHeight=768;  
    lpDevMode.dmSize=sizeof(lpDevMode);  
    lpDevMode.dmFields =DM_PELSWIDTH|DM_PELSHEIGHT|DM_BITSPERPEL;  
    LONG result;  
    result=ChangeDisplaySettings(&lpDevMode,0);  
    if (result==DISP_CHANGE_SUCCESSFUL)  
    {  
        //MessageBox("修改成功!");  
        ChangeDisplaySettings(&lpDevMode,CDS_UPDATEREGISTRY);  
        //            //使用CDS_UPDATEREGISTRY表示次修改是持久的,  
        //            //并在注册表中写入了相关的数据  
        MessageBox("修改成功!还原");  
        if(IDOK)  
        {  
            ChangeDisplaySettings(&lpDevMode0,CDS_UPDATEREGISTRY);  
        }  
    }  
    else  
    {  
        //MessageBox("修改失败,恢复原有设置!");  
        ChangeDisplaySettings(NULL,0);  
    }  

出处:http://blog.csdn.net/nat_myron/article/details/8502009

posted on 2015-07-23 16:15  vinsonLu  阅读(4077)  评论(0编辑  收藏  举报