C++ 메뉴로 메모장을 개발하려고합니다. 코드는 다음과 같습니다.C++에서 메모장 개발
#include <windows.h>
#define IDI_APP_ICON 1
#define IDD_ABOUT 100
#define IDC_STATIC 101
#define IDM_MAINMENU 200
#define IDM_FILE_NEW 201
#define IDM_FILE_OPEN 203
#define IDM_FILE_SAVE 204
#define IDM_FILE_EXIT 205
#define IDM_HELP_ABOUT 206
class MainWindow
{
public:
MainWindow(HINSTANCE hInstance);
~MainWindow();
static LRESULT CALLBACK MainWndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
static void OnCommand(HWND hwnd, int id, HWND hCtl, UINT codeNotify);
bool Run(int nCmdShow);
private:
WNDCLASSEX m_wndClass;
static HINSTANCE m_hInstance;
HWND m_hwnd;
static char m_szClassName[];
};
class AboutDialog
{
public:
AboutDialog();
~AboutDialog();
static BOOL CALLBACK DialogProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
int Run(HINSTANCE hInstance, HWND hParent);
private:
HWND m_hwnd;
};
AboutDialog::AboutDialog()
{
}
AboutDialog::~AboutDialog()
{
}
// Function: Run
// Returns: Result of the DialogBox
int AboutDialog::Run(HINSTANCE hInstance, HWND hParent)
{
int retval = DialogBox(
hInstance,
MAKEINTRESOURCE(IDD_ABOUT), // Dialog template
hParent, // Pointer to parent hwnd
DialogProc);
}
BOOL CALLBACK
AboutDialog::DialogProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
int retVal = false;
switch(msg)
{
case WM_INITDIALOG:
retVal = true;
break;
case WM_COMMAND:
if(LOWORD(wParam)== IDOK)
EndDialog(hwnd, TRUE);
break;
case WM_CLOSE:
EndDialog(hwnd, TRUE);
break;
}
return retVal;
}
char MainWindow::m_szClassName[] = "DrawLite";
HINSTANCE MainWindow::m_hInstance = NULL;
MainWindow::MainWindow(HINSTANCE hInstance)
{
m_hInstance = hInstance; // Save Instance handle
m_wndClass.cbSize = sizeof(WNDCLASSEX); // Must always be sizeof(WNDCLASSEX)
m_wndClass.style = CS_DBLCLKS; // Class styles
m_wndClass.lpfnWndProc = MainWndProc; // Pointer to callback procedure
m_wndClass.cbClsExtra = 0;
m_wndClass.cbWndExtra = 0;
m_wndClass.hInstance = hInstance;
m_wndClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APP_ICON));
m_wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
m_wndClass.hbrBackground = (HBRUSH) (COLOR_WINDOW);
m_wndClass.lpszMenuName = MAKEINTRESOURCE(IDM_MAINMENU);
m_wndClass.lpszClassName = m_szClassName;
m_wndClass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APP_ICON));
}
MainWindow::~MainWindow()
{
}
LRESULT CALLBACK MainWindow::MainWndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_DESTROY:
PostQuitMessage (0);
break;
case WM_COMMAND:
//HANDLE_WM_COMMAND(hwnd, wParam, lParam, OnCommand);
break;
default:
return DefWindowProc (hwnd, msg, wParam, lParam);
}
return 0;
}
void MainWindow::OnCommand(HWND hwnd, int id, HWND hCtl, UINT codeNotify)
{
switch(id)
{
case IDM_FILE_EXIT:
PostQuitMessage(0);
break;
case IDM_HELP_ABOUT:
AboutDialog* dlg = new AboutDialog();
dlg->Run(m_hInstance, hwnd);
delete dlg; dlg = NULL;
break;
}
}
bool MainWindow::Run(int nCmdShow)
{
if(!RegisterClassEx(&m_wndClass))
return false;
m_hwnd = CreateWindowEx(
0,
m_szClassName,
"Draw Lite",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
500,
400,
NULL,
NULL,
m_hInstance,
NULL
);
if(!m_hwnd)
return false;
ShowWindow(m_hwnd, nCmdShow);
return true;
}
int WINAPI
WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
MainWindow *winMain = new MainWindow(hInst);
if(!winMain->Run(nCmdShow))
{
delete winMain;
return 1; // error
}
// Run the message loop. It will run until GetMessage() returns 0
while (GetMessage (&msg, NULL, 0, 0))
{
// Translate virtual-key messages into character messages
TranslateMessage(&msg);
// Send message to WindowProcedure
DispatchMessage(&msg);
}
delete winMain;
return msg.wParam;
}
링커 오류가 발생하여이 필드에서 아주 새로운 부분을 수정하는 방법을 모르겠습니다. 나는 누군가가 이것에 관해 나를 도울 수 있는지 궁금하게 생각한다. 덕분에,
이
내가[Linker error] undefined reference to [email protected]'
무엇입니까 오류이며,이뿐만 아니라
[Linker error] undefined reference to [email protected]'
아시프
오류가 무엇인지 말해야합니다. –
링커 오류, 컴파일 명령 등을 게시하십시오. 우리는 당신이 그것 없이는 당신을 도울 수 없습니다. – Linuxios
이것은 [_ZN11AboutDialog10DialogProcEP6HWND__jjl @ 16 '에 대한 링커 오류] 정의되지 않은 참조이고, 이것 또한 [_ZN11AboutDialog10Dialog10DialogProcEP6HWND__jjl @ 16' –