24,854
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <iostream>
#include <windows.h>
using namespace std;
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
WINBASEAPI HWND WINAPI GetConsoleWindow();
#ifdef __cplusplus
}
#endif // __cplusplus
int main(int argc, char *argv[])
{
cout << "Hello, " << argv[0] << "." << endl;
HWND hWnd = GetConsoleWindow();
char windowClassName[256];
GetClassNameA(hWnd, windowClassName, sizeof(windowClassName) - 1);
cout << "class name: " << windowClassName << endl;
WNDCLASS windowClass;
HINSTANCE hInst;
hInst = (HINSTANCE)GetModuleHandle(NULL);
cout << "instance handle: " << hInst << endl;
BOOL success = GetClassInfo(hInst, (LPWSTR)windowClassName, &windowClass);
if (!success)
{
HRESULT errCode = GetLastError(); // the error code will be 0x583 that means "ERROR_CLASS_DOES_NOT_EXIST"
cout << "error when getting class information: " << errCode << endl;
void *errMsgBuf;
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, errCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)(&errMsgBuf), 0, NULL);
cout << (LPSTR)(errMsgBuf) << endl;
LocalFree(errMsgBuf);
system("pause");
return -1;
}
cout << "class name: " << windowClass.lpszClassName << endl;
cout << "menu name: " << windowClass.lpszMenuName << endl;
return 0;
}