MFC 适配DPI (win7系统 + vs2015)

zlxi 2020-01-15 06:30:31
在win7下开发的程序,移动2k,3K屏幕上,字体变小,BITMAP 图像也缩小了。根据dpi修改字体大小,和加载不一样的图像
...全文
537 8 打赏 收藏 举报
写回复
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zgl7903 2020-02-06
  • 打赏
  • 举报
回复
zlxi 2020-01-19
引用 6 楼 zgl7903 的回复:
试一试修改窗口的字体大小来适配 LOGFONT 中有这样的说明 For the MM_TEXT mapping mode, you can use the following formula to specify a height for a font with a given point size: lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
请教 PointSize 这个是什么值,该如何获取
  • 打赏
  • 举报
回复
zgl7903 2020-01-18
试一试修改窗口的字体大小来适配 LOGFONT 中有这样的说明 For the MM_TEXT mapping mode, you can use the following formula to specify a height for a font with a given point size: lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
  • 打赏
  • 举报
回复
schlafenhamster 2020-01-16

// Codes are shown here for reading ! not tested !
void CVcDispResDlg::ChangeResolution()
{
if(!m_bAllowToChange) return;
//
LPCTSTR psz;
UINT nMBBtn;
// Keep the current refresh rate
m_DevSelect.dmDisplayFrequency = GetDeviceCaps((HDC)GetDC(), VREFRESH);
// Attempt to change the display resolution.
switch (ChangeDisplaySettings(&m_DevSelect, CDS_UPDATEREGISTRY))
{
case DISP_CHANGE_SUCCESSFUL:
psz = __TEXT("Display change successful.");
break;

case DISP_CHANGE_RESTART:
psz = __TEXT("You must restart your computer before the ")
__TEXT("new settings will take effect.\n\n")
__TEXT("Do you want to restart your computer now?");
nMBBtn = MB_YESNO;
break;

case DISP_CHANGE_BADFLAGS:
psz = __TEXT("An invalid set of flags was passed in.");
break;

case DISP_CHANGE_FAILED:
psz =__TEXT("The display driver couldn't change the display.");
break;

case DISP_CHANGE_BADMODE:
psz = __TEXT("Invalid settings.");
break;

case DISP_CHANGE_NOTUPDATED:
psz = __TEXT("Unable to write settings to the registry.");
break;
}
// Show the user the results
if (IDYES == AfxMessageBox( psz, nMBBtn | MB_ICONINFORMATION))
{ // If the user wants to reboot the computer, do so.
// Windows NT: We must enable our shutdown privilege,assumming we have it.
// Windows 95: OpenProcessToken, LookupPrivilegeValue, and
// AdjustTokenPrivileges are not implemented and
// are ignored.
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// We want to adjust our process's privileges.
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken);
// Get the LUID for shutdown privilege
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Turn the SE_SHUTDOWN_NAME privilege on for our process
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, 0);
CloseHandle(hToken);
// Shut down and reboot the system.
ExitWindowsEx(EWX_REBOOT, 0);
}
}

DEVMODE
The DEVMODE data structure contains information about the device initialization and environment of a printer.

typedef struct _devicemode { // dvmd
BCHAR dmDeviceName[CCHDEVICENAME];
WORD dmSpecVersion;
WORD dmDriverVersion;
WORD dmSize;
WORD dmDriverExtra;
DWORD dmFields;
union {
struct {
short dmOrientation;
short dmPaperSize;
short dmPaperLength;
short dmPaperWidth;
};
POINTL dmPosition;
};
short dmScale;
short dmCopies;
short dmDefaultSource;
short dmPrintQuality;
short dmColor;
short dmDuplex;
short dmYResolution;
short dmTTOption;
short dmCollate;
BCHAR dmFormName[CCHFORMNAME];
WORD dmLogPixels;
DWORD dmBitsPerPel;
DWORD dmPelsWidth;
DWORD dmPelsHeight;
DWORD dmDisplayFlags;
DWORD dmDisplayFrequency;
#if(WINVER >= 0x0400)
DWORD dmICMMethod;
DWORD dmICMIntent;
DWORD dmMediaType;
DWORD dmDitherType;
DWORD dmReserved1;
DWORD dmReserved2;
#if (WINVER >= 0x0500) || (_WIN32_WINNT >= 0x0400)
DWORD dmPanningWidth;
DWORD dmPanningHeight;
#endif
#endif /* WINVER >= 0x0400 */
} DEVMODE;

DEVMODE m_DevSelect;
  • 打赏
  • 举报
回复
zlxi 2020-01-16
引用 1 楼 zgl7903 的回复:
Setting the default DPI awareness for a process
https://bbs.csdn.net/topics/40373091 这里有讲一个,没看明白 ,大神能否帮忙解释一下
  • 打赏
  • 举报
回复
zlxi 2020-01-16
引用 3 楼 schlafenhamster 的回复:

// Codes are shown here for reading ! not tested !
void CVcDispResDlg::ChangeResolution()
{
	if(!m_bAllowToChange) return;
//
	LPCTSTR psz;
	UINT nMBBtn;
	// Keep the current refresh rate
	m_DevSelect.dmDisplayFrequency = GetDeviceCaps((HDC)GetDC(), VREFRESH);
	// Attempt to change the display resolution.
	switch (ChangeDisplaySettings(&m_DevSelect, CDS_UPDATEREGISTRY))
	{
	case DISP_CHANGE_SUCCESSFUL:
		psz = __TEXT("Display change successful."); 
		break;
		
	case DISP_CHANGE_RESTART:
		psz = __TEXT("You must restart your computer before the ")
			  __TEXT("new settings will take effect.\n\n")
			  __TEXT("Do you want to restart your computer now?"); 
		nMBBtn = MB_YESNO; 
		break;
		
	case DISP_CHANGE_BADFLAGS:
		psz = __TEXT("An invalid set of flags was passed in."); 
		break;
		
	case DISP_CHANGE_FAILED:
		psz =__TEXT("The display driver couldn't change the display.");
		break;
		
	case DISP_CHANGE_BADMODE:
		psz = __TEXT("Invalid settings."); 
		break;
		
	case DISP_CHANGE_NOTUPDATED:
		psz = __TEXT("Unable to write settings to the registry."); 
		break;
	}
	// Show the user the results
	if (IDYES == AfxMessageBox( psz, nMBBtn | MB_ICONINFORMATION))
	{   // If the user wants to reboot the computer, do so.
        // Windows NT: We must enable our shutdown privilege,assumming we have it.
        // Windows 95: OpenProcessToken, LookupPrivilegeValue, and 
        //             AdjustTokenPrivileges are not implemented and
        //             are ignored.
        HANDLE hToken;
        TOKEN_PRIVILEGES tkp;
        // We want to adjust our process's privileges.
        OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken);
        // Get the LUID for shutdown privilege
        LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
        tkp.PrivilegeCount = 1;  // one privilege to set
        tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
        // Turn the SE_SHUTDOWN_NAME privilege on for our process
        AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, 0);
        CloseHandle(hToken);
        // Shut down and reboot the system.
        ExitWindowsEx(EWX_REBOOT, 0);
	}
}
DEVMODE The DEVMODE data structure contains information about the device initialization and environment of a printer. typedef struct _devicemode { // dvmd BCHAR dmDeviceName[CCHDEVICENAME]; WORD dmSpecVersion; WORD dmDriverVersion; WORD dmSize; WORD dmDriverExtra; DWORD dmFields; union { struct { short dmOrientation; short dmPaperSize; short dmPaperLength; short dmPaperWidth; }; POINTL dmPosition; }; short dmScale; short dmCopies; short dmDefaultSource; short dmPrintQuality; short dmColor; short dmDuplex; short dmYResolution; short dmTTOption; short dmCollate; BCHAR dmFormName[CCHFORMNAME]; WORD dmLogPixels; DWORD dmBitsPerPel; DWORD dmPelsWidth; DWORD dmPelsHeight; DWORD dmDisplayFlags; DWORD dmDisplayFrequency; #if(WINVER >= 0x0400) DWORD dmICMMethod; DWORD dmICMIntent; DWORD dmMediaType; DWORD dmDitherType; DWORD dmReserved1; DWORD dmReserved2; #if (WINVER >= 0x0500) || (_WIN32_WINNT >= 0x0400) DWORD dmPanningWidth; DWORD dmPanningHeight; #endif #endif /* WINVER >= 0x0400 */ } DEVMODE; DEVMODE m_DevSelect;
麻烦描述一下,看功能好像修改屏幕分辨率。 不能修改屏幕分辨率
  • 打赏
  • 举报
回复
zlxi 2020-01-15
引用 1 楼 zgl7903 的回复:
Setting the default DPI awareness for a process
win8 系统以上才行,win7 系统没有相关接口
  • 打赏
  • 举报
回复
zgl7903 2020-01-15
相关推荐
发帖
界面
加入

1.5w+

社区成员

VC/MFC 界面
申请成为版主
帖子事件
创建了帖子
2020-01-15 06:30
社区公告
暂无公告