gpt4 book ai didi

c++ - 坚持让 Windows.h 工作,在编译之前没有错误消息。

转载 作者:行者123 更新时间:2023-11-28 02:04:46 26 4
gpt4 key购买 nike

<分区>

所以我目前一直在尝试让 Windows api 显示出来(语言是 c++),当我尝试运行该程序时出现以下错误。 (虽然我现在收到关于红色下划线的错误)。我目前使用 visual studio community 作为我的 IDE。

“函数“int _cdel invoke(main(void))”中未解析的外部符号_main 引用

“1 个已解决的外部问题”

我已经在线检查过,并尝试将其作为 win 32 控制台程序和 win 32 项目(有些已将其列为解决该程序的方法。)但是没有结果。我不知道错误可能是什么。 (同样作为引用,我使用以下教程作为起始基础 https://www.youtube.com/watch?v=012pFrYE5_k,但我没有使用开放式 GL 库,因为我想要完成的只是制作一个非常简化的 win32 窗口模板)。有什么想法吗?

代码:main.h

#pragma once
#pragma once
#include<Windows.h>
#include<tchar.h>
#include<iostream>
#define WINDOW_WIDTH = 800 //remember to leave off the ; at the end of define sets(currently not being used
#define WINDOW_HEIGHT = 600
HWND hWnd;

代码:main.cpp

#include "main.h" //remember <> means library, "" means within your project. 
// long results, CALL BACK, windows procedure, basically the basics of what to do. UINT (unsigned INT)
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_CREATE:
break;
case WM_DESTROY:
case WM_QUIT:
case WM_CLOSE:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
/*
remember that this is a run time instance, and is in essence the same as Main (char[args]) {}
returning 0 ends the operation of the win32 library.
*/
int WINAPI winMain(HINSTANCE hInstance, HINSTANCE hPrevious, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS wc; //default instance for the scope of the window (new window named WC for WINDOW CLASS)
MSG msg;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH); //default background color, set to stock light gray
wc.hCursor = LoadCursor(hInstance, IDC_ARROW); //default cursor
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = _T("NAME");
wc.lpszMenuName = NULL;
wc.style = CS_VREDRAW | CS_HREDRAW; //windows style in bit form, 0X00 hex if you were to print them
if (!RegisterClass(&wc)) //pointer the to the window, if it doesn't exist call this simple error handle
{
MessageBox(NULL, _T("error: cannot reg window class"), _T("error"), MB_OK);
return 0; // kills
}
hWnd = CreateWindow(L"NAME", //reference of the object already defined as wc
L"Window Title", //title
WS_OVERLAPPEDWINDOW, //basic window style
0, //x start,
0, //y start,
800,
600, //set all the dimensions to default value
NULL, //no parent window
NULL, //no menu
hInstance,
NULL);
if (!hWnd)
{
MessageBox(NULL, L"ERROR: cannot create window", L"ERROR!", MB_OK);
return 0;
}
while (1)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
if (GetMessage(&msg, NULL, 0, 0))
{
break;
}
}
DispatchMessage(&msg);
TranslateMessage(&msg);
}
return(int)msg.wParam;
}

26 4 0
文章推荐: css - 编辑 CSS header 信息可将 Wordpress 网站恢复为默认设置
文章推荐: css - 始终将
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com