⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 set32mkalllightdlg.cpp

📁 解决显示屏亮度调节程序
💻 CPP
字号:
// Set32MKAllLightDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Set32MKAllLight.h"
#include "Set32MKAllLightDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//#define SIZE_MY_OFFSET 32

int m_show_flag=0;
int m_width=4,m_height=4;

int m_color_value=192;
char INI_PATHFILENAME[256];

COLORREF m_test_color[4]={RGB(0,0,0),RGB(192,0,0),RGB(0,192,0),RGB(0,0,192)};


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSet32MKAllLightDlg dialog

CSet32MKAllLightDlg::CSet32MKAllLightDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSet32MKAllLightDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSet32MKAllLightDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CSet32MKAllLightDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSet32MKAllLightDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSet32MKAllLightDlg, CDialog)
	//{{AFX_MSG_MAP(CSet32MKAllLightDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_KEYDOWN()
	ON_WM_CHAR()
	ON_MESSAGE(WM_MY_KEY,OnSendKeyEvent)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSet32MKAllLightDlg message handlers

BOOL CSet32MKAllLightDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	strcpy(INI_PATHFILENAME,GetCurDir());
	strcat(INI_PATHFILENAME,"Set32MKAllLight.ini");
	SetWindowText("Set32MKAllLight (Ver1.00) for win9x,2000,xp");
	m_startx=GetPrivateProfileInt("SCREEN","STARTX",0,INI_PATHFILENAME);
	m_starty=GetPrivateProfileInt("SCREEN","STARTY",0,INI_PATHFILENAME);
	m_width=GetPrivateProfileInt("SCREEN","WIDTH",4,INI_PATHFILENAME);	
	m_height=GetPrivateProfileInt("SCREEN","HEIGHT",4,INI_PATHFILENAME);
	if(m_width<0)
	{
		m_width=4;
	}
	if(m_height<0)
	{
		m_height=4;
	}
	m_color_value=GetPrivateProfileInt("SCREEN","COLOR_VALUE",192,INI_PATHFILENAME);
	if(m_color_value<0||m_color_value>255) m_color_value=255;

	//for(int i=0;i<3;i++)
	//{
		m_test_color[1]=RGB(m_color_value,0,0);
		m_test_color[2]=RGB(0,m_color_value,0);
		m_test_color[3]=RGB(0,0,m_color_value);
	//}


	

	m_show_flag=GetPrivateProfileInt("SCREEN","SHOW_FLAG",0,INI_PATHFILENAME);
	

	int w=::GetDeviceCaps(::GetDC(NULL),HORZRES);
	int h=::GetDeviceCaps(::GetDC(NULL),VERTRES );
	
	//int x1,y1,x2,y2;
	

	//x
	if(m_startx<=0)
		m_startx=0;
	if(m_startx>=w)
		m_startx=w-m_width*m_height;
    //y
	if(m_starty<=0)
		m_starty=0;
	if(m_starty>=h)
		m_starty=h-m_width*m_height;

	//调整屏的位置与大小	
    //MoveWindow(m_startx,m_starty,
	//	       m_startx+SIZE_MY_OFFSET,
	//		   m_starty+SIZE_MY_OFFSET);
	SetWindowPos((CWnd *)GetDesktopWindow(),m_startx-2,m_starty-2,m_width*8+4,m_height*8+4,SWP_NOZORDER);

	UpdateData(FALSE);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CSet32MKAllLightDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CSet32MKAllLightDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting

	if (IsIconic())
	{
	
	//CPaintDC dc(this); // device context for painting
		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}

/*	m_startx=GetPrivateProfileInt("SCREEN","STARTX",0,INI_PATHFILENAME);
	m_starty=GetPrivateProfileInt("SCREEN","STARTY",0,INI_PATHFILENAME);
	


	int w=::GetDeviceCaps(::GetDC(NULL),HORZRES);
	int h=::GetDeviceCaps(::GetDC(NULL),VERTRES );
	
	//x
	if(m_startx<=0)
		m_startx=0;
	if(m_startx>=w)
		m_startx=w-SIZE_MY_OFFSET;
    //y
	if(m_starty<=0)
		m_starty=0;
	if(m_starty>=h)
		m_starty=h-SIZE_MY_OFFSET;

	//调整屏的位置与大小	
    MoveWindow(m_startx,m_starty,
		       m_startx+SIZE_MY_OFFSET,
			   m_starty+SIZE_MY_OFFSET);

*/	
	//CClientDC dc(this);

	CBitmap bitmap;
    CBitmap* OldBitmap;
	CDC MemDC;    
    MemDC.CreateCompatibleDC(&dc); ///建立与显示设备兼容的内存设备场境
    bitmap.CreateCompatibleBitmap(&dc,m_width*8,m_height*8);///建立与显示设备兼容的位图
    OldBitmap=MemDC.SelectObject(&bitmap); ///将位图选入内存场境	

	CBrush brush(RGB(0,0,0));
	CBrush *oldbrush=MemDC.SelectObject(&brush);
	MemDC.FillRect(CRect(0,0,m_width*8,m_height*8),&brush);
    
	//test 
//	m_show_flag=1;

	CRect tmp_rect;
	//COLORREF tmp_color=RGB(0,0,255);
	if(m_show_flag>0)
	{
	//draw mk
	  int i,j,k;//y,x

	  int tmp_flag=0;

      k=m_show_flag/(m_width*m_height);
	  
	  tmp_flag=m_show_flag-k*m_width*m_height;
	  

	if(m_show_flag!=k*m_width*m_height)
	{
	  i=(tmp_flag-1)/m_width;
	  j=(tmp_flag-1)%m_width;

	}
	 else
	 {
		 i=(m_show_flag)/m_width;
		 
		 j=(m_show_flag)%m_width;
		 if(j==0)
		 {
			 j=m_width;
		 }

	 }  
	  	    
		tmp_rect.left =j*8;;
		tmp_rect.top =i*8;	 
		tmp_rect.right =tmp_rect.left +8;
		tmp_rect.bottom =tmp_rect.top +8;

		
		this->DrawMKRect(&MemDC,tmp_rect,
			m_test_color[k+1]);
		

		//grid	
		this->DrawMKBorder(&MemDC,tmp_rect,RGB(0,0,0));	
	}
	
	
	dc.BitBlt(0,0,m_width*8,m_height*8,&MemDC,0,0,SRCCOPY);



	MemDC.SelectObject(OldBitmap);	
	MemDC.SelectObject(oldbrush);
	MemDC.DeleteDC();
	bitmap.DeleteObject();
	brush.DeleteObject();
	


}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CSet32MKAllLightDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
CString CSet32MKAllLightDlg::GetCurDir()
{
	TCHAR sDrive[_MAX_DRIVE];
	TCHAR sDir[_MAX_DIR];
	TCHAR sFilename[_MAX_FNAME],Filename[_MAX_FNAME];
	TCHAR sExt[_MAX_EXT];

	GetModuleFileName(AfxGetInstanceHandle(), Filename, _MAX_PATH);
	_tsplitpath(Filename, sDrive, sDir, sFilename, sExt);
	CString homeDir(CString(sDrive) + CString(sDir));
	int nLen = homeDir.GetLength();
	if(homeDir.GetAt(nLen-1) != _T('\\'))
		homeDir += _T('\\');
	return homeDir;
}

void CSet32MKAllLightDlg::DrawMKRect(CDC *pDC,CRect rect,COLORREF color)
{
	CBrush brush(color);
	//CRect rect(
	CBrush *oldbrush=pDC->SelectObject(&brush);
	pDC->FillRect(rect,&brush);
	pDC->SelectObject(oldbrush);
	brush.DeleteObject();

	
}

void CSet32MKAllLightDlg::DrawMKBorder(CDC *pDC,CRect rect,COLORREF color)
{
	//pDC->SetROP2(R2_NOTXORPEN);

	CPen pen(PS_SOLID,2,color);
	CPen *oldpen=pDC->SelectObject(&pen);

	pDC->MoveTo(rect.left,rect.top);
	pDC->LineTo(rect.right,rect.top);
	pDC->LineTo(rect.right,rect.bottom);
	pDC->LineTo(rect.left,rect.bottom);
	pDC->LineTo(rect.left,rect.top);	
		
	pDC->SelectObject(oldpen);
	pen.DeleteObject();
	
}


BOOL CSet32MKAllLightDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	/*switch(pMsg->message)
	{
	
	    case WM_KEYDOWN:
			{
			  switch (pMsg->wParam)
			  {
				 // case VK_ESCAPE:					  
				  case VK_RETURN:
					   return TRUE;
					  break;
			  }
			}
		     break;	
	    default:
			 break;
	}*/

	return CDialog::PreTranslateMessage(pMsg);
}



void CSet32MKAllLightDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CSet32MKAllLightDlg::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default


	CDialog::OnChar(nChar, nRepCnt, nFlags);
}

void CSet32MKAllLightDlg::OnSendKeyEvent(void)
{
   Invalidate(FALSE);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -