gpt4 book ai didi

c++ - 在没有项目的情况下使用Dev c++在窗口中绘制文本

转载 作者:行者123 更新时间:2023-11-28 08:01:39 25 4
gpt4 key购买 nike

我想在窗口中绘制文本。当我在一个项目中使用这个文件时,它运行良好,没有任何错误,当我单独运行它时,它显示以下错误。要求是仅使用 windows.h 和 .cpp 格式编译文件。

[Linker error] undefined reference to `TextOutA@20' 
ld returned 1 exit status

网上搜了一下,都说要加gdi32 lib。但这只是添加到项目中。我想知道是否有人可以提供帮助。

#include <windows.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("My Window") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
//wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.hbrBackground = (HBRUSH) COLOR_WINDOW+0;//DISPLAYS GREY BACKGROUND OF CLIENT AREA
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("Window not Registered"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, // window class name
TEXT ("abcd"), // window caption
WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
400,300,
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
HRGN bgRgn;
HBRUSH hBrush;
HPEN hPen;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
GetClientRect (hwnd, &rect) ;
TextOut(hdc, 50, 42, "Johnny Carson", 13);
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}

最佳答案

i searched online, everyone says to add gdi32 lib. but that is only added to a project. i wonder if someone can help on this.

您需要链接到 gdi32.lib,这是您尝试调用的代码所在的位置。它与“项目”无关,“项目”是 IDE 使用的术语,仅用作管理代码的模型。

您要求链接器链接函数调用的代码,但您不想告诉链接器该代码所在的位置。好吧,链接器获胜。

关于c++ - 在没有项目的情况下使用Dev c++在窗口中绘制文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11298052/

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