举报

使用createwindow时发生错误

0

在mfc创建窗口函数处报错

HWND hwnd = CreateWindow(a.lpszClassName,a.lpszClassName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hinstance, NULL);

在上面的这句这里提示:0xc00000000:执行位置0xccccccc时发生错误

操作系统:win10、编译环境:vs2017空项目

#include<Windows.h>
//WINAPI参数的传递顺序
int WINAPI WinMain(
	HINSTANCE hinstance,//应用程序句柄
	HINSTANCE hprevinstance,//上一个应用程序句柄
	LPSTR ipcmdline, //char *argv[]命令行参数
	int nshowcmd)//显示命令
{ 
	//设计窗口。
	WNDCLASS a;
	a.cbClsExtra = 0;//类的额外内存
	a.cbWndExtra = 0;//窗口的额外内存
	a.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH);//设置光标
	a.hCursor = (HCURSOR)LoadCursor(NULL,IDC_HAND);
	a.hIcon=(HICON)LoadIcon(0,IDI_APPLICATION);
	a.hInstance=hinstance;
	//a.lpfnWndProc=;
	a.lpszClassName=TEXT("第一次喔");
	a.lpszMenuName=0;
	a.style=0;
	//注册
	RegisterClass(&a);
	//创建窗口
	HWND hwnd = CreateWindow(a.lpszClassName,a.lpszClassName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hinstance, NULL);
	//显示更新
	ShowWindow(hwnd, SW_SHOWNORMAL);
	UpdateWindow(hwnd);
	//通过循环获取消息
	MSG msg;
	while (1)
	{
		if(GetMessage(&msg, NULL,0,0)==false)
			break;
	}
	//翻译消息
	TranslateMessage(&msg);
	//分法消息
	DispatchMessage(&msg);
	//
	return 0;
}
C
ava
/*旧梦*/

2021-6-19

举报
0
#include<Windows.h>

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	switch (message)
	{
		case WM_PAINT:
			hdc = GetDC(hWnd);
			TextOutA(hdc, 100, 100, "hello", 5);
			ReleaseDC(hWnd, hdc);
			break;

		case WM_DESTROY:
			PostQuitMessage(0);
			break;

		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}



//WINAPI参数的传递顺序
int WINAPI WinMain(
	HINSTANCE hinstance,//应用程序句柄
	HINSTANCE hprevinstance,//上一个应用程序句柄
	LPSTR ipcmdline, //char *argv[]命令行参数
	int nshowcmd)//显示命令
{
	//设计窗口。
	TCHAR szWindowClass[] = TEXT("第一次喔");//The title bar text
	WNDCLASS a = {0};
	a.cbClsExtra = 0;//类的额外内存
	a.cbWndExtra = 0;//窗口的额外内存
	a.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);//设置光标
	a.hCursor = (HCURSOR)LoadCursor(NULL, IDC_HAND);
	a.hIcon = (HICON)LoadIcon(0, IDI_APPLICATION);
	a.hInstance = hinstance;
	a.lpfnWndProc = (WNDPROC)WndProc;//消息处理函数
	//a.lpszClassName = TEXT("第一次喔"); 这里仅是个地址 只有string 才能用等号,这里没有分配内存所以也不能用copy
	a.lpszClassName = szWindowClass;//
	a.lpszMenuName = 0;
	a.style = 0;
	//注册
	RegisterClass(&a);
	//创建窗口
	HWND hwnd = CreateWindow(a.lpszClassName, a.lpszClassName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hinstance, NULL);
	//显示更新
	ShowWindow(hwnd, SW_SHOWNORMAL);
	UpdateWindow(hwnd);
	//通过循环获取消息

	MSG msg;
	while (GetMessage(&msg, NULL, 0, 0))
	{
		if (!TranslateAccelerator(msg.hwnd, 0, &msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return (int)msg.wParam;
}
ava
#$@#$#$

2021-6-20

技术讨论社区