Palmos Development Tutorial - 3

zhaozj2021-02-08  239

The fun in the text box in this chapter, we will study the properties and events of the text box by discussing a copy of the Hello application in Chapter 2. The content involved includes how the text box calls the PALM OS memory and the relationship between them. We will also spend some other content related to text boxes: ◆ Handwriting input conversion indicator ◆ String resources ◆ Special things for editing menu and ordinary menus ◆ Palm OS version Compatible code ◆ What is the error message and the warning text box? The text box is actually an edit box (individually editable), using it you can enter text or data. Let us create a text box and feel the fun of learning. Create an application in the Code Warrior integrated development environment: 1. Run the Code Warrior integrate development environment. 2. Select Menu File | New Project to create a new project. 3. Select the Hello application from the project option and rename the name of your new application. 4. Remove the original resource file from the project. You can do this: Use Right-click Hello.RSRC in the SRC folder to select Remove Selected Items. 5. Remove Hello.RSC in the SRC directory of your project folder. 6. Run a resource constructor to create a resource file. 7. Select the form in the resource list and press CTRL K to create a form named Contact Detail. Click the default name and rename the form. 8. Double-click the form to open the form into the editing state. 9. Drag and drop a text box to the form. You can select menu Window / Catalog to open the directory window. Then drag a text box control from the directory window to the form. 10. Named text box name is firstname. You can do this: Click on the text box to display its properties, a window appears in the left box of the form, click the Object Identifier property, then enter FirstName. 11. In this step, it is best to put the handwriting input conversion indicator (Graffiti Shift Indicators) in your form. Drag a handwritten input conversion indicator from a directory window to the form, the standard position of this converter should be placed in the lower right corner of the form. 12. After pressing the above operation, the form is shown in Figure 3-1. 13. Go back to the Code Warrior integrated development environment, add a new resource file in the project. Check the Project | Add Files command in the Code Warrior integrated development environment. 14. Check the Project | make command to compile the connection item. 15. To the debugger debugging. First attack the live debugger by menu Project | Enable Debugger. 16. Open your Palm and confirm that it is fixed on the bracket. Then turn off the PC's HotSync software. 17. On the PC, select the Project | Debug command. 18. In your device, enter the letter "1", two points "..", and a number "2" (1..2) to start the console program (Console). 19. On the PC, click the OK to start the debugger. 20. Click the forward arrow in the debugger to perform the application. Figure 3-1 The appearance of the form in the program runs the application on Palm, click on the text box, you can enter text or numbers.

If you pick up your right up to the right in the big character status, your handwriting input conversion indicator on the form will expose the arrow or point separately. The application is displayed as shown: When the picture needs to end the application, please remember to click X to restart your device or stop the operation of the console program. Let the console continue to run some problems in Palm. If your handwritten input conversion indicator runs smoothly in the program you just, you can start further understanding it. But if it doesn't work properly, then you need to decide whether there is code in the program to prevent text box events being processed by the operating system. The correct approach is that you can put them in any form, then you can see its use when you handwritten input. It is usually placed in the lower right corner of the form, because people are used to do so. No programs must need it, but it will work in the form in the form. From the above example you can see many things related to the text box at work. The code in the form we run (Hello.c) does not do anything to the form, but we can modify, enter, find, and replace text, and even do what we want to do. Shear and paste do not work here. As for menus and shortcuts, we will come into contact with later chapters. Note: If your Palm has an exception after the debugger operation, it may be because it is not restarted or the console is still running. Please put your Palm, use the tail of the push pin or the end of the clip. Property You can change a lot of content about how to work on the text box in the resource constructor. Turn out the Contact Detail window in the constructor, select the .rsrc file in the project, then double-click the text box in the Contact Detail form, and its properties will appear next to it. All Palm OS User Interface controls have some public properties, like Left Origin and Top Origin. Table 3-1 is a list of all text box properties and descriptions. After familiar with these properties, recompile and debug procedures to test how each attribute affects text box behavior. Table 3-1 Name Description Object Identifier Your Selected Text Box Name. Field ID This value is that Palm OS is used to define a special user interface object. LEFT Origin defines the location of the left boundary of the text box, the entire screen spans 160 pixels. Top ORIGIN defines the position of the boundary on the text box, the entire screen from the top to the bottom 160 pixels. Width text box width pixels. Height text box height pixels, you must add this value to avoid cutting out some of the top of some big fonts. USABLE Defines whether the text box is displayed in the form. The text boxes that are not marked as available are invisible or unselected until they are activated by a feature command. Editable Defines whether the text box is optional or properly handled. For most text boxes, this item has been selected. Underline draws its position on the text box below to display its location. Otherwise, you cannot indicate an empty text box that already exists on the screen. Single Line restrictions to enter a line of text. This text box does not scroll vertically or accepted the input of the carriageway or Tab key. Dynamic Size enables this text box to expand as needed to display all of the input text. You must increase the code to implement, don't worry that it doesn't see its role when changing properties. Left Justified aligns the text left alignment. Do not check the usefulness of the digital display, so the decimal is placed. The maximum number of characters specified in Max Characters, the number of characters that can be entered before the Palm OS is prohibited. The font in the Font text is displayed in the text box. Note that you'd better manually change the height of the text box in accordance with your own font. Auto Shift changes the first letter entered into uppercase. HAS Scroll Bar This option allows the text box to automatically add a scroll bar in the character too much. This will cause the Palm OS to send events, and the user can update the scroll bar display in the event. Numeric allows the input number to transition to character saving.

Talking about the event From the second chapter, it can be learned that Palm OS programs, similar to the Mac OS program and Windows programs are based on event drivers. The program does not have to do anything (most of this) until the user's input arrival, for example, press the button, contact the screen with the input pen or finger. When you use the text box, we care about the following four events. First, PENDOWNEVENT and PENUPEVENT. Every time the screen is in contact with PENDOWNEVENT. Similarly, there is a p enupevent when you enter the screen every time you enter the screen. For users of Palm OS, interface element events, events including text boxes, are converted into calls to the frMdispatChevent () function. For text box event frMdispatchool () functions is actually converted to other three events: FldEnterevent, FldChangeDevent, and KeyDownevent. As long as the text box is tapped, the FldEntereven T is sent. As long as the text box adjusts its appearance, for example, the horizontal roller will send FldChangeDevent. As long as the handwritten input feature is identified and sent to the text box, the keydowne vent is sent. If you don't make an incident, you should return false values ​​in the event processor. In this case, the characteristics of the excellent automatic event I just described are useless. If the T RUE value is returned in the event processor, fRMDispatChevent () processes the next event; if the false value is returned, DispatchEvent () calls frmhandleevent (), the frmHandleEvent () function is the essence of multiple simple events into several complex events. The function. Take the text box event as an example, the F rmhandleevent () function call fldHandleEvent () produced the text box event we just discussed. Unless it is in an abnormal environment, I don't recommend calling the frmhandleev ent () function or the FLDHANDLEVENT () function. When you want to handle a special event, please pay attention to the false value returned from your event handler. Now let's modify the code in the Contacts project, call the new resource that labeled the date. Use the Explorer to copy another Hello.c copy to the S RC folder of the Contacts project. Renown it to Contacts.c, then re-add it to the project by selecting the Project | Add Files command. Use the new contacts_res.h header to replace Hello_RES.H, which contains it in the Contacts.c file. After doing these, in order to make the code can be successfully compiled and connected, you must also change the reference from H Elloform to ContactDetailform. To now, although we are still using the wrong resource file, the program is already working because the ID indicating the Helloform form is the same. The constructor often begins the ID value of the 41000. The other needs to modify is a CASE statement, find the CASE statement that processes the CTLSELECTEVENT event in the program. Here is to find, it indicates that the button is pressed: //ch.2 The Botton Was Pressed Case CtelectEvent; SndPlaySystemSound; return (false); until now, the CASE statement in the Contacts program has not been done yet Finish. Since there is no button in the form, there is no chance to receive the CTLSeleCte event event at all.

Then let us capture the PENDOWNEVENT event by changing the C ASE statement, it will make you more confident. Replace the above Case CTLSelectEvent code: //ch.3 the pen touch Down Case PENDOWNEVENT; SNDPLAYSYSTEMSOUND (SNDAlarm); Return (false); select Project | Make (under Project | Debug) to debug the modified code . Click the Run button in the debug window to run the modified application, when you click on the text box, it may issue only alert sound when the emergency is generated. In fact, Whether you click on the form, you will hear the alarm, because there is a P endownevent event triggered. You can also try to replace PendowNevent to Penupevent, make, Debug, and then run the program. The alarm now is issued when the pen is entered by the pen. Try to replace the Penupevent to Fldenterevent, make, Debug, and run the program. You can find that the alarm sounds in the text box portion of the input pen touching the form. Now we can easily use accurate events to replace unclear events, like p endownevent and penupevent events. This is not only quite simple, but it will give people a feeling of user interface, which is consistent with the style of other Palm OS applications. So, I know that PenDownevent and Penupevent events are very beneficial, but my suggestion is just use in many precise events that are not available. Try to replace Fldenterevent to FldChangeDevent. Make, Debug, and run the application. This time, if you enter a quite a number of characters in the text box, the text box will appear horizontal scroll bars, and the alarm will disappear. Try to replace FldEnterevent to Keydownevent. Make, Debug, and run the application. Now as long as a correct glyph is generated in the input area, the alert will sound. If you have not decided whether you have already entered the correct content before you have entered the correct content, you can see some interesting things. This is not easy to do (at least for me). Note: Playing sounds when the event is generated, is usually a good method, which can correctly see when a special event will happen. This is a good experimental method to help you collect the status of the operating system. Focus has more than 50 Palm OS functions, allowing you to operate text boxes and data you entered in different ways. In the next part, we will handle most basic function calls, you may often use (at least for the text box, not data directly in the database). Text box features cut, copy, delete, paste, and undo the most popular, we will handle these issues when we use the menu and shortcut menu. You need to click on the text box to write characters to the text box. In other words, the text box needs to get the focus to receive input. Let us call the frMsetFocus () function to meet the needs of the focus after clicking the text box. This function must appear tightly with the statement of the drawing form, because the focus function is not functioning before the form appears. Therefore, the most suitable location for it should be after frmdrawform () in p ilotmain (). In order to use the fmsetfocus () function, you must first call the frMGetObjectIndex () function to get the target object index. This way, after you m ake, debug, and run the code, you can see a flashing pointer in the text box before you click on the input.

The new code you join should be as follows: //ch.3 initialize ou form form = frMinitform (contactDetailform); frmseTeventHandler (Form, myHandleevent); frmSetActiveForm (Form); frmdrawform (form); //ch.3 get the index of Our Field INDEX = frMgetObjectIndex (Form, ContactDetailfirstNamefield); //ch.3 set the focus to company Field FRMSETFOCUS (Form, Index); //ch.2 OUR Event Loop DO {text box Enter characters Now we should go in the text box Enter some characters. Before doing this, you need to learn a little knowledge about the text box using Palm OS memory. Once the text box is edited, the database memory is directly edited, and all the operations related to the text box are corresponding to a piece of memory and free to change the size of the memory film. In the terms of P Alm OS, these memory tablets are called a block. The text box requires these special data structures to save the data input data, as this data structure has the characteristics of the size of the input data. Now suppose we have assigned two blocks of memory to two text boxes. The initial size of each block is 8 0 bytes: XXXXXXXXYYYYYYY is like this, if you need to expand the capacity of the first text box to 100 bytes, but because the block allocated by the second text box is tight Holding it below, so there is no space to expand the first memory block. At this time, if we don't prepare to give up, don't limit the text box and do not change the total number of characters, some content will be lost. In order to solve this problem, people extend the concept of Memory Handle. The method of placing the pointer in the memory pointer list instead of the direct return pointer to each assigned memory film. The operating system can use idle time to adjust the position of the block so that the block can be allowed, XXXXXXXXXXXXYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY is to prevent the operating system attempt to move the memory block by locking the memory block. The memory block has been locked in a state before we have not completed the operation. In the previous simple text box example, when we start to join the character to the text box, the Palm OS automatically assigns a memory block to the text box and implements the auto-binding of the memory block and the text box. If you want to get a text box with characters at the beginning of the program, we must first assign a memory block to the text box, enter text to memory, and bind memory with the text box.

Let us join C code in c palacts.c, enabling us to allocate and initialize memory blocks at the beginning of Contacts.c: //ch.3 out; //ch.3 Htext; //ch.3 handle to the text IN Our Edit Field #define htext_size 81 //ch.3 size of our Edit Field //ch.2 The Main Entries Point DWORD PILOTMAIN (Word CMD, PTR, WORD) {Formptr form; //ch.2 a Pointer to Our Form structure charptr ptext; //ch.3 Points to the text in the edit field word index //ch.3 a general purpose index fieldptr field; //ch.3 buy for manipulating field atType Event; //ch.2 OUR event structure //CH.2 If this is not a normal launch do not lauch if (cmd = sysAppLaunchCmdNormalLaunch!) return (0); //CH.3 Allocate our field chunk htext = MemHandleNew (HTEXT_SIZE); if (htext = = NULL) RETURN (0); //ch.3 Lock The Memory, Get The Point PText = MemHandLock (htext); //ch.3 Initialize It Strcopy (PTEXT, "Hello"); //ch.3 Unlock THE Field's Memory MemHandleunlock (HTEXT); you can see the new features of the four Palm OS in the code. MemHandleNew () assigns a memory block. MemHandLock () locks the memory block to prevent the Palm OS mobile memory. Strcopy () is like a C language function strcpy (), which copies a zero-bound string from a place from the memory to another - thus, you can copy a constant value to our memory block. M emHenLock () tells the operating system, we have unlocked a memory block. After this statement, any call to the PTEXT pointer becomes dangerous because the memory block may be moved at any time. MemHandLenew () will return NULL if there is such a tragic event in the PALM device. The above code can make the application quietly exit, but this is far from an ideal solution. In the next chapter you will learn how to send the user who has a warning error to give you. The rest is to throw our memory blocks to the text box.

You can do these work before the drawing, //ch.3 initialize ou form form = frMinitform (ContactDetailform); fmseTeventHandler (Form, myHandleevent); fmsetActiveform (Form); //ch.3 get the index of out @ //ch.3 get the index of out = FrmGetObjectIndex (form, ContactDetailFirstNameField); //CH.3 Get the pointer to our field field = FrmGetObjectPtr (form, index); //CH.3 Set the editable text FldSetTextHandle (field, htext); //CH.2 Draw The form frmdrawform (form); Some skills here are fldsetTextHandle (). In order to call this function, you must have a pointer to the text box. You can call frMGetObjectPtr () to get this pointer. You can see that f ldsetTextHandle () must be called before fmgetObjectPtr (), otherwise the text you enter to the memory block cannot draw on the form part. Call the FldDrawFie LD () to draw the entire form. After adding the code you modified above to Contacts.c, then make Make, Debug, and run your project. The initial value "Hello" will be displayed in the text box. With string resources, we initialize the text box in the program, which has a string that is not easy to encode. For such a small application, string coding may not be a problem, but for large applications, it may cause unpleasant problems. When you are ready to sell your software overseas, you will find you. It is necessary to have endless time spending time on the problem of code, just translating its display portions into other languages. I know that the only way to help you freely use a string resource. String resources are strings stored in your resource file with other interface elements. Many translation companies have the ability to translate your app into other foreign languages, as long as you give them a resource file. So this is a way to translate your app into another language cost. Create a string resource in the resource constructor: 1. Start the resource constructor and open the Contacts.RSRC file. 2. Select the string resource type from the resource list. 3. Press CTRL-K to create a new string resource. And named FieldInit. 4. Double-click to open a new string resource. Enter Hello. To use a string resource in your code, you must get it, lock it, use it when you want to use it, and finally release it.

Codes to achieve the following: //CH.2 If this is not a normal launch, do not launch if (cmd = sysAppLaunchCmdNormalLaunch!) //CH.3 Get the initialization string resource handle hsrc = DmGetResource (strRsc, FieldInitString); // Ch.3 Lock The Resource, Get The Pointer Psrc = MemHandLock (HSRC); //ch.3 Allocate Our Field Chunk HText = MemHandleNew (HTEXT_SIZE); if (htext = null) Return (0); //ch.3 Lock the memory, get the pointer ptext = MemHandleLock (htext); //CH.3 Initialize it StrCopy (ptext, psrc); //CH.3 Unlock the field's memory MemHandleUnlock (htext); //CH.3 Unlock the resource's Memory MemHandleunlock (HSRC); //ch.3 Release The String Resource DMRELESERESSOURCE (HSRC); Modify the above code in Contacts.c. Make, Debug, and results. The program doesn't seem to be different from the original, but now your character is already got from string resources. The menu is now an EDIT menu for the Contacts program. The Palm OS user interface defines a standard EDIT menu as long as you provide a text box, it can be entered and edited. This menu is displayed as follows: Figure first constructing the resource section of the menu: 1. Start the resource constructor and open the Contacts.RSRC file. 2. Click on the list of menu items from the resource list. Press CTRL-K to create a menu. And named Contact Detail. 3. Double-click Open the Contact Detail menu bar resource. Press CTRL-M to create a new menu. 4. Change the name on the menu bar and change the unsil to Edit. 5. Press CTRL-K to create a new menu entry. Enter UNDO. Press the Tab button to reach the menu entry. Enter U. Continue this process, create each new menu entry, just as shown in the previous example. You can use C TRL-connect numbers (-) to create partitions between SELECT ALL and KeyBoard. 6. When you create a menu, double-click Open the Contact Detail form. Enter the ID number of the menu in the MENU BAR ID attribute bar (possibly 1000). 7. The above work has completed the creation of the menu bar resource, which looks like a standard EDIT menu in the previous example. In order to use the menu you just created, you must add some code in Contacts.c. To deal with menu events, you must add a function call called MemuHandleevent () to process the menu event in the event loop. //CH.2 Handle system events if (SysHandleEvent (& event)) continue; //CH.3 Handle menu events if (MenuHandleEvent (NULL, & event, & error)) contiue; //CH.2 Handle form events FrmDispatchEvent (& event) In the loop of your event processor, replace the CTLSELECTEVENT call with a menuevent function call. Use it to call a function called MenueventHandler ().

Now your new event processor looks like this: //ch.2 Our form Handler Function Static Boolean myHandleRevent (EventType * Event) {//ch.3 Parse menu Events if (Event-> ETYPE = = MenueVent) Return (MenueventHandler (Event); //ch.2 We're Done Return (false);} Now to write a menueventhandler () function. First, you must send a signal to the user interface, report menu events have been received: //ch.3 handle menu Events Boolean MenueventHandler (eventptr80) {Formptr Form ////ch.3 a Pointer to Our Form Structure Word Index //CH .2 A general purpose control index FieldPtr field; //CH.3 Used for manipulating fields //CH.3 Get our form pointer form = FrmGetActiveForm (); //CH.3 Erase the menu status from the display MenuEraseStatus (NULL) Provide a separate input area help. This is because the input area help should be available, regardless of whether the text box is currently selected. //CH.3 Handle graffiti help if (event-> data.menu.itemID = = EditGraffitiHelp) {//CH.3 Pop up the graffiti reference based on // the graffiti state SysGraffitiReferenceDialog (referenceDefault); return (true); } Next, you can call those very good editing commands after you get the text box pointer. The following example shows a text box pointer with the most common method, which we used in previous C ASE FRMOPENEVENT: Regardless of how many text boxes on the form, it works. //Ch.3 get the index of outfocus (form); //ch.3 if there is no field selected, we're done if (index = = nofocus) return (false); // ch. 3 get the pointer of out u el = frMgetObjectptr (Form, Index); Now we can execute the edit command. Calling these editing functions is very simple and they handle everything. If you do the select all command, you can pass the entire string to the fldsetSelection () function.

//Ch.3 do the Edit Command Switch (Event-> Data.Menu.Itemid) {//ch.3 undo Case Editundo; Fldo (Field); Break; //ch.3 Cut Case Editcut; FLDCUT (Field) Break; //ch.3 Copy Case Editcopy; FldCopy; Break; //ch.3 Paste Case EditPaste; FLDPASTE (Field); Break; //ch.3 Select All Case Editslect All; {//C .3 get the length of the string in the field word length = fldgettextLength (field); //ch.3 select the whole string fldsetSelection (Field, 0, Length);} Break; //ch.3 Bring Up The Kdyboard Tool Case EditKeyboard; syskeyboarddialog (kbddefault); Break;} //ch.3 We're Done RERN (TRUE);} After the above modification, make, debug, and run your application. You can use the created menu and shortcuts. Supports a variety of different versions of Palm OS in fact, if the code is listed if Pilot 1000 or Pilot 1500 is running on the system that uses PALM OS1.0 version, the system will crash. This is because in version 1.0, syskeyboarddialog () is one different function call. But there are several ways to solve this problem. The first choice is to replace the call function S YskeyboardDialogv10 (), which is a backward compatible function. In addition to the latest system commands, if you still want to know more, you need to check the version of the OS, which can be based on the OS version to correctly call the function. If we have encountered serious consequences from the OS version, we will become more practiced when programming. Now use SyskeyBoardDialogv10 () to replace this syske yboarddialog () function call. //Ch.3 Bring Up The keyboard; syskeyboarddialogv10 (); break; errors and warning Contacts programs have extended its use range, and some of the operations you do may result in errors. It is now an excellent time to discuss the error handling. If you perform an edit command, you can find that if you do something meaningless, you can copy a warning when you copy any text, the editing function will also generate a warning. Not just s elect all, because you have called an ordinary function, even if there is no error, it will also make a sound. In order to make SELECT ALL in line with other functions, you can join a SndPlaySystemSound () function: //ch.3 Select All case Editslectall {//ch.3 get the length of the string in the field word length = fldgetTextLength (Field); //ch.3 Sound An error if appropriate if (legth = 0) {SNDPLAYSYSTEMSOUND (SNDERR); Return (false);} //ch.3 Select the whole string fldsetSelection (Field, 0, Length) [} When the user's input exceeds the function of the modulated function, you should prompt to what they may do something wrong.

In this regard, there is a good solution that uses Alerts. Alerts `is very convenient for cocovered forms controlled by operating system. For a test: Create an ALERT resource to display the error message of the select all command: 1. Start the resource constructor. 2. Select Alert from the resource type list. 3. Press CTRL-K to create a new warning. 4. Double click to open a warning. 5. Change the message property like "There Was NO Text to SELECT." 6. Change the title attribute of Error. 7. Change the warning type attribute of Error. To call these Alert, we join the frMalert () function. You can get the variable name of the warning ID from the Contacts_RES.H file. //Ch.3 POP UP an Error if Appropriate if (length = = 0) {SndPlaySystemSound (SNDERROR); frmarert (SELECTALLERRORALERT); return (false);} After adding the above code, make, debug, and run the application. It can be found that since we set a warning type to the error, there is twice apered: a from SndPlaySyst EMSound (), a warning. Another one we have to place Alert, at least a place where the system beep is, just when we check the focus. In fact, when the application of the sleep state is awakened, the text box is the preferred control of the focus. Under normal circumstances we want to send a classic system beep at this time to inform users. Since the error prompt of SELECT ALL does not often appear, let us remove this Alert resource. In the later chapter, we use the Alert to inform users of a variety of different error signals. What is the next step? In the next chapter, we will study how you have multiple forms in your application. Program list Here is a full Contacts.c program list. Courses change from hello.c Use //ch.3 annotations.

//Ch.2 the super-incrude for the palm OS #include //ch.3 out.3 file file #include "contacts_res.h" // ch.2 prototypes for out lent handler functions static boolean myhandleevent (eventptr energy); static Boolean MenueventHandler (Eventptr Event); //ch.3 Our Field Memory Handle Static Htext; //ch.3 Handle To The Text In Our Edit Field #define Htext_size 81 // Ch.3 Size Our Edit Field //C .2 The main entry point dWord Pilotmain (Word EMD, PTR, WORD) {Formptr form; //ch.2 a Pointer To Our form structure * / handle hsrc; //ch.3 handle to the string resource charptr psrc; / /Ch.3 Points to the text ;//ch.3 Points to the text in The Edit Field Word Index; //ch.3 a general purpose index fieldptr field; //ch.3 buy for manipulating Fields eventtype event; //ch.2 OUR Ent structure word error; //ch.3 Error Word for menu Event Handler //ch.2 if this in not a normal launch, do't launch if (cmd! = sysapplaunchcmdnormaunch) Return (0); //ch.3 get the initializati on string resource handle hsrc = DmGetResource (strRsc, FieldInitString); //CH.3 Lock the resource, get the pointer psrc = MemHandleLock (hsrc); //CH.3 Allocate our field chunk htext = MemHandleNew (HTEXT_SIZE); if ( HTEXT = = null) Return (0); //ch.3 Lock The Resource, Get The Point PTEXT = MemHandLock (htext); //ch.3 Initialize It Strcopy (PTEXT, PSRC); //ch.3 Unlock THE field's memory MemHandleUnlock (htext); //CH.3 Unlock the resource's memory MemHandleUnlock (hsrc); //CH.3 Release the string resource DmReleaseResource (hsrc); //CH.2 Initialize our form form = FrmInitForm (ContactDetailForm); FRMSETEVENTHANDLER (Form, myHandleevent); fmsetAndactiveform (Form); //ch.3 get the index of inefield index =

FrmGetObjectIndex (form, ContactDetailFirstNameField); //CH.3 Get the pointer to our field field = FrmGetObjectPtr (form, index); //CH.3 Set the editable text FldSetTextHandle (field, htext); //CH.2 Draw the Form frmdrawform (form); //ch.3 set the focus to company, index); //ch.2 u gT loop do {//ch.2 get the next event evtgetEvent (& envet, -1) ; //CH.2 Handle system events if (SysHandleEvent (& event)) continue; //CH.3 Handle menu events if (MenuHandleEvent (NULL, & event, & error)) continue; //CH.2 Handle form events FrmDispatchEvent (& event ); //Ch.2 if it's a stop event, exit} while (event, eType! = Appstopevent); //ch.2 we're done return (0);} //ch.2 Our form handler function static Boolean myHandleevent (Eventype * Event) {//ch.3 Parse menu Events if (Event-> ETYPE = = MENUEVENT) RETURN (MenUEventHandler (Event)); //ch.2 we're done return (false);} / /Ch.3 Handle Menu Events Boolean MenueventHandler (eventptr form; //ch.3 a Pointer to Our Form Structure Word Index; //ch.3 a general purpose control index FieldPtr field; //CH.3 Used for manipulating fields //CH.3 Get our form pointer form = FrmGetActiveForm (); //CH.3 Erase the menu status from the display MenuEraseStatus (NULL); // cH.3 Handle graffiti help if (event-> data.menu.itemID = = EditGraffitiHelp) {//CH.3 Pop up the graffiti reference based on // the graffiti state SysGraffitiReferenceDialog (referenceDefault); Return (true);} / /Ch.3 get the index of outfocus (form); //ch.3 if there is no field selected, we're done if (index = = nofocus) return (false); //ch.3 Get the Pointer of Our Fiedl Field = frMgetObjectptr (Form, Index); //ch.3 do the edt command switch (event->

转载请注明原文地址:https://www.9cbs.com/read-2721.html

New Post(0)