#include #include #include "kysymode.rh" /************************************************************************ Demo 3: Projektiin: kysyint.rc kysyint.rh kysyint.cpp *************************************************************************/ #define USER_MESSAGE_NAYTA (WM_USER+10) class TNappulaDialog; // Nappuladialogin esittely //------------------------------------------------------------------------------ // Kokonaislukua kysyvä dialogi class TKysyIntDialog : public TDialog { int arvo; TWindow *dlg; // Viittaus nappuladialogiin joka omistaa tämän public: TKysyIntDialog(TWindow *parent, TResId resId, TModule *module = 0) : TDialog(parent,resId,module) { dlg = parent; } virtual ~TKysyIntDialog() { Destroy(); } void TextChanged() { arvo=GetDlgItemInt(KYSYINT_EDIT); dlg->SendMessage(USER_MESSAGE_NAYTA,arvo,0); } virtual void Destroy(int retValue=IDCANCEL) { Show(SW_HIDE); } DECLARE_RESPONSE_TABLE(TKysyIntDialog); }; DEFINE_RESPONSE_TABLE1(TKysyIntDialog, TDialog) // EV_EN_CHANGE(KYSYINT_EDIT,TextChanged), EV_BN_CLICKED(ID_OK,TextChanged), END_RESPONSE_TABLE; //------------------------------------------------------------------------------ // Pääohjelmana toimiva dialogi class TNappulaDialog : public TDialog { TKysyIntDialog *dlg; public: TNappulaDialog(TWindow *parent, TResId resId, TModule *module = 0) : TDialog(parent,resId,module) { dlg = new TKysyIntDialog(this,"KYSYINT_DIALOG"); dlg->Create(); } virtual ~TNappulaDialog() { Destroy(); } // Näyttää arvon ruudulla LRESULT DisplayValue(WPARAM a,LPARAM) { // int DisplayValue(int a) { TClientDC dc(*this); char text[40]; wsprintf(text,"Luku oli %d, heksana 0x%x",a,a); dc.TextOut(10,10,text); return 0; } void EvRButtonDown(uint modKeys, TPoint& point) { if (dlg->IsWindowVisible()==false) dlg->Show(SW_SHOW); } DECLARE_RESPONSE_TABLE(TNappulaDialog); }; DEFINE_RESPONSE_TABLE1(TNappulaDialog, TDialog) EV_WM_RBUTTONDOWN, EV_MESSAGE(USER_MESSAGE_NAYTA,DisplayValue), END_RESPONSE_TABLE; //------------------------------------------------------------------------------ class TNappulaApp : public TApplication { public: TNappulaApp(const char *title) : TApplication(title) {} void InitMainWindow() { TDecoratedFrame *fw = new TDecoratedFrame(0,Name, new TNappulaDialog(0,"PAA_DIALOG")); fw ->SetFlag(wfShrinkToClient); SetMainWindow(fw); } }; /********************* Pääohjelma *********************************************/ int OwlMain(int ,char far * []) { return TNappulaApp("Nappulaohjelma").Run(); }