📄 hello.c
字号:
#include <Pilot.h>
#include "hello.h"
static FieldPtr SetFieldTextFromHandle(Word fieldID, Handle txtH)
{
Handle oldTxtH;
FormPtr frm=FrmGetActiveForm();
FieldPtr fldP;
// get the field and the field's current text handle.
fldP =FrmGetObjectPtr(frm,FrmGetObjectIndex(frm,fieldID));
ErrNonFatalDisplayIf(!fldP, "missing field");
oldTxtH = FldGetTextHandle(fldP);
// set the field's text to the new text.
FldSetTextHandle(fldP, txtH);
FldDrawField(fldP);
// free the handle AFTER we call FldSetTextHandle().
if (oldTxtH)
MemHandleFree( (VoidHand) oldTxtH );
return fldP;
}
// Allocates new handle and copies incoming string
static FieldPtr SetFieldTextFromStr(Word fieldID, CharPtr strP)
{
Handle txtH;
// get some space in which to stash the string
txtH = (Handle) MemHandleNew(StrLen(strP)+1);
if (!txtH)
return NULL;
// copy the string to the locked handle.
StrCopy(MemHandleLock( (VoidHand) txtH),strP);
// unlock the string handle.
MemHandleUnlock( (VoidHand) txtH);
// set the field to the handle
return SetFieldTextFromHandle(fieldID, txtH);
}
static void ClearFieldText(Word fieldID)
{
SetFieldTextFromHandle(fieldID, NULL);
}
static Word MyAlert(void)
{
FormPtr previousForm=FrmGetActiveForm();
FormPtr frm = FrmInitForm(formAlert);
Word hitButton;
FrmSetActiveForm(frm);
hitButton=FrmDoDialog(frm);
if (previousForm)
FrmSetActiveForm(previousForm);
FrmDeleteForm(frm);
return hitButton;
}
static Boolean HelloFormEventHandler(EventPtr event)
{
Boolean handled = false;
switch (event->eType) {
case ctlSelectEvent:
if (event->data.ctlSelect.controlID==cmdButton1)
{
ClearFieldText(cmdField);
}
if (event->data.ctlSelect.controlID==cmdButton2)
{
SetFieldTextFromStr(cmdField, "gGgGg");
}
if (event->data.ctlSelect.controlID==cmdButton3)
{
// This example simply removes any uppercase characters in the field
FormPtr frm=FrmGetActiveForm();
FieldPtr fld;
Handle h;
// get the field and the field's current text handle.
fld = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, cmdField));
h=FldGetTextHandle(fld);
if (h)
{
CharPtr s;
FldSetTextHandle(fld, NULL);
s = MemHandleLock( (VoidHand) h);
// change contents of s
while (*s != '\0')
{
if (*s >= 'A' && *s <= 'Z')
StrCopy(s, s+1);
else
s++;
}
MemHandleUnlock( (VoidHand) h);
FldSetTextHandle(fld,h);
FldDrawField(fld);
}
}
handled=true;
break;
case frmOpenEvent:
FrmDrawForm(FrmGetActiveForm());
handled = true;
break;
case menuEvent:
if(event->data.menu.itemID==cmdMenu_1)
SndPlaySystemSound(sndInfo);
else
SndPlaySystemSound(sndStartUp);
handled=true;
break;
}
return (handled);
}
static Boolean ApplicationHandleEvent(EventPtr event)
{
FormPtr form;
Word formID;
Boolean handled = false;
if (event->eType == frmLoadEvent) {
formID = event->data.frmLoad.formID;
form = FrmInitForm(formID);
FrmSetActiveForm(form);
switch (formID) {
case formID_hello:
FrmSetEventHandler(form, HelloFormEventHandler);
break;
}
handled = true;
}
return (handled);
}
static void StartApplication()
{
FrmGotoForm(formID_hello);
}
static void EventLoop(void)
{
short err;
int formID;
FormPtr form;
EventType event;
do {
EvtGetEvent(&event, evtWaitForever);
if (SysHandleEvent(&event)) continue;
if (MenuHandleEvent(NULL, &event, &err)) continue;
if (ApplicationHandleEvent(&event)) continue;
FrmDispatchEvent(&event);
} while (event.eType != appStopEvent);
}
static void StopApplication(void)
{
FrmCloseAllForms();
}
DWord PilotMain (Word cmd, Ptr cmdPBP, Word launchFlags)
{
if (cmd == sysAppLaunchCmdNormalLaunch) {
StartApplication();
EventLoop();
StopApplication();
}
return (0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -