我对Win32 API中的GetWindowTextA()
函数有一些理解上的问题。
根据微软文档,nMaxCount
是要复制到缓冲区lpString
中的最大字符数,包括空字符。
那么,GetWindowTextA()
函数是否会自动将空字符写入缓冲区lpString
中,还是我需要手动将空字符添加到lpString
中呢?
以下是来自微软文档的GetWindowTextA()
定义:
int GetWindowTextA(
[in] HWND hWnd,
[out] LPSTR lpString,
[in] int nMaxCount
);
这里是代码:
char M_Buff[20];
SetWindowTextA(M_SEND_EDIT_TEXT,"Hello World");
GetWindowTextA(M_SEND_EDIT_TEXT,M_Buff,20); //Do i have to add the null termination caracter into M_Buff myself or it is put automatically ?
printf("String is %s\n",M_Buff);
NULL
(或nullptr
)仅应用于指针,而不是字符。要指定空字符,通常会写成'\0'
。 - Andreas Wenzel