gpt4 book ai didi

c - 为什么 RegisterClassEx 失败

转载 作者:太空宇宙 更新时间:2023-11-04 08:43:32 24 4
gpt4 key购买 nike

我正在用下面的代码创建一个窗口

int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow){
MSG messages;
WNDCLASSEX wc;
DWORD dwrd;

InitCommonControls();

//The Window structure
wc.hInstance = hThisInstance;
wc.lpszClassName = szClassName;
wc.lpfnWndProc = WindowProcedure;
wc.style = CS_DBLCLKS;
wc.cbSize = sizeof(WNDCLASSEX);

wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); //if I comment it RegisterClassEx(&wc) fails with error: ERROR_INVALID_PARAMETER
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.lpszMenuName = 0;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;

wc.hbrBackground = CreateSolidBrush(RGB(230, 225, 208)); //(HBRUSH)(COLOR_3DFACE + 1);

//Register the window class, and if it fails quit the program
if(!RegisterClassEx(&wc)){
dwrd = GetLastError();

printf("Error in Function = WinMain() at line = %d, with error code = %X \n", __LINE__ - 3, (unsigned int)dwrd);

exit(EXIT_FAILURE);
}

//more code
}

当我注释掉该行时

wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

RegisterClassEx(&wc) 失败并出现错误:ERROR_INVALID_PARAMETER

谢谢

最佳答案

当您注释掉该行时,wc.hIconSm 字段不会被初始化并且可能包含垃圾值。 RegisterClassEx() 恰好注意到这一点并提示。

关于c - 为什么 RegisterClassEx 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22572429/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com