|
From: andrew7 <bd...@us...> - 2007-02-19 02:24:12
|
Update of /cvsroot/smartwin/SmartWin/tests/swDll In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv1785/tests/swDll Modified Files: swDllMain.cpp Added Files: ResourceDialogClass.h resource.h swDllswMain.cpp Log Message: Try resources in DLLs --- NEW FILE: swDllswMain.cpp --- // $Revision: 1.1 $ /* Copyright (c) 2005 - Thomas Hansen * Part of the SmartWin++ library example code * Permission to use under the same terms as the actual library * The license to the library can be found at http://smartwinlib.org * License for library is Open Source and BSD */ // swDllswMain.cpp : Defines the entry point for the C++ application. // This program uses swDll.dll whose source is swDll.cpp, and API definition is swdll.h // We use SmartWin in the application, and in the DLL. // Both projects are in the swDLL directory. // #define DLLMODE dllimport #include "swdll.h" #include <iostream> #include "SmartWin.h" using namespace SmartWin; class HelloWinClass : public WidgetFactory< WidgetWindow, HelloWinClass > { private: WidgetMenuPtr itsMainMenu; WidgetButtonPtr itsButton; public: void menuSayHello( WidgetMenuPtr menu, unsigned item ) { int numb; char str[99]; // Dll gets values with a GUI. if ( guiGetNumberAndString( & numb, ( char * ) & str ) ) { createMessageBox().show( _T( "Hello !" ), str ); } } void menuClose( WidgetMenuPtr menu, unsigned item ) { close(); } void buttonClicked( WidgetButtonPtr button ) { int numb; char str[99]; // Same thing but this time the DLL does it with a dialog. if ( dialogGetNumberAndString( & numb, ( char * ) & str ) ) { createMessageBox().show( _T( "Hello !" ), str ); } } void initAndCreate() { createWindow(); setText( _T( "Hello SmartWin" ) ); // Title SmartWin::Rectangle desktop( getDesktopSize() ); setBounds( desktop.top( 0.2 ).right( 0.3 ) ); itsButton = createButton(); itsButton->setText( _T( "Bring up a dialog from a DLL" ) ); itsButton->onClicked( & HelloWinClass::buttonClicked ); itsButton->setBounds( sw::Rectangle( Point( 200, 30 ) ) ); // Creating main menu itsMainMenu = createMenu(); WidgetMenuPtr file = itsMainMenu->appendPopup( _T( "&MenuCommands" ) ); int m = 1; file->appendItem( m++, _T( "Use DLL function" ), & HelloWinClass::menuSayHello ); file->appendItem( m++, _T( "Close" ), & HelloWinClass::menuClose ); #ifndef WINCE itsMainMenu->attach( this ); #endif layout(); onSized( & HelloWinClass::isResized ); } void isResized( const WidgetSizedEventResult & sz ) { layout(); } void layout() { SmartWin::Place p; SmartWin::Rectangle r( getClientAreaSize() ); p.setBoundsBorders( r, 4, 4 ); itsButton->setPositionPerPlace( p ); } }; int SmartWinMain( Application & app ) { HelloWinClass * testHello = new HelloWinClass; testHello->initAndCreate(); return app.run(); } --- NEW FILE: ResourceDialogClass.h --- #include "SmartWin.h" using namespace SmartWin; #include <iostream> //------------------------------------------------------- /* ResourceDialogClass IN: Class needs to be constructed with a dialog resource ID that contains: Two buttons: IDOK and IDCANCEL, and one textbox: IDC_HEXEDIT */ #include "resource.h" class ResourceDialogClass : public SmartWin::WidgetFactory< SmartWin::WidgetDialog, ResourceDialogClass, SmartWin::MessageMapPolicyDialogWidget > { private: WidgetTextBox * itsHexTxt; // or WidgetText * if using MSVC++ char * itsOutStrPtr; public: // Constructor ResourceDialogClass( char * outStrPtr ) : itsOutStrPtr( outStrPtr) { try { createDialog( IDD_HEXDIALOG ); WidgetButtonPtr btnOk = subclassButton( IDOK ); WidgetButtonPtr btnCancel = subclassButton( IDCANCEL ); itsHexTxt = subclassTextBox( IDC_HEXEDIT ); itsHexTxt->setTextLimit(32); itsHexTxt->setFocus(); itsHexTxt->setText( _T("Hello from a resource based dialog in a DLL") ); onClosing( & ResourceDialogClass::closing ); btnCancel->onClicked( & ResourceDialogClass::cancelClicked ); btnOk->onClicked( & ResourceDialogClass::OkClicked ); } catch ( xCeption x ) { SmartUtil::tstring errmsg( x.whatWndMsg() ); errmsg += _T(" from "); errmsg += x.what(); createMessageBox().show( errmsg ); } } void OkClicked( WidgetButtonPtr btn ) { close(); } void cancelClicked( WidgetButtonPtr btn ) { itsHexTxt->setText( _T("Cancel") ); } bool closing() { strcpy( itsOutStrPtr, itsHexTxt->getText().c_str() ); return true; } }; //------------------------------------------------------- --- NEW FILE: resource.h --- //{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. // Used by WidgetDialog.rc // #define IDD_HEXDIALOG 101 #define IDC_HEXEDIT 1001 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 102 #define _APS_NEXT_COMMAND_VALUE 40001 #define _APS_NEXT_CONTROL_VALUE 1002 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif Index: swDllMain.cpp =================================================================== RCS file: /cvsroot/smartwin/SmartWin/tests/swDll/swDllMain.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- swDllMain.cpp 7 Jan 2007 18:43:05 -0000 1.4 +++ swDllMain.cpp 19 Feb 2007 02:24:02 -0000 1.5 @@ -1,6 +1,7 @@ // $Revision$ // swDllMain.cpp : Defines the entry point for the C++ application. // This program uses swDll.dll whose source is swDll.cpp, and API definition is swdll.h +// We don't use SmartWin in the application, but do in the DLL. // Both projects are in the swDLL directory. // #define DLLMODE dllimport |