打包window平台,全屏后有很大黑边需要切换窗口才能实现真正全屏

找到ccc安装目录下的“cocos\platform\desktop\CCGLView-desktop.cpp”这个文件,
_mainWindow = glfwCreateWindow(screen_width, screen_height, name.c_str(), _monitor, nullptr);
修改为,(如图):
const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
int screen_width = mode->width;
int screen_height = mode->height;
// _mainWindow = glfwCreateWindow(1920, 1080, name.c_str(), glfwGetPrimaryMonitor(), nullptr);
_mainWindow = glfwCreateWindow(screen_width, screen_height, name.c_str(), glfwGetPrimaryMonitor(), nullptr);
// _mainWindow = glfwCreateWindow(screen_width, screen_height, name.c_str(), _monitor, nullptr);

修改项目文件“build\jsb-link\frameworks\runtime-src\proj.win32”里的main.cpp 文件
#include “main.h”
#include “AppDelegate.h”

USING_NS_CC;

// uncomment below line, open debug console
// #define USE_WIN32_CONSOLE

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

#ifdef USE_WIN32_CONSOLE
AllocConsole();
freopen(“CONIN$”, “r”, stdin);
freopen(“CONOUT$”, “w”, stdout);
freopen(“CONOUT$”, “w”, stderr);
#endif

// create the application instance
//by jd, get the real screen size in windows

//以下的cx,cy不通用,在设置了win10的屏幕缩放之后,下面2个参数是缩放之后的分辨率,不是原始的分辨率(物理宽度与高度)
//int  cx = GetSystemMetrics(SM_CXSCREEN);
//int  cy = GetSystemMetrics(SM_CYSCREEN);

HWND hWnd = GetDesktopWindow();
HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);

// 获取监视器逻辑宽度与高度
MONITORINFOEX miex;
miex.cbSize = sizeof(miex);
GetMonitorInfo(hMonitor, &miex);
int cxLogical = (miex.rcMonitor.right - miex.rcMonitor.left);
int cyLogical = (miex.rcMonitor.bottom - miex.rcMonitor.top);

// 获取监视器物理宽度与高度
DEVMODE dm;
dm.dmSize = sizeof(dm);
dm.dmDriverExtra = 0;
EnumDisplaySettings(miex.szDevice, ENUM_CURRENT_SETTINGS, &dm);
int cxPhysical = dm.dmPelsWidth;
int cyPhysical = dm.dmPelsHeight;

// 缩放比例计算  实际上使用任何一个即可
//double horzScale = ((double)cxPhysical / (double)cxLogical);
//double vertScale = ((double)cyPhysical / (double)cyLogical);

AppDelegate app(cxPhysical, cyPhysical);
app.start();

#ifdef USE_WIN32_CONSOLE
FreeConsole();
#endif

return 0;

}

1赞

这个main.cpp这样改编译不了,有解决方案吗