向高手提问……

Learn-anything 2008-04-29 12:09:02
1、你有没有遇到过类似下面的这个链接错误?如果遇到过,简单说说它是怎么回事,你又是怎么解决的?
error LNK2019: 无法解析的外部符号 _function1,该符号在函数 _ function2中被引用


2、使用Win32(不用MFC或其他框架),写一个窗口程序,实现下列功能:
(1),窗口启动时最大化
(2),窗口的背景为蓝色
(3),当鼠标在窗口上移动时,在窗口的左上角显示鼠标相对于窗口客户区左上角的坐标
(4),从Cards.dll中加载一张扑克牌,最初显示在窗口的中间(提示: Cards.dll在系统盘下的Windows\system32下可以找到),按下上下左右键后,这张 扑克可以在窗口内上下左右移动,每按一次,移动一个像素。并且保证这张扑克不会移动到窗口外面去。




请高手做下这两题,非常感谢……
...全文
132 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
薛定谔之死猫 2008-04-29
  • 打赏
  • 举报
回复
1.添加函数的源代码参与编译,或者添加包含函数代码的lib,或者包含函数dll实现描述的lib
2.很多sdk的示例程序就做这样的实例,加载扑克牌主要训练使用资源dll,找找相关例子程序
  • 打赏
  • 举报
回复
1 增加函数实现,或者lib
2 自动生成的向导已经由了大部分的功能.
星羽 2008-04-29
  • 打赏
  • 举报
回复

2)建个win32工程

// win32.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "resource.h"

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name

// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);

HBITMAP g_hImage = 0;
POINT g_cards;
HWND hWnd;

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;

// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_WIN32, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WIN32));

HMODULE handel = LoadLibrary(TEXT("Cards.dll"));
g_hImage = LoadBitmap(handel, MAKEINTRESOURCE(52));

RECT rect;
GetClientRect(hWnd, &rect);
g_cards.x = rect.right / 2 - 50;
g_cards.y = rect.bottom / 2 - 100;

InvalidateRect(hWnd, NULL, TRUE);

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return (int) msg.wParam;
}



//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage are only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WIN32));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)CreateSolidBrush(RGB(0, 0, 255));
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_WIN32);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

return RegisterClassEx(&wcex);
}

//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}

ShowWindow(hWnd, SW_MAXIMIZE);
UpdateWindow(hWnd);

return TRUE;
}

//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//

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

switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
{
POINT pt;
GetCursorPos(&pt);
ScreenToClient(hWnd, &pt);
TCHAR str[128];
_stprintf(str, TEXT("x = %d, y = %d"), pt.x, pt.y);
SetBkColor(hdc, RGB(0, 0, 255));
SetTextColor(hdc, RGB(255, 255, 255));
TextOut(hdc, 10, 10, str, _tcslen(str));

HDC hcdc = CreateCompatibleDC(hdc);
HGDIOBJ hSave = SelectObject(hcdc, g_hImage);
BitBlt(hdc, g_cards.x, g_cards.y, 100, 100, hcdc, 0, 0, SRCCOPY);
SelectObject(hcdc, hSave);
ReleaseDC(hWnd, hcdc);

}
EndPaint(hWnd, &ps);
break;

case WM_MOUSEMOVE :
{
RECT rect = {0, 0, 200, 100};
InvalidateRect(hWnd, &rect, TRUE);
}
break;

case WM_KEYDOWN :
{
RECT rect = {g_cards.x - 10, g_cards.y -10, g_cards.x + 100, g_cards.y + 200};

switch (wParam)
{
case VK_LEFT :
--g_cards.x;
break;
case VK_RIGHT :
++g_cards.x;
break;
case VK_UP :
--g_cards.y;
break;
case VK_DOWN :
++g_cards.y;
break;
}

InvalidateRect(hWnd, &rect, TRUE);

}

break;

case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}



星羽 2008-04-29
  • 打赏
  • 举报
回复

1) .确保xxxx.lib能正确的链接到工程中.

64,683

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧