Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / Drawing Objects to a panel

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Drawing Objects to a panel
#5557
Posted by: 2004-12-08 01:14:21
Why doesn't this draw a circle on the panel.  According to the documentation, I have created a DC object and painted on it.  but, when I compile my code, it doesn't draw a circle on the context.  I'm having the same problems with lines, bitmaps, etc.  I've upgraded and downgraded wxWindows from 2.2.9 to 2.5.3 to no avail.  What am I doing incorrectly?

here is the code snippet.

MainFrame::MainFrame(const wxString &title, const wxPoint &pos, const wxSize &size)
    : wxFrame((wxFrame *) NULL, -1, title, pos, size)
{
    wxMenu *FileMenu = new wxMenu;
    wxMenuBar *MenuBar = new wxMenuBar;

    FileMenu->Append(ID_MAINWIN_QUIT, "&Quit");

    MenuBar->Append(FileMenu, "&File");
    SetMenuBar(MenuBar);

    CreateStatusBar(2);
    SetStatusText("Hello World!");
   
    wxPanel *myPanel = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize);
    wxClientDC dc(myPanel);
    dc.SetPen(*wxBLACK_PEN);
    dc.DrawCircle(20, 20, 20);
   
}
Message2. Re: Drawing Objects to a panel
#5564
Posted by: idb 2004-12-09 00:50:19

// TestDraw.h 
// ==========
#include <wx/wx.h>
#include <wx/image.h>
#include <wx/msgdlg.h>
#ifndef TESTDRAW_H
#define TESTDRAW_H
class MyFrame: public wxFrame {
public:
    MyFrame(wxWindow* parent, int id, const wxString& title, const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE);
protected:
    wxPanel* panel_Draw;
    wxButton* button_circle;
    wxButton* button_polyline;
    wxButton* button_rectangle;
    void OnButtonCircle();
    void OnButtonPolyline();
    void OnButtonRectangle();
    DECLARE_EVENT_TABLE()
};
#endif // TESTDRAW_H
//***************************************

// TestDraw.cpp 
// ============
#include "TestDraw.h"
MyFrame::MyFrame(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
    wxFrame(parent, id, title, pos, size, wxTAB_TRAVERSAL|wxCAPTION|wxMINIMIZE_BOX|wxSYSTEM_MENU)
{
    panel_Draw = new wxPanel(this, -1);
    button_circle = new wxButton(this, 10001, wxT("Circle"));
    button_polyline = new wxButton(this, 10002, wxT("Polyline"));
    button_rectangle = new wxButton(this, 10003, wxT("Rectangle"));
    SetTitle(wxT("My Title"));
    panel_Draw->SetSize(wxSize(381, 276));
    wxBoxSizer* sizer_myFrame = new wxBoxSizer(wxHORIZONTAL);
    wxFlexGridSizer* grid_sizer_Polovina = new wxFlexGridSizer(2, 1, 0, 0);
    wxGridSizer* grid_sizer_2 = new wxGridSizer(1, 3, 0, 0);
    grid_sizer_Polovina->Add(panel_Draw, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL, 3);
    grid_sizer_2->Add(button_circle, 0, wxALL|wxEXPAND, 3);
    grid_sizer_2->Add(button_polyline, 0, wxALL|wxEXPAND, 3);
    grid_sizer_2->Add(button_rectangle, 0, wxALL|wxEXPAND, 3);
    grid_sizer_Polovina->Add(grid_sizer_2, 1, wxEXPAND, 2);
    sizer_myFrame->Add(grid_sizer_Polovina, 1, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
    SetAutoLayout(true);
    SetSizer(sizer_myFrame);
    sizer_myFrame->Fit(this);
    sizer_myFrame->SetSizeHints(this);
    Layout();
    Centre();    
}

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
	EVT_BUTTON(10001,MyFrame::OnButtonCircle)
	EVT_BUTTON(10002,MyFrame::OnButtonPolyline)
	EVT_BUTTON(10003,MyFrame::OnButtonRectangle)
END_EVENT_TABLE()

void MyFrame::OnButtonCircle(){
	wxClientDC cdc(panel_Draw);
   PrepareDC(cdc);
	cdc.SetPen(*wxBLACK_PEN);
	for (int i=25;i>1;i--) cdc.DrawCircle(100,100,i*5);
}
void MyFrame::OnButtonPolyline(){
	wxMessageBox("OnButtonPolyline - TODO","Info!", wxOK|wxICON_EXCLAMATION,this,10,10);
}
void MyFrame::OnButtonRectangle(){
	wxClientDC cdc(panel_Draw);
   PrepareDC(cdc);
	cdc.SetBrush(*wxTRANSPARENT_BRUSH);
	cdc.SetPen(*wxRED_PEN);
	cdc.DrawRectangle(10,10,200,175);
}

class MyDrawApp: public wxApp {
public:
    bool OnInit();
};

IMPLEMENT_APP(MyDrawApp)

bool MyDrawApp::OnInit(){
    MyFrame* frame_main = new MyFrame(0, -1, "");
    SetTopWindow(frame_main);
    frame_main->Show();
    return true;
}
On: Windows 2000, Dev-Cpp 4.9.9.0, wxWidgets 2.4.2
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Fri 2024-3-29  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0