I have been using pure C written BREW programs, because of some reasons, I started to use C to develop Brew, and I use this frame in the financial industry's Brew version, it feels more convenient, now summarize a lot of experience with you. . (After paying the source code project, the compilation is successful, absolutely non-wood, welcome the public to use it) 1. The distribution of memory is released under BREW, which can only be assigned and released by the interface provided by the platform, so we must do things according to the rules, need inline we have a long-lost operator new and delete, wow, I like New. . . Remember to be delete
Source code:
Inline void * Operator new (size_t, void * a0) throw () {return (A0);
Inline void * operator new [] (size_t, void * a0) throw () {return (A0);
Inline void * Operator new (size_t r0) throw () {return (malloc (r0));}
Inline void * operator new [] (size_t r0) throw () {return (malloc (r0));
Inline void Operator Delete (void *, void *) {return;}
Inline void Operator delete [] (void *, void *) {return;}
Inline void Operator Delete (void * a0) {free (a0); return;}
Inline void operator delete [] (void * a0) {free (a0); return;}
2. Heavy release of pointer
Source code:
#ifndef aee_simulator
Template
Inline T Reinterpret_brew (const void * a0) {return (t (a0));}
Template
Inline T static_brew (const void * a0) {return (t (a0));}
Template
INLINE T DYNAMIC_BREW (const void * a0) {return (t (a0));}
Template
INLINE T const_brew (const void * a0) {return (t (a0));}
#ELSE
#define reinterpret_brew reinterpret_cast
#define static_brew static_cast
#define Dynamic_Brew Dynamic_cast
#define const_brew const_cast
#ENDIF
3. Platform calls our Applet's portal must use Extern "C" to define, don't tell me, you don't know that it will happen.
Source code:
//Entrance
EXTERN "C"
{
INT aeeclscreateInstance (aeeclsid clsid, ishell * pishell, imodule * po, void ** ppobj) {
* ppobj = NULL;
IF (CLSID == aeeclsid_tjapp)
{
IF (aeeeapplet_new (sizeof (ctjapp), clsid, pishell, po, (ketplet **) PPOBJ,
(Aeehandler) CTJAPP :: Handleevent, (pfnfreeappdata) ctjapp :: freeAppdata)
{
IF (CTJAPP :: InitAppdata) * PPOBJ))
{
Return (aee_success);
}
}
}
Return (efailed);
}
}
4. Implement C to C conversion definition 3 static functions,
Source code:
Static Boolean Handleevent (CTJAPP * PAPP, AEEEVENT ECODE, UINT16 WPARAM, UINT32 DWPARAM);
Static Boolean initAppdata (Iapplet * piapplet);
Static void FreeAppdata (CTJAPP * PAPP);
Event forwarding, converted to C
Source code:
Boolean ctjapp :: Handleevent (ctjapp * pi, aeeeevent ecode, uint16 wparam, uint32 dwparam)
{
IF (ecode == evt_key && wparam == avk_fa_f2)
WPARAM = AVK_FA_SELECT;
Return Pi-> Onevent (Ecode, WPARAM, DWPARAM);
}
Other structural modes are processed according to MediaPlay. MediaPlay is the structure of most of the classics. 5. New window is ready to wow, first define window values, inherit a Class CTJWIN to realize the virtual function of Class Ctjwin, virtual functions, haha, I like virtual functions
Source code:
Virtual Boolean OnInit (CTJAPP * PAPP) {Return True;}
Virtual void OneNable (Boolean Benable = true) {}
Virtual void onRedraw () {}
Virtual Boolean Onhandleevent (aeeeevent ecode, uint16 wparam, uint32 dwparam) {return true;}
Virtual Boolean ONNOTIFY (INT Nnotify) {Return True;} // Require data notification, please override this function
Then implement the functions you need in the corresponding function. I have written some common functions in CTJWIN, absolutely non-wood, welcome to use the masses, all the consequences are self-contained, 嘿嘿 Implement, dialogs and basic headings, buttons, and window switches
Source code:
Static void closemsg (ctjwin * pwin); // automatically disappeared dialog closing function
Void Showmsg (); // Display dialog
Void setmsg (uint16 nmsgid, msg_type nmt = mt_1000); // 2 ways
Void setmsg (AECHAR * PSZ, MSG_TYPE NMT = MT_1000);
Boolean isactive (); // Whether the window is active
Void DrawTitle (Boolean Bcenter = true); // Drawn Title Void DrawTitle (AECHAR * PSZ, Boolean Bcenter = true);
Void DrawTitlebar (Aeeeect * Prect, AECHAR * PSTextBuf, RGBVAL Background, Rgbval Text, Boolean Bcenter;
Void DrawtTb (); // text TB
Void drawtb ();
Void DrawToolbar (aeeeect * prect, uint16 nresid, boolean bleft);
Void DrawTextTb (aeeeect * prect, uint16 nTextResid, Boolean Bleft);
Void DrawTTBText (Aeeeect * Prect, AECHAR * PSTextBuf, RGbVal Text, Boolean Bleft);
void loadingtitle ();
Void loadingTitle (uint16);
Void setTitle; AECHAR *);
PUBLIC:
Boolean OnnumKey (IMenuctl * Pmenu, UINT16 Key);
Boolean Postevent (Aeeeevent EVT, UINT16 WP, UINT32 DWP);
Boolean Gowin (TPWindow TPWIN); / / Switching Window
Boolean gobackwin (); // back to the previous window
Void clearscreen (); // clear screen
TPWindow gettpactive (); // The value of the current window
TPWindow gettpback (); // The last window is worth
Let's take a look at how you have time to add. 6. Example: CSPLASHWIN, the startup flash window Requirements: When extracting a picture resource redraw, display a picture to the keyboard to skip the processing of the keyboard, switch to the main window Enable and Disable (calls and SMS) ) At the end of the timing, when switching to the main window destroy window, release the image resource, release the timer
Source code:
#include "tjwin.h"
Class Csplashwin: Public CTJWIN
{
PUBLIC:
CSPLASHWIN ();
Virtual ~ csplashwin ();
Boolean OnInit (CTJAPP * PAPP);
Void OneNable (Boolean Benable = True);
Void onRedraw ();
Boolean Onhandleevent (aeeeevent ecode, uint16 wparam, uint32 dwparam);
Static void closeSplash (CSPLASHWIN * PSLASHWIN); / / timer function,
IIMAGE * PI; // Startup screen painting picture
}
Implement specific features
Source code:
CSPlashwin :: csplashwin ()
{
}
CSPlashwin :: ~ csplashwin ()
{
// When destroy the window, release the image resource, release the timer
Ishell_canceltimer (m_pishell, (pfnnotify) csplashwin :: closeSplash, this);
FA_RELESEIF (PI);
}
Boolean CSPlashwin :: OnNit (CTJAPP * PAPP)
{
/ / Extract a picture resource when you initially
PI = Ishell_LoadResimage (m_pishell, tjapp_res_file, idb_splash);
Return True;}
Void Csplashwin :: CloseSplash (CSPLASHWIN * PSLASHWIN)
{
// End, switch to the main window
Pslashwin-> m_papp-> setWindow; FAW_MAIN
}
Void Csplashwin :: OneNable (Boolean Benable)
{
// Processing window Enable and Disable (calls and SMS)
IF (Benable)
{
ISHELL_SETTIMER (M_Pishell, Fa_Splash_timer, (Pfnnotify) CSPlashwin :: CloseSplash, this);
}
Else
{
Ishell_canceltimer (m_pishell, (pfnnotify) csplashwin :: closeSplash, this);
}
}
Void csplashwin :: OnRedraw ()
{
// Show a picture when redrawing
IF (pi)
{
FA_DRAWIMAGE (PI, & M_PAPP-> M_RECT, TRUE);
}
}
Boolean Csplashwin :: OnHandleevent (Aeeeevent Ecode, Uint16 WPARAM, UINT32 DWPARAM)
{
/ / Skip to the processing of the keyboard, switch to the main window
IF (ecode == evt_key)
{
m_papp-> setwindow;
}
Return True;
}
In the development, in gradually establishing your own C development library, such as CTJMenuo (menu), cstwin (text) is built from CTJWIN, and the constant rich CTJWIN function function is improved in future development and Restrain. I also hope that everyone will give to the jade. Tang Jian 2004/09/24