
1. wxWidgets 설치는 아래를 참고하세요.
C++ GUI : wxWidgets 설치
Visual Studio 2022( Community 판) 기준으로 설치를 진행함.참고 : Visual Studio Community 다운로드 - https://visualstudio.microsoft.com/ko/vs/community/ Visual Studio Community | 최신 무료 버전 다운로드Windows, Android 및 iOS용
taekho.tistory.com
1. 로그인(Login) 구현하시 위해 LoginFrame을 별도로 만들어 습니다.
2. App.h 파일을 추가합니다.
#pragma once
#include <wx/wx.h>
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
3. App.cpp 파일을 추가합니다.
#include "App.h"
#include "LoginFrame.h"
wxIMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
LoginFrame* login = new LoginFrame();
SetTopWindow(login);
login->Show();
return true;
}
4. LoginFrame.h 파일을 추가합니다.
#pragma once
#include <wx/wx.h>
class LoginFrame : public wxFrame
{
public:
LoginFrame();
private:
wxTextCtrl* m_textCtrlId;
wxTextCtrl* m_textCtrlPw;
void OnLogin(wxCommandEvent& event);
bool CheckAuth(const wxString& id, const wxString& pw);
};
5. LoginFrame.cpp
#include "LoginFrame.h"
#include "MainFrame.h"
LoginFrame::LoginFrame()
: wxFrame(nullptr, wxID_ANY, "Login", wxDefaultPosition, wxSize(300, 200))
{
CentreOnScreen();
wxPanel* panel = new wxPanel(this);
new wxStaticText(panel, wxID_ANY, "ID", wxPoint(20, 20));
m_textCtrlId = new wxTextCtrl(panel, wxID_ANY, "", wxPoint(80, 20), wxSize(180, 25));
new wxStaticText(panel, wxID_ANY, "PW", wxPoint(20, 60));
m_textCtrlPw = new wxTextCtrl(panel, wxID_ANY, "", wxPoint(80, 60), wxSize(180, 25), wxTE_PASSWORD);
wxButton* btn = new wxButton(panel, wxID_ANY, "Login", wxPoint(80, 100));
btn->Bind(wxEVT_BUTTON, &LoginFrame::OnLogin, this);
}
void LoginFrame::OnLogin(wxCommandEvent& event)
{
wxString id = m_textCtrlId->GetValue();
wxString pw = m_textCtrlPw->GetValue();
if (CheckAuth(id, pw))
{
wxMessageBox("Login Success!");
MainFrame* mainFrame = new MainFrame();
wxTheApp->SetTopWindow(mainFrame);
mainFrame->Show(true);
Destroy();
}
else
{
wxMessageBox("Login Failed!");
}
}
bool LoginFrame::CheckAuth(const wxString& id, const wxString& pw)
{
return (id == "admin" && pw == "1234");
}
6. MainFrame.h 파일을 추가합니다.
#pragma once
#include <wx/wx.h>
class MainFrame : public wxFrame
{
public:
MainFrame();
};
7. MainFrame.cpp 파일을 추가합니다.
#include "MainFrame.h"
MainFrame::MainFrame()
: wxFrame(nullptr, wxID_ANY, "Main Frame", wxDefaultPosition, wxSize(600, 400))
{
CentreOnScreen();
wxPanel* panel = new wxPanel(this);
new wxStaticText(panel, wxID_ANY, "Welcome to Main System", wxPoint(20, 20));
}'C++ GUI' 카테고리의 다른 글
| C++ GUI : wxWidgets의 wxSimplebook/wxNotebook사용하기 (0) | 2026.06.01 |
|---|---|
| C++ GUI : wxWidgets에서 wxFTP 사용하기 (0) | 2026.05.18 |
| C++ GUI : Console에서 mariaDB ADO 사용하기 (0) | 2026.05.10 |
| C++ GUI : Console에서 mariaDB C/C++ Connector 사용하기 (0) | 2026.05.10 |
| C++ GUI : MFC에서 mariaDB ADO사용하기 (0) | 2026.05.10 |