如何将客户区的显示分辨率设置的和屏幕分辨率一样?

madlas 2003-12-31 07:15:54
默认的分辨率太低了,比如我要画条长度为1000的直线,就会画到客户区外面去.如何才能将客户区的显示分辨率设置的和屏幕分辨率一样?最好给出源代码.
...全文
51 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
howtotell 2003-12-31
  • 打赏
  • 举报
回复
// DialogExDlg.h : header file
//

#if !defined(AFX_DIALOGEXDLG_H__49B9DB6A_6B15_11D5_89BF_0080C82BC052__INCLUDED_)
#define AFX_DIALOGEXDLG_H__49B9DB6A_6B15_11D5_89BF_0080C82BC052__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <afxtempl.h>
/////////////////////////////////////////////////////////////////////////////
// CDialogExDlg dialog
typedef CMap<CString, LPCSTR, CRect, CRect&> CMapCStringToCRect;
typedef CList<CRect, CRect> CListRect;
typedef struct _SCREEN
{
int nScreenX;
int nScreenY;
}SCREEN;

class CDialogExDlg : public CDialog
{
// Construction
public:
CString GetCurDir();
CDialogExDlg(CWnd* pParent = NULL); // standard constructor

CMapCStringToCRect mapStrToRect;
CListRect listRect;
SCREEN screen;
// Dialog Data
//{{AFX_DATA(CDialogExDlg)
enum { IDD = IDD_DIALOGEX_DIALOG };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA

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

// Implementation
protected:
HICON m_hIcon;

// Generated message map functions
//{{AFX_MSG(CDialogExDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnDestroy();
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DIALOGEXDLG_H__49B9DB6A_6B15_11D5_89BF_0080C82BC052__INCLUDED_)
/////////////////////////////////////////////////////////////////////////////////




/////////////////////////////////////////////////////////////////////////////

BOOL CDialogExDlg::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

CRect rectWnd;
GetWindowRect(&rectWnd);
listRect.AddTail(&rectWnd);
CWnd *pWndChild = GetWindow(GW_CHILD);
while(pWndChild)
{
pWndChild->GetWindowRect(&rectWnd);
listRect.AddTail(&rectWnd);
pWndChild = pWndChild->GetNextWindow();
}
// screen.nScreenX=GetSystemMetrics(SM_CXSCREEN);
// screen.nScreenY=GetSystemMetrics(SM_CYSCREEN);

return TRUE; // return TRUE unless you set the focus to a control
}


void CDialogExDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);

// TODO: Add your message handler code here
int nCount=listRect.GetCount();
if(listRect.GetCount()>0)
{
CRect rectDlgNow;
GetWindowRect(&rectDlgNow);
POSITION mP = listRect.GetHeadPosition();
CRect rectDlgSaved;
rectDlgSaved = listRect.GetNext(mP);
ScreenToClient(rectDlgSaved);
ScreenToClient(rectDlgNow);
float fRateScaleX = (float)(rectDlgNow.right-rectDlgNow.left)/(rectDlgSaved.right-rectDlgSaved.left);
float fRateScaleY = (float)(rectDlgNow.bottom-rectDlgNow.top)/(rectDlgSaved.bottom-rectDlgSaved.top);
ClientToScreen(rectDlgSaved);
ClientToScreen(rectDlgNow);
LOGFONT stFont;
::GetObject((HFONT)GetStockObject(DEFAULT_GUI_FONT), sizeof(stFont), &stFont);
strcpy(stFont.lfFaceName,"Times New Roman");
stFont.lfHeight = (long)(fRateScaleY*14);
stFont.lfWidth = (long)(fRateScaleX*7);
CFont * m_pCFont;
m_pCFont = new CFont;
m_pCFont->CreateFontIndirect(&stFont);
CRect rectChildSaved;
CWnd *pWndChild = GetWindow(GW_CHILD);
while(pWndChild)
{
rectChildSaved = listRect.GetNext(mP);
rectChildSaved.left = rectDlgNow.left+(int)((rectChildSaved.left-rectDlgSaved.left)* fRateScaleX);
rectChildSaved.top = rectDlgNow.top+(int)((rectChildSaved.top-rectDlgSaved.top)*fRateScaleY);
rectChildSaved.right = rectDlgNow.right+(int)((rectChildSaved.right-rectDlgSaved.right)* fRateScaleX);
rectChildSaved.bottom = rectDlgNow.bottom+(int)((rectChildSaved.bottom-rectDlgSaved.bottom)* fRateScaleY);
ScreenToClient(rectChildSaved);
pWndChild->MoveWindow(rectChildSaved);
pWndChild->SetFont(m_pCFont);
pWndChild = pWndChild->GetNextWindow();
}
}
Invalidate();
}

broadoceans 2003-12-31
  • 打赏
  • 举报
回复
只能把系统默认分辨率改一下,
程序退出在改回去。

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧