这是我所有的代码:
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
LRESULT CALLBACK WNDProc(HWND hwnd, UINT uMSG, WPARAM wparam, LPARAM lparam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR args, int ncmdshow) {
WNDCLASSEX wincls;
HWND first;
UINT last;
wincls.lpfnWndProc = WNDProc;
wincls.hInstance = hInstance;
wincls.lpszClassName = _T("ISSA_CLASS");
wincls.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
if (!RegisterClassEx(&wincls)) {
MessageBox(first, _T("Register failed"), _T("Yeah baby"), last);
return 1;
}
TCHAR szwincls[] = _T("win32app");
TCHAR title[] = _T("Neptune's Limit");
HWND hwnd = CreateWindow(szwincls, title, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 200, NULL, NULL, hInstance, NULL);
if (!hwnd) {
MessageBox(first, _T("Register failed"), _T("Yeah baby"), last);
return 1;
}
ShowWindow(hwnd, ncmdshow);
UpdateWindow(hwnd);
MSG message;
while (GetMessage(&message, NULL, 0, 0)) {
TranslateMessage(&message);
DispatchMessage(&message);
}
return (int) message.wParam;
}
LRESULT CALLBACK WNDProc(HWND hwnd, UINT uMSG, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
TCHAR greeting[] = _T("Hello, World!");
switch(uMSG) {
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
TextOut(hdc, 5, 5, greeting, _tcslen(greeting));
EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMSG, wParam, lParam);
break;
}
return 0;
}
在运行时的命令提示符下,这将生成“对TextOut @ 20的未定义引用”。我知道有人问过类似的问题,我确实读过答案,但是我不明白为什么我必须链接gdi库。这段代码几乎直接来自MSDN,并且它们使用TextOut(),它的工作原理很吸引人。另外,我正在尝试为该项目使用尽可能少的外部资源。我实际上是在Windows记事本中对此进行编码,然后在命令提示符下将其编译为可执行文件。为什么TextOut()不能在此代码中工作?看起来语法正确,但是我应该知道什么?我只是在学习这些东西。