다음 코드는 제대로 작동하지 않습니다. %i
은 변수와 연결되지 않습니다.형식이 지정된 MessageBox 내에서 숫자를 인쇄 할 수 없습니다.
#include<Windows.h>
#include<stdio.h>
#include<tchar.h>
/* SCREENSIZE.C
This project contains the code that Programming Windows
book by Charles Petzold is using.
*/
int cdecl MessageBoxPrintfW(TCHAR *msgBoxTitle, TCHAR *msgBoxFormat, ...)
{
//define buffer
TCHAR msgBoxBuffer[1024];
//define iteration pointer
va_list argPtr;
//start iteration
va_start(argPtr, msgBoxFormat);
/*int _vsnwprintf_s(
wchar_t *const _Buffer,
const size_t _BufferCount,
const size_t _MaxCount,
const wchar_t *const _Format,
va_list _ArgList)
*/
_vsntprintf_s(msgBoxBuffer, sizeof(msgBoxBuffer)/sizeof(TCHAR), (sizeof(msgBoxBuffer)/sizeof(TCHAR)) - 1, msgBoxFormat, argPtr);
//end iteration
va_end(argPtr);
//Use return type to pass preconfigured MessageBox(0,"Text","Title",MB_OKCANCEL);
//Whe we use L before a string example: L"text" it is considered UNICODE format.
return(MessageBox(0, msgBoxFormat, msgBoxTitle, MB_OKCANCEL));
}
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR pCmdLine,
int iCmdShow)
{
int cxScreen, cyScreen;
cxScreen = GetSystemMetrics(SM_CXSCREEN);
cyScreen = GetSystemMetrics(SM_CYSCREEN);
MessageBoxPrintfW(TEXT ("SCREENSIZE"), TEXT("The screen is %i pixels wide by %i pixels high."), cxScreen, cyScreen);
return(0);
}
왜 이런 일이 발생합니까? 다음은
내가 얻을 출력됩니다 : 당신이msgBoxBuffer
에을 writting된다
delete[]
의 사용버전
C
하십시오. –그리고 원하는 것은 무엇입니까? 당신은'msgBoxBuffer'를 사용하지 않고'msgBoxFormat'을 대신 표시합니다. – RbMm
편집을 도와 준 레미에게 감사드립니다. – strax