代码如下
/*本程序用来插入一张图片*/
#include
#pragma comment(lib,"msimg32.lib")
#define wnd_width 640 //窗口的宽
#define wnd_height 480 //窗口的高
HDC hdc; //窗口设备句柄
HDC memdc; //内存设备句柄
HDC bufmemdc; //内存设备句柄
HBITMAP bmp; //空位图
HBITMAP backbmp; //背景图片
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
switch(Message) {
case WM_PAINT:{
BitBlt(hdc,0,0,500,500,memdc,0,0,SRCCOPY);
break;
}
case WM_DESTROY: {
PostQuitMessage(0);
break;
}
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
WNDCLASSEX wc;
HWND hwnd;
MSG msg;
memset(&wc,0,sizeof(wc));
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszClassName = "WindowClass";
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc)) {
MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
return 0;
}
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Caption",WS_VISIBLE|WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
wnd_width,
wnd_height,
NULL,NULL,hInstance,NULL);
if(hwnd == NULL) {
MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
return 0;
}
hdc = GetDC(hwnd);
bufmemdc = CreateCompatibleDC(hdc);
memdc = CreateCompatibleDC(hdc);
bmp = CreateCompatibleBitmap(hdc,wnd_width,wnd_height);
backbmp = (HBITMAP)LoadImage(NULL,"./picture/n.bmp",IMAGE_BITMAP,500,500,LR_LOADFROMFILE);
SelectObject(memdc,bmp);
SelectObject(bufmemdc,backbmp);
TransparentBlt(memdc,0,0,500,500,bufmemdc,0,0,500,500,RGB(0,0,5));
while(GetMessage(&msg, NULL, 0, 0) > 0) { /* If no error is received... */
TranslateMessage(&msg); /* Translate key codes to chars if present */
DispatchMessage(&msg); /* Send it to WndProc */
}
return msg.wParam;
}
然后编译运行的时候,页面就跳转到MakeFile
Project: 插入图片
Makefile created by Dev-C++ 5.9.2
CPP = g++.exe
CC = gcc.exe
WINDRES = windres.exe
OBJ = main.o
LINKOBJ = main.o
LIBS = -L"D:/devc++/dev-cpp_gr/dev-cpp_gr/Dev-Cpp/MinGW64/lib" -L"D:/devc++/dev-cpp_gr/dev-cpp_gr/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib" -static-libgcc -mwindows
INCS = -I"D:/devc++/dev-cpp_gr/dev-cpp_gr/Dev-Cpp/MinGW64/include" -I"D:/devc++/dev-cpp_gr/dev-cpp_gr/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"D:/devc++/dev-cpp_gr/dev-cpp_gr/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.8.1/include"
CXXINCS = -I"D:/devc++/dev-cpp_gr/dev-cpp_gr/Dev-Cpp/MinGW64/include" -I"D:/devc++/dev-cpp_gr/dev-cpp_gr/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"D:/devc++/dev-cpp_gr/dev-cpp_gr/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.8.1/include" -I"D:/devc++/dev-cpp_gr/dev-cpp_gr/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.8.1/include/c++"
BIN = 插入图片.exe
CXXFLAGS = $(CXXINCS)
CFLAGS = $(INCS)
RM = rm.exe -f
.PHONY: all all-before all-after clean clean-custom
all: all-before $(BIN) all-after
clean: clean-custom
${RM} $(OBJ) $(BIN)
$(BIN): $(OBJ)
$(CC) $(LINKOBJ) -o $(BIN) $(LIBS)
main.o: main.c
$(CC) -c main.c -o main.o $(CFLAGS)
出现了如下的报错信息:
D:\dev-c++文档\插入图片\main.o main.c:(.text+0x39b): undefined reference to `__imp_TransparentBlt'
D:\dev-c++文档\插入图片\collect2.exe [Error] ld returned 1 exit status
25
D:\dev-c++文档\插入图片\Makefile.win recipe for target '插入图片.exe' failed
求助是什么原因,怎么解决