Windows编程——在消息框中显示屏幕的像素大小 布满荆棘的人生 2021-06-24 15:58 277阅读 0赞 可以显示当前屏幕的大小,单位为像素. 效果图: ![效果示意图][aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTgwMTA2MTUzNDE2MDMw] /*---------------------------------------------------------------------------- Displays screen size in a message box ----------------------------------------------------------------------------*/ #include<Windows.h> #include<tchar.h> #include<stdio.h> int CDECL MessageBoxPrintf(TCHAR * szCaption, TCHAR * szFormat, ...) { TCHAR szBuffer[1024]; va_list pArgList; //the va_start mavro (defined in STDARG.H) is usually equivalent to: //pArgList = (char *) &szFormat + sizeof (szFormat); va_start(pArgList, szFormat); //thr last argument to wvsprintf points to the arguments _vsnprintf(szBuffer, sizeof(szBuffer) / sizeof(TCHAR),szFormat,pArgList); //the va_end macro just zeroes out aArgList for no good reason va_end(pArgList); return MessageBox(NULL, szBuffer, szCaption, 0); } int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { int cxScreen, cyScreen; cxScreen = GetSystemMetrics(SM_CXSCREEN); cyScreen = GetSystemMetrics(SM_CYSCREEN); MessageBoxPrintf( TEXT ("ScrnSize"), TEXT ("The screen is %i pixels wide by %i pisels high."), cxScreen, cyScreen); return 0; } [aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTgwMTA2MTUzNDE2MDMw]: /images/20210615/ec6c6c22dc394010a419c2d24fcfd685.png
还没有评论,来说两句吧...