为什么我的窗口无法退出了?

这是wxWidgets论坛的中文版本。在这里,您可以用您的母语汉语讨论上面任一子论坛所涉及的所有关于wxWidgets的话题。欢迎大家参与到对有价值的帖子的中英互译工作中来!
Post Reply
huangxf
In need of some credit
In need of some credit
Posts: 1
Joined: Thu Jul 09, 2009 7:52 am

为什么我的窗口无法退出了?

Post by huangxf »

我做了一个小程序来学习wxWidgets的最简单的编程结构。我的程序是基于《跨平台开发wxWidgets》中minimal.cpp这个例子的,一个wxApp派生类,一个wxFrame派生类。然后我只是在wxFrame派生了中增加了对PAINT事件的支持。编译可以成功,但是运行的时候无论是quit还是about菜单都无法响应了。直接点右上角的关闭也无法让窗口关闭。窗口仅仅是失去焦点了那样地定在那里,什么也不做。谁能告诉我这是为什么呢?我把有问题的代码如下。

Code: Select all

// Name:        minimal.cpp
// Purpose:     Minimal wxWidgets sample
// Author:      Julian Smart

#include "wx/wx.h"

// Declare the application class
class MyApp : public wxApp
{
public:
    // Called on application startup
    virtual bool OnInit();
};

// Declare our main frame class
class MyFrame : public wxFrame
{
public:
    // Constructor
    MyFrame(const wxString& title);

    // Event handlers
    void OnQuit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
	void OnPaint(wxPaintEvent& event);

private:
	void DrawMsg(void);
	void CreateControl(void);
	wxBoxSizer *topSizer; //layout parameter
    // This class handles events
    DECLARE_EVENT_TABLE()
};

// Implements MyApp& GetApp()
DECLARE_APP(MyApp)

// Give wxWidgets the means to create a MyApp object
IMPLEMENT_APP(MyApp)

// Initialize the application
bool MyApp::OnInit()
{
    // Create the main application window
    MyFrame *frame = new MyFrame(wxT("Minimal wxWidgets App"));
    // Show it
    frame->Show(true);
    // Start the event loop
    return true;
}

// Event table for MyFrame
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
    EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
    EVT_MENU(wxID_EXIT,  MyFrame::OnQuit)
	EVT_PAINT(MyFrame::OnPaint)
END_EVENT_TABLE()

void MyFrame::OnAbout(wxCommandEvent& event)
{
    wxString msg;
    msg.Printf(wxT("Hello and welcome to %s"),  
               wxVERSION_STRING);

    wxMessageBox(msg, wxT("About Minimal"),
                 wxOK | wxICON_INFORMATION, this);
}

void MyFrame::OnQuit(wxCommandEvent& event)
{
    // Destroy the frame
	wxMessageBox(wxT("On exit!"), wxT("Quit Minimal"),
                 wxOK | wxICON_INFORMATION, this);
    Close(true);
}

void MyFrame::OnPaint(wxPaintEvent& evetn){

}




void MyFrame::CreateControl(){

}


MyFrame::MyFrame(const wxString& title)
       : wxFrame(NULL, wxID_ANY, title)
{
    // Set the frame icon

    // Create a menu bar
    wxMenu *fileMenu = new wxMenu;

    // The "About" item should be in the help menu
    wxMenu *helpMenu = new wxMenu;
    helpMenu->Append(wxID_ABOUT, wxT("&About...\tF1"),
                     wxT("Show about dialog"));

    fileMenu->Append(wxID_EXIT, wxT("E&xit\tAlt-X"),
                     wxT("Quit this program"));

    // Now append the freshly created menu to the menu bar...
    wxMenuBar *menuBar = new wxMenuBar();
    menuBar->Append(fileMenu, wxT("&File"));
    menuBar->Append(helpMenu, wxT("&Help"));

    // ... and attach this menu bar to the frame
    SetMenuBar(menuBar);
	CreateControl();


    // Create a status bar just for fun
    CreateStatusBar(2);
    SetStatusText(wxT("Welcome to wxWidgets!"));
}

[/code]
murusu
Earned a small fee
Earned a small fee
Posts: 13
Joined: Thu Mar 12, 2009 9:38 am

Post by murusu »

OnPaint里面什么都不干就是原因,如果你目前不打算任何特殊处理的话,请调用skip(),或者是单纯获取该窗口的dc也可以,总之要让系统知道你已经响应了重绘的请求
Post Reply