📄 cursoroptionsdlg.cpp
字号:
((CButton *) GetDlgItem(IDC_CUSTOMCURSOR))->EnableWindow(FALSE);
((CButton *) GetDlgItem(IDC_FILECURSOR))->EnableWindow(TRUE);
}
if (recordcursor==0) {
((CButton *) GetDlgItem(IDC_RADIO1))->SetCheck(TRUE);
((CButton *) GetDlgItem(IDC_RADIO2))->SetCheck(FALSE);
((CButton *) GetDlgItem(IDC_CURSOR1))->EnableWindow(FALSE);
((CButton *) GetDlgItem(IDC_CURSOR2))->EnableWindow(FALSE);
((CButton *) GetDlgItem(IDC_CURSOR3))->EnableWindow(FALSE);
((CButton *) GetDlgItem(IDC_CUSTOMCURSOR))->EnableWindow(FALSE);
((CButton *) GetDlgItem(IDC_FILECURSOR))->EnableWindow(FALSE);
}
else {
((CButton *) GetDlgItem(IDC_RADIO1))->SetCheck(FALSE);
((CButton *) GetDlgItem(IDC_RADIO2))->SetCheck(TRUE);
((CButton *) GetDlgItem(IDC_CURSOR1))->EnableWindow(TRUE);
((CButton *) GetDlgItem(IDC_CURSOR2))->EnableWindow(TRUE);
((CButton *) GetDlgItem(IDC_CURSOR3))->EnableWindow(TRUE);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CCursorOptionsDlg::OnSelchangeCustomcursor()
{
// TODO: Add your control notification handler code here
RefreshPreviewCursor();
}
void CCursorOptionsDlg::RefreshPreviewCursor()
{
if (recordcursor==0) {
previewcursor = NULL;
}
else {
if (cursortype==0) {
previewcursor = GetCursor();
}
else if (cursortype==1) {
customsel = ((CComboBox *) GetDlgItem(IDC_CUSTOMCURSOR))->GetCurSel();
DWORD customicon;
if (customsel<0) customsel = 0;
customicon = icon_info[customsel];
previewcursor = LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(customicon));
customcursor = previewcursor;
}
else {
previewcursor = loadcursor;
} //cursortype
} //recordcursor
((CStatic *) GetDlgItem(IDC_ICONCURSOR))->SetIcon(previewcursor);
}
void CCursorOptionsDlg::OnFilecursor()
{
// TODO: Add your command handler code here
CString fileName;
CString filt;
CString filetype;
filetype.LoadString(ID_FILETYPE_CURSOR);
filt.Format("%s (*.ico; *.cur)|*.ico;*.cur||", (LPCTSTR)filetype);
if (iconFileDlg == NULL)
iconFileDlg = new CFileDialog(TRUE,"*.ico;*.cur","*.ico;*.cur",NULL,filt,this);
if (iconFileDlg!=NULL) {
char dirx[200];
GetWindowsDirectory(dirx,200);
CString initdir(dirx);
initdir = initdir + "\\cursors";
iconFileDlg->m_ofn.Flags|=OFN_FILEMUSTEXIST;
CString titlestr;
titlestr.LoadString(ID_TITLE_LOADCURSOR);
iconFileDlg->m_ofn.lpstrTitle=titlestr;
if (cursordir=="")
cursordir=initdir;
iconFileDlg->m_ofn.lpstrInitialDir = cursordir;
if (iconFileDlg->DoModal()==IDOK) {
fileName=iconFileDlg->GetPathName();
CString extension =fileName.Right(4);
extension.MakeUpper();
if ((extension==".ICO") || (extension==".CUR")) {
loadcursor = LoadCursorFromFile(fileName);
previewcursor = loadcursor;
((CStatic *) GetDlgItem(IDC_ICONCURSOR))->SetIcon(previewcursor);
//LoadBMP(fileName);
}
g_cursorFilePath = fileName;
fileName=fileName.Left(fileName.ReverseFind('\\'));
cursordir = fileName;
}
delete iconFileDlg;
iconFileDlg = NULL;
}
}
void CCursorOptionsDlg::OnOK()
{
// TODO: Add extra validation here
if (cursortype==0) {
}
else if (cursortype==1) {
customcursor = previewcursor;
}
else {
loadcursor = previewcursor;
} //cursortype
g_customsel = customsel;
g_recordcursor = recordcursor;
g_cursortype = cursortype;
g_highlightcursor = highlightcursor;
g_highlightsize = highlightsize;
g_highlightshape = highlightshape;
g_highlightcolor = highlightcolor;
g_loadcursor = loadcursor;
g_customcursor = customcursor;
CDialog::OnOK();
}
void CCursorOptionsDlg::OnSelchangeHighlightshape()
{
// TODO: Add your control notification handler code here
highlightshape = ((CComboBox *) GetDlgItem(IDC_HIGHLIGHTSHAPE))->GetCurSel();
RefreshHighlight();
}
void CCursorOptionsDlg::OnHighlightcolor()
{
CColorDialog colerdlog(highlightcolor,CC_ANYCOLOR | CC_FULLOPEN |CC_RGBINIT);
if (colerdlog.DoModal() ==IDOK) {
highlightcolor=colerdlog.GetColor();
}
RefreshHighlight();
}
void CCursorOptionsDlg::OnHighlightcursor()
{
// TODO: Add your control notification handler code here
highlightcursor = ((CButton *) GetDlgItem(IDC_HIGHLIGHTCURSOR))->GetCheck();
if (highlightcursor) {
((CSliderCtrl *) GetDlgItem(IDC_HIGHLIGHTSIZE))->EnableWindow(TRUE);
((CComboBox *) GetDlgItem(IDC_HIGHLIGHTSHAPE))->EnableWindow(TRUE);
((CButton *) GetDlgItem(IDC_HIGHLIGHTCOLOR))->EnableWindow(TRUE);
((CStatic *) GetDlgItem(IDC_STATIC_SIZE))->EnableWindow(TRUE);
((CStatic *) GetDlgItem(IDC_STATIC_SHAPE))->EnableWindow(TRUE);
((CStatic *) GetDlgItem(IDC_STATIC_HALFSIZE))->EnableWindow(TRUE);
}
else {
((CSliderCtrl *) GetDlgItem(IDC_HIGHLIGHTSIZE))->EnableWindow(FALSE);
((CComboBox *) GetDlgItem(IDC_HIGHLIGHTSHAPE))->EnableWindow(FALSE);
((CButton *) GetDlgItem(IDC_HIGHLIGHTCOLOR))->EnableWindow(FALSE);
((CStatic *) GetDlgItem(IDC_STATIC_SIZE))->EnableWindow(FALSE);
((CStatic *) GetDlgItem(IDC_STATIC_SHAPE))->EnableWindow(FALSE);
((CStatic *) GetDlgItem(IDC_STATIC_HALFSIZE))->EnableWindow(FALSE);
}
RefreshHighlight();
}
void CCursorOptionsDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
highlightsize = ((CSliderCtrl *) GetDlgItem(IDC_HIGHLIGHTSIZE))->GetPos();
RefreshHighlight();
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
void CCursorOptionsDlg::RefreshHighlight()
{
CSize previewsize;
previewsize.cx=64;
previewsize.cy=64;
#if 0
int xoffset = 300;
int yoffset = 230;
#else
int xoffset = 340;
int yoffset = 215;
#endif
int highlightsizehalf = highlightsize/2;
double x1,x2,y1,y2;
//OffScreen Buffer
CDC* cdc= GetWindowDC();
HDC hdc= cdc->m_hDC;
HBITMAP hbm = NULL;
HBITMAP old_bitmap;
HDC hdcBits = ::CreateCompatibleDC(hdc);
hbm = (HBITMAP) ::CreateCompatibleBitmap(hdc,previewsize.cx,previewsize.cy);
old_bitmap = (HBITMAP) ::SelectObject(hdcBits,hbm);
if ((highlightshape == 0) || (highlightshape == 2)) { //circle and square
x1 = (previewsize.cx - highlightsizehalf)/2.0;
x2 = (previewsize.cx + highlightsizehalf)/2.0;
y1 = (previewsize.cy - highlightsizehalf)/2.0;
y2 = (previewsize.cy + highlightsizehalf)/2.0;
}
else if ((highlightshape == 1) || (highlightshape == 3)) { //ellipse and rectangle
x1 = (previewsize.cx - highlightsizehalf)/2.0;
x2 = (previewsize.cx + highlightsizehalf)/2.0;
y1 = (previewsize.cy - highlightsizehalf/2.0)/2.0;
y2 = (previewsize.cy + highlightsizehalf/2.0)/2.0;
}
HBRUSH ptbrush = (HBRUSH) ::GetStockObject(LTGRAY_BRUSH);
HPEN nullpen = CreatePen( PS_NULL,0,0);
HBRUSH hlbrush = CreateSolidBrush( highlightcolor);
HBRUSH oldbrush = (HBRUSH) ::SelectObject(hdcBits,ptbrush);
HPEN oldpen = (HPEN) ::SelectObject(hdcBits,nullpen);
::Rectangle(hdcBits, 0,0,previewsize.cx+1,previewsize.cy+1);
if (highlightcursor) { //draw the shape only if highlight cursor is selected
::SelectObject(hdcBits,hlbrush);
if ((highlightshape == 0) || (highlightshape == 1)) { //circle and ellipse
::Ellipse(hdcBits,(int) x1,(int) y1,(int) x2,(int) y2);
}
else if ((highlightshape == 2) || (highlightshape == 3)) { //square and rectangle
::Rectangle(hdcBits,(int) x1,(int) y1,(int) x2,(int) y2);
}
::SelectObject(hdcBits,oldbrush);
}
::SelectObject(hdcBits,oldpen);
DeleteObject(hlbrush);
DeleteObject(nullpen);
//OffScreen Buffer
BitBlt(hdc, xoffset, yoffset, previewsize.cx, previewsize.cy, hdcBits, 0, 0, SRCCOPY);
SelectObject(hdcBits, old_bitmap);
DeleteObject(hbm);
DeleteDC(hdcBits);
ReleaseDC(cdc);
}
void CCursorOptionsDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
RefreshHighlight();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -