클릭에 대한 간단한 응답이있는 단추가 포함 된 프레임 기반 MFC 응용 프로그램을 작성하려고했습니다. 불행히도 버튼이 내 행동에 반응하지 않는 것처럼 보입니다.
1) OS.cpp :단추 메시지 처리기를 설치하지 못했습니다.
#include "stdafx.h"
#include "mfc_includes.h" // some general includes like afxwin.h
#include "OS.h"
#include "MainFrm.h"
#include "button.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
BEGIN_MESSAGE_MAP(COSApp, CWinApp)
END_MESSAGE_MAP()
COSApp::COSApp() {}
COSApp theApp;
btnHelloWorld_t my_button;
BOOL COSApp::InitInstance()
{
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
CMainFrame* pFrame = new CMainFrame;
if (!pFrame)
return FALSE;
m_pMainWnd = pFrame;
pFrame->Create(L"", L"The application", WS_OVERLAPPEDWINDOW, CRect(100, 100, 500, 500));
my_button.Create(L"Hello World!", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(30, 30, 150, 80), pFrame, btnHelloWorld_t::GetID());
HFONT font = CreateFont(20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, L"Times New Roman");
SendMessage(my_button.m_hWnd, WM_SETFONT, (WPARAM)font, true);
pFrame->ShowWindow(SW_SHOW);
pFrame->UpdateWindow();
return TRUE;
}
2) OS.h :
class COSApp : public CWinApp
{
public:
virtual BOOL InitInstance();
afx_msg void OnAppAbout();
DECLARE_MESSAGE_MAP()
};
extern COSApp theApp;
3) button.h() 맞춤 버튼 클래스를 포함 :
여기서 응용 프로그램 코드는#pragma once
#include "mfc_includes.h"
class btnHelloWorld_t : public CButton
{
static const int is_button = 0x200;
static int id;
public:
btnHelloWorld_t()
{
id++;
};
static const int GetID()
{
return id;
};
afx_msg void Click();
DECLARE_MESSAGE_MAP()
};
int btnHelloWorld_t::id = 0x200;
afx_msg void btnHelloWorld_t::Click()
{
SetWindowText(L"Hello!");
}
BEGIN_MESSAGE_MAP(btnHelloWorld_t, CButton)
ON_BN_CLICKED(btnHelloWorld_t::GetID(), &btnHelloWorld_t::Click)
END_MESSAGE_MAP()
무엇이 잘못되었으며 클릭 한 후에 버튼이 텍스트를 변경하도록 할 수 있습니까? 미리 감사드립니다.
당신의 문제'btnHelloWorld_t :: GetID()'에 대한 당신의 문제는 당신이 당신이하고있는 일을하는 이유를 이해하지 못합니다 ...이 코드는 단지 재앙 일뿐입니다. –