📄 diasample.c
字号:
WinSetBounds (FrmGetWindowHandle(frmP), &displayBounds);
//
MaintFormResizeForm(frmP, &curBounds, &displayBounds);
FrmDrawForm(frmP);
handled = true;
break;
}
}
return handled;
}
void PrefInit (void)
{
FormType * frmP;
ControlType * cbox = NULL;
FieldType * field = NULL;
UInt16 controlID = 0;
MemHandle handle = 0;
/* Clear the menu status from the display */
MenuEraseStatus(0);
/* Initialize the preference form. */
frmP = FrmGetActiveForm ();
/*
* Set the controls in the preference dialog to reflect our
* preference data structure
*/
cbox = (ControlType *)FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, PrefsSetting1Checkbox));
if (cbox)
CtlSetValue(cbox, g_prefs.pref1);
field = (FieldType *)FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, PrefsSetting2Field));
if (field && (g_prefs.pref2[0] != '\0'))
{
MemPtr text = NULL;
UInt32 len = StrLen(g_prefs.pref2);
handle = FldGetTextHandle(field);
if (!handle)
handle = MemHandleNew(len + 1);
else
MemHandleResize(handle, len + 1);
text = MemHandleLock(handle);
if (text)
StrCopy((char *)text, g_prefs.pref2);
MemHandleUnlock(handle);
FldSetTextHandle(field, handle);
handle = 0;
}
}
void PrefApply(void)
{
/*
* The user hit the OK button. Get the value of the controls
* and store them in our pref struct
*/
ControlType * cbox = NULL;
FieldType * field = NULL;
MemHandle handle = 0;
FormType * frmP;
frmP = FrmGetActiveForm();
cbox = (ControlType *)FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, PrefsSetting1Checkbox));
if (cbox)
g_prefs.pref1 = CtlGetValue(cbox);
if (field)
{
handle = FldGetTextHandle(field);
if (handle)
{
MemPtr text = MemHandleLock(handle);
if (text)
{
/* Guard against the field text being longer than our pref's buffer */
UInt32 len = StrLen((const char *)text);
UInt32 count = (len > (sizeof(g_prefs.pref2) - 1)) ? (sizeof(g_prefs.pref2) - 1) : len;
MemMove(g_prefs.pref2, text, count);
g_prefs.pref2[count] = '\0';
}
MemHandleUnlock(handle);
}
}
}
static Boolean PrefsFormHandleEvent(EventType * event)
{
FormPtr frm;
Boolean handled = false;
if (event->eType == ctlSelectEvent)
{
switch (event->data.ctlSelect.controlID)
{
case PrefsOKButton:
PrefApply ();
FrmGotoForm (MainForm);
handled = true;
break;
case PrefsCancelButton:
FrmGotoForm (MainForm);
handled = true;
break;
}
}
else if (event->eType == frmOpenEvent)
{
frm = FrmGetActiveForm ();
PrefInit ();
FrmDrawForm (frm);
FrmSetFocus (frm, FrmGetObjectIndex (frm, PrefsSetting2Field));
handled = true;
}
else if (event->eType == winDisplayChangedEvent)
{
RectangleType curBounds,displayBounds;
// get the current bounds for the form
frm = FrmGetActiveForm();
WinGetBounds (FrmGetWindowHandle(frm), &curBounds);
// get the new display window bounds
WinGetBounds(WinGetDisplayWindow(), &displayBounds);
// This should be added here.
WinSetBounds (FrmGetWindowHandle(frm), &displayBounds);
//
PerfsFormResizeForm(frm, &curBounds, &displayBounds);
FrmDrawForm(frm);
handled = true;
}
return (handled);
}
/*
* FUNCTION: AppHandleEvent
*
* DESCRIPTION:
*
* This routine loads form resources and set the event handler for
* the form loaded.
*
* PARAMETERS:
*
* event
* a pointer to an EventType structure
*
* RETURNED:
* true if the event was handled and should not be passed
* to a higher level handler.
*/
static Boolean AppHandleEvent(EventType * eventP)
{
UInt16 formId;
FormType * frmP;
WinHandle formWinH;
Err err;
#if 0
if (eventP->eType == frmLoadEvent)
{
/* Load the form resource. */
formId = eventP->data.frmLoad.formID;
frmP = FrmInitForm(formId);
FrmSetActiveForm(frmP);
/*
* Set the event handler for the form. The handler of the
* currently active form is called by FrmHandleEvent each
* time is receives an event.
*/
switch (formId)
{
case MainForm:
FrmSetEventHandler(frmP, MainFormHandleEvent);
break;
}
return true;
}
#endif
if (eventP->eType == frmLoadEvent) {
// Load the form resource.
formId = eventP->data.frmLoad.formID;
frmP = FrmInitForm(formId);
FrmSetActiveForm(frmP);
// Set the same policy for each form in application.
err = FrmSetDIAPolicyAttr(frmP, frmDIAPolicyCustom);
// Enable the input trigger
err = PINSetInputTriggerState(pinInputTriggerEnabled);
formWinH = FrmGetWindowHandle (frmP);
// Set the event handler for the form, and set each form’s
// size requirements.
switch (formId) {
case MainForm:
FrmSetEventHandler(frmP, MainFormHandleEvent);
WinSetConstraintsSize(formWinH, 80, 160, 225,
160, 160, 160);
break;
case PrefsForm:
FrmSetEventHandler(frmP, PrefsFormHandleEvent);
WinSetConstraintsSize(formWinH, 100, 160, 225,
160, 160, 160);
break;
default:
break;
}
return true;
}
return false;
}
/*
* FUNCTION: AppEventLoop
*
* DESCRIPTION: This routine is the event loop for the application.
*/
static void AppEventLoop(void)
{
UInt16 error;
EventType event;
do
{
/* change timeout if you need periodic nilEvents */
EvtGetEvent(&event, evtWaitForever);
if (! SysHandleEvent(&event))
{
if (! MenuHandleEvent(0, &event, &error))
{
if (! AppHandleEvent(&event))
{
FrmDispatchEvent(&event);
}
}
}
} while (event.eType != appStopEvent);
}
/*
* FUNCTION: AppStart
*
* DESCRIPTION: Get the current application's preferences.
*
* RETURNED:
* errNone - if nothing went wrong
*/
static Err AppStart(void)
{
UInt16 prefsSize;
/* Read the saved preferences / saved-state information. */
prefsSize = sizeof(g_prefs);
if (PrefGetAppPreferences(
appFileCreator, appPrefID, &g_prefs, &prefsSize, true) ==
noPreferenceFound)
{
/* no prefs; initialize pref struct with default values */
g_prefs.pref1 = false;
g_prefs.pref2[0] = '\0';
}
return errNone;
}
/*
* FUNCTION: AppStop
*
* DESCRIPTION: Save the current state of the application.
*/
static void AppStop(void)
{
/*
* Write the saved preferences / saved-state information. This
* data will be saved during a HotSync backup.
*/
PrefSetAppPreferences(
appFileCreator, appPrefID, appPrefVersionNum,
&g_prefs, sizeof(g_prefs), true);
/* Close all the open forms. */
FrmCloseAllForms();
}
/*
* FUNCTION: RomVersionCompatible
*
* DESCRIPTION:
*
* This routine checks that a ROM version is meet your minimum
* requirement.
*
* PARAMETERS:
*
* requiredVersion
* minimum rom version required
* (see sysFtrNumROMVersion in SystemMgr.h for format)
*
* launchFlags
* flags that indicate if the application UI is initialized
* These flags are one of the parameters to your app's PilotMain
*
* RETURNED:
* error code or zero if ROM version is compatible
*/
static Err RomVersionCompatible(UInt32 requiredVersion, UInt16 launchFlags)
{
UInt32 romVersion;
/* See if we're on in minimum required version of the ROM or later. */
FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);
if (romVersion < requiredVersion)
{
if ((launchFlags &
(sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp)) ==
(sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp))
{
FrmAlert (RomIncompatibleAlert);
/* Palm OS versions before 2.0 will continuously relaunch this
* app unless we switch to another safe one. */
if (romVersion < kPalmOS20Version)
{
AppLaunchWithCommand(
sysFileCDefaultApp,
sysAppLaunchCmdNormalLaunch, NULL);
}
}
return sysErrRomIncompatible;
}
return errNone;
}
/*
* FUNCTION: PilotMain
*
* DESCRIPTION: This is the main entry point for the application.
*
* PARAMETERS:
*
* cmd
* word value specifying the launch code.
*
* cmdPB
* pointer to a structure that is associated with the launch code
*
* launchFlags
* word value providing extra information about the launch.
*
* RETURNED:
* Result of launch, errNone if all went OK
*/
UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
{
Err error;
UInt32 version;
error = RomVersionCompatible (ourMinVersion, launchFlags);
if (error) return (error);
switch (cmd)
{
case sysAppLaunchCmdNormalLaunch:
error = FtrGet(pinCreator, pinFtrAPIVersion, &version);
if (!error && version) {
//PINS exists
}
error = AppStart();
if (error)
return error;
/*
* start application by opening the main form
* and then entering the main event loop
*/
FrmGotoForm(MainForm);
AppEventLoop();
AppStop();
break;
// used for Version 1.0 of the Pen Input Manager only.
case sysAppLaunchCmdNotify:
if (((SysNotifyParamType*) cmdPBP)->notifyType ==
sysNotifyDisplayResizedEvent)
{
EventType resizedEvent;
MemSet(&resizedEvent, sizeof(EventType), 0);
//add winDisplayChangedEvent to the event queue
resizedEvent.eType = winDisplayChangedEvent;
EvtAddUniqueEventToQueue(&resizedEvent, 0, true);
}
break;
}
return errNone;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -