Example

This is example of code which presnt main featues of widgets:

 #include "MWidgets.h"
 #ifdef _DEBUG
     #ifdef _MSC_VER
         #include <crtdbg.h>
     #endif
 #endif
 using namespace MWidgets;
 using namespace std;
 
 class ToolBar:public DockWindow
 {
         Image imgs[6];
         Button btnNew;
         Button btnOpen;
         Button btnSave;
         Button btnCut;
         Button btnCopy;
         Button btnPaste;
         TextBox text;
         ComboBox combo;
 public:
         ToolBar():DockWindow(){};
         virtual void OnCreate()
         {
                 imgs[0].Load("..\\res\\icon_New.bmp");
                 imgs[1].Load("..\\res\\icon_Open.bmp");
                 imgs[2].Load("..\\res\\icon_Save.bmp");
                 imgs[3].Load("..\\res\\icon_Cut.bmp");
                 imgs[4].Load("..\\res\\icon_Copy.bmp");
                 imgs[5].Load("..\\res\\icon_Paste.bmp");
 
                 int pos=1;
                 Size((25+2)*6+160+160,33);
                 btnNew.Create(this,pos,1,25,25,"New","New",true);
                 pos+=25;
                 btnNew.SetImage(&imgs[0]);
                 btnNew.Show();
                 pos+=1;
                 btnOpen.Create(this,pos,1,25,25,"Open","Open",true);
                 pos+=25;
                 btnOpen.SetImage(&imgs[1]);
                 btnOpen.Show();
                 pos+=1;
                 btnSave.Create(this,pos,1,25,25,"Save","Save",true);
                 pos+=25;
                 btnSave.SetImage(&imgs[2]);
                 btnSave.Show();
                 pos+=1;
                 btnCut.Create(this,pos,1,25,25,"Cut","Cut",true);
                 pos+=25;
                 btnCut.SetImage(&imgs[3]);
                 btnCut.Show();
                 pos+=1;
                 btnCopy.Create(this,pos,1,25,25,"Copy","Copy",true);
                 pos+=25;
                 btnCopy.SetImage(&imgs[4]);
                 btnCopy.Show();
                 pos+=1;
                 btnPaste.Create(this,pos,1,25,25,"Paste","Paste",true);
                 pos+=25;
                 btnPaste.SetImage(&imgs[5]);
                 btnPaste.Show();
                 pos+=5;
                 text.Create(this,pos,1,150,25);
                 pos+=150;
                 text.Show();
                 pos+=1;
                 combo.Create(this,pos,1,150,60);
                 combo.Show();
                 combo.AddString("White");
                 combo.AddString("Red");
                 combo.AddString("Blue");
                 combo.AddString("Green");
 
         };
 };
 class MyDockWnd2:public DockWindow
 {
         TextBox  text1;
 public:
         MyDockWnd2():DockWindow(){};
         virtual void OnCreate()
         {
                 text1.Create(this,10,10,150,30);
                 text1.Show();
         };
 };
 
 class MyDockWnd3:public DockWindow
 {
         Button btnToCol;
         Button btnToMin;
         Button btnToMax;
         Grid  grid1;
 public:
         MyDockWnd3():DockWindow(){};
         virtual void OnCreate()
         {
                 grid1.Create(this,0,0,0,0);
                 grid1.Show();
 
                 int w=256,h=65536;
                 grid1.SetDefColWidth(80);
                 grid1.SetDefRowHeight(25);
                 grid1.SetSize(h,w);
                 grid1.SetFixedColCount(2);
                 grid1.SetFixedRowCount(2);
                 
 
                 grid1.SetItemText(3,5,"Hello World!");
                 grid1.SetFont("Arial",18,true,true,false);
                 grid1.SetDefFixedCellColor(RGB(178,178,178));
                 
                 
                 for(int r=grid1.GetFixedRowsCount();r<5000;r++)
                 {                       
                         //grid1.SetRowHeight(r,20+rand()/500);
                 }
 
                 for(int c=grid1.GetFixedColsCount();c<200;c++)
                 {
                         //grid1.SetColWidth(c,c*5+10);
                 }
 
                 grid1.SetTextAlign(ALIGN_CENTER);
                 grid1.SetHideMode(HIDE_COL);
                 grid1.HighlightFocusedRow(true,RGB(255,255,0));
                 //grid1.HighlightFocusedCol(true,RGB(255,0,255));
                 grid1.NumberFixedCol(0,true);
                 grid1.NumberFixedRow(0,true);
                 grid1.Refresh();
 
                 btnToMin.Create(this,10,5,85,30,"Aling to Min");
                 btnToMin.Show();
                 btnToMin.SetOnClickHandler<MyDockWnd3>(this,&MyDockWnd3::BtnToMinClick);
                 btnToMax.Create(this,90+10,5,85,30,"Aling to Max");
                 btnToMax.Show();
                 btnToMax.SetOnClickHandler<MyDockWnd3>(this,&MyDockWnd3::BtnToMaxClick);
                 btnToCol.Create(this,90+90+10,5,85,30,"Aling to Col");
                 btnToCol.Show();
                 btnToCol.SetOnClickHandler<MyDockWnd3>(this,&MyDockWnd3::BtnToColClick);
         };
         virtual void OnSize(int left,int top,int right,int bottom)
         {
                 grid1.Move(0,40);
                 grid1.Size(right-left-3,bottom-top-3-40);
                 grid1.Refresh();
         }
         void BtnToMinClick(Widget* )
         {
                 grid1.ResizeToMinSize();
                 grid1.Refresh(true);
         }
         void BtnToMaxClick(Widget* )
         {
                 grid1.ResizeToMaxSize();
                 grid1.Refresh(true);
         }
         void BtnToColClick(Widget* )
         {
                 grid1.ResizeToAlignCol();
                 grid1.Refresh(true);
         }
 };
 
 
 class MyDialog:public Dialog
 {
         Label  label1;
         Button butOk;
         Button butCancel;
         GroupBox group1;
 public:
         MyDialog():Dialog(){};
         void Create(string caption,string text)
         {
                 Dialog::Create(300,200,caption);
 
                 group1.Create(this,10,10,250,150,"Childs");
                 group1.Show();
 
                 label1.Create(&group1,10,50,80,30,text);
                 label1.Show();
 
                 butOk.Create(&group1,10,100,50,20,"OK");
                 butOk.SetOnClickHandler<MyDialog>(this,&MyDialog::ButOkOnClick);
                 butOk.Show();
 
                 butCancel.Create(&group1,115,100,50,20,"CHANCEL");
                 butCancel.SetOnClickHandler<MyDialog>(this,&MyDialog::ButCancelOnClick);
                 butCancel.Show();
 
                 SetHotKey<MyDialog>(MOD_CONTROL,'E',this,&MyDialog::OnCtrlE);
         };
         void ButOkOnClick(Widget* )
         {
                 EndDlg(IDOK);
         }
         void ButCancelOnClick(Widget*  )
         {
                 EndDlg(IDCANCEL);
         }
         virtual void OnRightButtonDown(int x,int y,DWORD )
         {
                 ContextMenu menu;
                 menu.InsertSubMenuItem<MyDialog>("",0,"Hello",this,&MyDialog::OnCMenu);
                 menu.TrackMenu(x,y,this);
         }
         void OnCMenu(Widget* )
         {
                 MessageBox(GetHwnd(),":)","Context Menu",MB_OK);
         };
         void OnCtrlE(Widget*)
         {
                 MessageBox(this->GetHwnd(),"Ctrl-E","Dialog HotKey",MB_OK);
         }
 };
 
 class MainFrame:public Window
 {
         ToolBar toolbar;
         MyDockWnd2 mydockwnd2;
         MyDockWnd3 mydockwnd3;
         Label  label1;
         Button but1;
         Button but2;
         CheckBox check1;
         ComboBox comb1;
         TextBox text1;
         GroupBox group1;
         RadioButton radio1;
         RadioButton radio2;
         StatusBar stbar;
         Menu menu;
 public:
         MainFrame():Window(){};
         virtual void Create()
         {
                 Window::Create(0,0,800,600,"Main window");
 
                 this->SetLeftButtonDownHandler<MainFrame>(this,&MainFrame::OnMLBD);
 
                 toolbar.Create(this,100,100,300,200,"");
                 toolbar.Show();
                 toolbar.Size(0,33);
                 toolbar.DockToTop();
 
 
                 mydockwnd2.Create(this,500,100,300,200,"Docking window2");
                 mydockwnd2.Show();
                 mydockwnd2.Size(100,0);
                 mydockwnd2.DockToRight();
 
 
                 mydockwnd3.Create(this,100,500,300,200,"Docking window3");
                 mydockwnd3.Show();
                 mydockwnd3.Size(0,300);
                 mydockwnd3.DockToBottom();
 
 
                 label1.Create(this,0,50,150,30,"This is Label");
                 label1.Show();
 
 
                 but1.Create(this,160,60,80,30,"But1","This is Button");
                 but1.SetOnClickHandler<MainFrame>(this,&MainFrame::But1OnClick);
                 but1.Show();
 
 
                 but2.Create(this,550,60,80,30,"DockWnd","create new dock window");
                 but2.SetOnClickHandler<MainFrame>(this,&MainFrame::But2OnClick);
                 but2.SetPressed(true);
                 but2.Show();
 
                 check1.Create(this,270,60,120,30,"World/Car");
                 check1.Show();
 
                 comb1.Create(this,400,60,100,60);
                 comb1.AddString("Hello");
                 comb1.AddString("World0");
                 comb1.AddString("World1");
                 comb1.AddString("World2");
                 comb1.AddString("World3");
                 comb1.AddString("World4");
                 comb1.SetOnChangeHandler<MainFrame>(this,&MainFrame::Comb1OnChange);
                 comb1.Show();
 
                 text1.Create(this,10,100,150,20);
                 text1.SetOnChangeHandler<MainFrame>(this,&MainFrame::Text1OnChange);
                 text1.Show();
 
                 group1.Create(this,250,100,100,100,"Options");
                 radio1.Create(&group1,10,30,60,20,"Hello");
                 radio1.Show();
                 radio1.SetCheked();
                 radio2.Create(&group1,10,120,60,20,"Buy");
                 radio2.Show();
                 group1.Show();
 
                 stbar.Create(this);
                 stbar.AddPart(100);
                 stbar.SetPartText(0,"part 0");
                 stbar.AddPart(200);
                 stbar.SetPartText(1,"part 1");
                 stbar.AddPart(50);
                 stbar.SetPartText(2,"part 2");
                 stbar.AddPart(25);
                 stbar.SetPartText(3,"part 3");
                 stbar.Show();
 
                 menu.InsertSubMenu("",0,"File");
                 menu.InsertSubMenu("",1,"Edit");
                 menu.InsertSubMenu("",2,"Help");
 
                 menu.InsertSubMenu("0",0,"Open");
                 menu.InsertSubMenu("0",1,"Close");
                 menu.InsertSubMenu("0:0",0,"Open2");
 
                 menu.RemoveSubMenu("0:1");
                 menu.UpdateSubMenu("0:0:0","Hello");
 
 
                 menu.InsertSubMenuItem<MainFrame>("0:0:0",0,"Privet",this,&MainFrame::MenuItem1OnClick);
 
                 menu.InsertSubMenuItem<MainFrame>("0",0,"Poka",this,&MainFrame::MenuItem2OnClick);
 
                 menu.EnableSubMenu("0:1",FALSE);
                 menu.InsertSubMenuSeparator("0",1);
                 SetMenuBar(&menu);
                 SetHotKey<MainFrame>(MOD_CONTROL,'S',this,&MainFrame::OnCtrlS);
                 SetHotKey<MainFrame>(MOD_CONTROL,'span',this,&MainFrame::OnCtrlA);
         };
         void OnMLBD(Widget* ,int x,int y,DWORD )
         {
                 char buf[20];
                 itoa(x,buf,10);
                 int len=(int)strlen(buf);
                 buf[len]=':';
                 itoa(y,buf+len+1,10);
                 label1.SetText(buf);
         };
         void But1OnClick(Widget*)
         {
                 if(radio1.GetCheked())
                         MessageBox(this->GetHwnd(),text1.GetText().c_str(),"Hello",MB_OK);
                 else if(radio2.GetCheked())
                         MessageBox(this->GetHwnd(),text1.GetText().c_str(),"Buy",MB_OK);
 
         };
         void But2OnClick(Widget*)
         {
                 if(mydockwnd2.IsDestroyed())
                 {
                         mydockwnd2.Create(this,500,100,300,200,"Docking window2");
                         mydockwnd2.Show();
                 }
                 if(mydockwnd3.IsDestroyed())
                 {
                         mydockwnd3.Create(this,100,500,300,200,"Docking window3");
                         mydockwnd3.Show();
                 }
         };
         void Comb1OnChange(Widget*)
         {
                 text1.SetText(comb1.GetText());
         };
         void Text1OnChange(Widget*)
         {
                 if(check1.GetCheked())
                         MessageBox(this->GetHwnd(),text1.GetText().c_str(),"World",MB_OK);
                 else if(!check1.GetCheked())
                         MessageBox(this->GetHwnd(),text1.GetText().c_str(),"Car",MB_OK);
         };
         void MenuItem1OnClick(Widget*)
         {
                 MyDialog dlg;
                 dlg.Create("Menu","Text");
                 int rez=dlg.DoModal(this);
                 if(rez==IDOK)
                 {
                         menu.EnableSubMenuItem("0:1:0:0",FALSE);
                         menu.UpdateSubMenuItem("0:1:0:0","dgfdgd");
                 }
         }
         void MenuItem2OnClick(Widget*)
         {
                 menu.EnableSubMenu("0:2",TRUE);
                 menu.RemoveSubMenuItem("0:0");
         }
         void OnCtrlS(Widget*)
         {
                 MessageBox(this->GetHwnd(),"Ctrl-S","HotKey",MB_OK);
         }
         void OnCtrlA(Widget*)
         {
                 MessageBox(this->GetHwnd(),"Ctrl-span","HotKey",MB_OK);
         }
 };
 
 
 int APIENTRY WinMain(HINSTANCE ,HINSTANCE ,LPTSTR ,int )
 {
 #ifdef _DEBUG
     #ifdef _MSC_VER
         int tmp;
         tmp = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
         tmp |= _CRTDBG_CHECK_ALWAYS_DF;
         tmp |= _CRTDBG_LEAK_CHECK_DF;
         tmp |= _CrtSetDbgFlag(tmp);
     #endif
 #endif
 
 
         try
         {
                 Icon bigIcon;
                 bigIcon.Load("..\\res\\icon2.ico");
                 Icon smallIcon;
                 smallIcon.Load("..\\res\\icon1.ico");
 
                 Widgets::Init(&bigIcon,&smallIcon);
 
                 MainFrame mf;
                 mf.Create();
                                                 
                 mf.Show();
 
                 Widgets::Instance()->Run();
                 Widgets::Destroy();
         }
         catch(Exception e)
         {
                 Widgets::Destroy();
                 TCHAR           buffer[160];
                 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError(), 
			MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), &buffer[0], 160, 0);
                 std::string errmsg=buffer;
                 errmsg+="\n";
                 MessageBox(NULL,(errmsg+e.Msg()).c_str(),"MWidgets Exception",MB_OK|MB_ICONERROR);
         }
         catch(...)
         {
                 Widgets::Destroy();
                 SEHExceptionWatcher ew;
                 std::string err=ew.Read();
                 MessageBox(NULL,err.c_str(),"MWidgets Exception",MB_OK);
         }
 
         return 0;
 };