本人学的是wxWidgets,就以它为例了。
#include <wx/app.h>
#include <wx/image.h>
#include <wx/msgdlg.h>
#include <wx/string.h>
#include <wx/intl.h>
#include <wx/menu.h>
#include <wx/statusbr.h>
#include <wx/frame.h>
//*)
class SampleApp : public wxApp
{
public:
virtual bool OnInit()
}
IMPLEMENT_APP(SampleApp)
bool SampleApp::OnInit()
{
//(*AppInitialize
bool wxsOK = true
wxInitAllImageHandlers()
if ( wxsOK )
{
SampleFrame* Frame = new SampleFrame(0)
Frame->Show()
SetTopWindow(Frame)
}
return wxsOK
}
class SampleFrame: public wxFrame
{
public:
SampleFrame(wxWindow* parent,wxWindowID id = -1)
virtual ~SampleFrame()
private:
//(*Handlers(SampleFrame)
void OnQuit(wxCommandEvent&event)
void OnAbout(wxCommandEvent&event)
//*)
//(*Identifiers(SampleFrame)
static const long idMenuQuit
static const long idMenuAbout
static const long ID_STATUSBAR1
//*)
//(*Declarations(SampleFrame)
wxStatusBar* StatusBar1
//*)
DECLARE_EVENT_TABLE()
}
//(*IdInit(SampleFrame)
const long SampleFrame::idMenuQuit = wxNewId()
const long SampleFrame::idMenuAbout = wxNewId()
const long SampleFrame::ID_STATUSBAR1 = wxNewId()
//*)
BEGIN_EVENT_TABLE(SampleFrame,wxFrame)
//(*EventTable(SampleFrame)
//*)
END_EVENT_TABLE()
SampleFrame::SampleFrame(wxWindow* parent,wxWindowID id)
{
//(*Initialize(SampleFrame)
wxMenuItem* MenuItem2
wxMenuItem* MenuItem1
wxMenu* Menu1
wxMenuBar* MenuBar1
wxMenu* Menu2
Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"))
MenuBar1 = new wxMenuBar()
Menu1 = new wxMenu()
MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL)
Menu1->Append(MenuItem1)
MenuBar1->Append(Menu1, _("&File"))
Menu2 = new wxMenu()
MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL)
Menu2->Append(MenuItem2)
MenuBar1->Append(Menu2, _("Help"))
SetMenuBar(MenuBar1)
StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"))
int __wxStatusBarWidths_1[1] = { -1 }
int __wxStatusBarStyles_1[1] = { wxSB_NORMAL }
StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1)
StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1)
SetStatusBar(StatusBar1)
Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&SampleFrame::OnQuit)
Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&SampleFrame::OnAbout)
//*)
}
SampleFrame::~SampleFrame()
{
//(*Destroy(SampleFrame)
//*)
}
void SampleFrame::OnQuit(wxCommandEvent&event)
{
Close()
}
void SampleFrame::OnAbout(wxCommandEvent&event)
{
wxString msg = wxT("This is a sample windows!")
wxMessageBox(msg, _("Welcome to..."))
}
windows下通过调用API来创建窗口:#include<windows.h>
int main()
{
MessageBox(NULL,"Hello World!","C图形程序",MB_OK)
return 0
}
linux下通过调用图形库来创建窗口。
楼主如果是学C的话,先不要急于搞这些东西,把基础打扎实才是最重要的,GUI可以后学。基础扎实了,这些只是很简单的东西。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)