nativdlg.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: samples/nativdlg/nativdlg.cpp
  3. // Purpose: Native Windows dialog sample
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 04/01/98
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. // For compilers that support precompilation, includes "wx/wx.h".
  11. #include "wx/wxprec.h"
  12. #ifdef __BORLANDC__
  13. #pragma hdrstop
  14. #endif
  15. #ifndef WX_PRECOMP
  16. #include "wx/wx.h"
  17. #endif
  18. #ifndef __WXMSW__
  19. #error Sorry, this sample is only appropriate under Windows.
  20. #endif
  21. #ifndef wxHAS_IMAGES_IN_RESOURCES
  22. #include "../sample.xpm"
  23. #endif
  24. #include <ctype.h>
  25. #include "nativdlg.h"
  26. #include "resource.h"
  27. IMPLEMENT_APP(MyApp)
  28. bool MyApp::OnInit(void)
  29. {
  30. if ( !wxApp::OnInit() )
  31. return false;
  32. // Create the main frame window
  33. MyFrame *frame = new MyFrame(NULL, wxID_ANY, wxT("wxWidgets Native Dialog Sample"), wxPoint(0, 0), wxSize(300, 250));
  34. #if wxUSE_STATUSBAR
  35. // Give it a status line
  36. frame->CreateStatusBar(2);
  37. #endif // wxUSE_STATUSBAR
  38. // Make a menubar
  39. wxMenu *file_menu = new wxMenu;
  40. file_menu->Append(RESOURCE_TEST1, wxT("&Dialog box test"), wxT("Test dialog box resource"));
  41. file_menu->Append(RESOURCE_QUIT, wxT("E&xit"), wxT("Quit program"));
  42. wxMenuBar *menu_bar = new wxMenuBar;
  43. menu_bar->Append(file_menu, wxT("&File"));
  44. // Associate the menu bar with the frame
  45. frame->SetMenuBar(menu_bar);
  46. // Make a panel
  47. frame->panel = new wxWindow(frame, wxID_ANY, wxPoint(0, 0), wxSize(400, 400), 0, wxT("MyMainFrame"));
  48. frame->Show(true);
  49. return true;
  50. }
  51. wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
  52. EVT_MENU(RESOURCE_QUIT, MyFrame::OnQuit)
  53. EVT_MENU(RESOURCE_TEST1, MyFrame::OnTest1)
  54. wxEND_EVENT_TABLE()
  55. // Define my frame constructor
  56. MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size):
  57. wxFrame(parent, id, title, pos, size)
  58. {
  59. SetIcon(wxICON(sample));
  60. panel = NULL;
  61. }
  62. void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
  63. {
  64. Close(true);
  65. }
  66. void MyFrame::OnTest1(wxCommandEvent& WXUNUSED(event))
  67. {
  68. #if ( defined(__WXPM__) || defined(__WXMSW__) ) && !defined(__WXUNIVERSAL__)
  69. MyDialog dialog;
  70. if (dialog.LoadNativeDialog(this, wxT("dialog1")))
  71. {
  72. dialog.ShowModal();
  73. }
  74. #else
  75. wxMessageBox(wxT("No native dialog support"),wxT("Platform limitation"));
  76. #endif
  77. }
  78. wxBEGIN_EVENT_TABLE(MyDialog, wxDialog)
  79. EVT_BUTTON(wxID_OK, MyDialog::OnOk)
  80. EVT_BUTTON(wxID_CANCEL, MyDialog::OnCancel)
  81. wxEND_EVENT_TABLE()
  82. void MyDialog::OnOk(wxCommandEvent& WXUNUSED(event))
  83. {
  84. EndModal(wxID_OK);
  85. }
  86. void MyDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
  87. {
  88. EndModal(wxID_CANCEL);
  89. }