DEV Community

海前 王
海前 王

Posted on

mfc open console test

define _CRT_SECURE_NO_WARNINGS

include // MFC 核心和标准组件

include // 标准输入输出流

include // Windows API 函数

class CMyFrameWnd : public CFrameWnd {
public:
CMyFrameWnd() {
Create(NULL, _T("Key Event Handling Window"), WS_OVERLAPPEDWINDOW, CRect(0, 0, 300, 200));
}

protected:
// 处理按键事件
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) {
// 输出按键虚拟键码到控制台
std::cout << "Key Pressed: " << nChar << std::endl;

    // 调用基类的处理方法
    CFrameWnd::OnKeyDown(nChar, nRepCnt, nFlags);
}

DECLARE_MESSAGE_MAP()
Enter fullscreen mode Exit fullscreen mode

};

BEGIN_MESSAGE_MAP(CMyFrameWnd, CFrameWnd)
ON_WM_KEYDOWN()
END_MESSAGE_MAP()

class CMyApp : public CWinApp {
public:
virtual BOOL InitInstance() {
// 创建控制台窗口
AllocConsole();
freopen("CONOUT$", "w", stdout);
freopen("CONIN$", "r", stdin);
freopen("CONIN$", "r", stderr);

    CMyFrameWnd* pFrame = new CMyFrameWnd;
    m_pMainWnd = pFrame;

    pFrame->ShowWindow(SW_SHOW);
    pFrame->UpdateWindow();

    return TRUE;
}
Enter fullscreen mode Exit fullscreen mode

};

CMyApp theApp;

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay