c++ - 如何制作toggle child?
问题描述
我创建了一个登录框架,它可以根据登录成功、孩子更改等情况像往常一样切换。并注销。但我的切换卡在这个过程中。登录->注销->登录。第二次登录后。孩子不想改回注销。它卡住了。我检查了几次并尝试了所有的东西,比如添加 UpdateWindow、SetWindowPos
#define LOGIN_BTN 1
#define LOGOUT_BTN 2
class CMainFrame: public CFrameWnd
{
public:
CMainFrame()
{
Create(
NULL,
"Learn MFC",
WS_OVERLAPPEDWINDOW,
CRect(CPoint(100, 100), CSize(640, 360)));
};
protected:
afx_msg int OnCreate(LPCREATESTRUCT);
afx_msg void login();
afx_msg void logout();
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
ON_COMMAND(LOGIN_BTN, &CMainFrame::login)
ON_COMMAND(LOGOUT_BTN, &CMainFrame::logout)
END_MESSAGE_MAP()
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
CButton* loginBtn = new CButton();
loginBtn->Create(
"Login",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
CRect(CPoint(100, 60), CSize(150, 25)),
this, LOGIN_BTN);
return 0;
};
void CMainFrame::login()
{
std::string resServer = "token";
if(resServer == "token")
{
// Destroy all childs window
while(GetWindow(GW_CHILD))
{
CWnd* pChild = GetWindow(GW_CHILD);
pChild->DestroyWindow();
}
CButton* logoutBtn = new CButton;
logoutBtn->Create(
"Logout",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
CRect(CPoint(100, 60), CSize(150, 25)),
this, LOGOUT_BTN);
};
}
void CMainFrame::logout()
{
CButton* loginBtn = new CButton();
loginBtn->Create(
"Login",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
CRect(CPoint(100, 60), CSize(150, 25)),
this, LOGIN_BTN);
};
class CApplication : public CWinApp {
BOOL InitInstance() {
CMainFrame* mainWnd = new CMainFrame();
m_pMainWnd = mainWnd;
mainWnd->ShowWindow(SW_NORMAL);
mainWnd->UpdateWindow();
return TRUE;
}
};
CApplication app;
解决方案
推荐阅读
- powerbi - 计算层次结构中总计的百分比
- c# - 如何在 .Net Core 2.2 中正确使用 ConfigurationManager.GetSection()
- google-maps - 我如何从谷歌地图的地方 api 对象中获取纬度和经度?
- python - Cython 的 language_level 3 和 3str 有什么区别?
- python - MultiIndex DataFrame:如何根据其他列中的值创建新列?
- bash - 意外令牌完成 bash 脚本附近的语法错误
- rest - 无法使用 invoke-webrequest/restmethod 从共享点检索正确的错误
- java - 使用带有多个 ClassLoader 的 Hibernate/JPA 访问多个数据库
- sql - Sql 查询返回最大计数 1 如果值为 0 或 -1 否则取最大计数
- jquery - 如何显示我的 for 循环的每个结果