Jump to content

WinCreateAtomTable: Difference between revisions

From EDM2
Created page with "This function creates an accelerator table from the accelerator definitions in memory. ==Syntax== WinCreateAccelTable(hab, pacctAccelTable) ==Parameters== ; hab (HAB) - in..."
 
No edit summary
Line 1: Line 1:
This function creates an accelerator table from the accelerator definitions in memory.  
This function creates a private empty atom table.  


==Syntax==
==Syntax==
  WinCreateAccelTable(hab, pacctAccelTable)
  WinCreateAtomTable(ulInitial, ulBuckets);


==Parameters==
==Parameters==
; hab (HAB) - input
;ulInitial (ULONG) - input
: Anchor-block handle.  
:Initial bytes.
:This parameter is ignored for version 3, or higher, of the OS/2 operating system. The ulInitial parameter is dynamically allocated. The initial number of bytes should be set to zero.


;pacctAccelTable (PACCELTABLE) - input
:For versions prior to version 3 of the OS/2 operating system, this parameter is the initial number of bytes to be reserved for the atom table. This is a lower bound on the amount of memory reserved. The amount of memory actually used by an atom table depends upon the actual number of atoms stored in the table. If zero, the size of the atom table is the minimum size needed to store the atom hash table. The minimum size of atom table allocated is 16+(2*ulBuckets).
:Accelerator table.
 
;ulBuckets (ULONG) - input
:Size of the hash table.
:Used to access atoms. If zero, the default value of 37 is used. The best results are achieved if a prime number is used.


==Returns==
==Returns==
; haccelhAccel (HACCEL) - returns
;hatomtblAtomTbl (HATOMTBL) - returns
:Accelerator-table handle.
:Atom-table handle.
:;NULLHANDLE
::Call failed.
:;Other
::Atom-table handle. This must be passed as a parameter in subsequent atom manager calls.


==Remarks==
==Remarks==
This function returns a different haccelhAccel value when called twice in succession with the same parameter values.
The atom table is owned by the process from which this function is issued. It cannot be accessed directly from any other process. If it is still in existence when the process terminates, it will automatically be deleted by the system.
 
There is a system atom table which is created at boot time, which cannot be destroyed, and which can be accessed by any process in the system. The handle of the system atom table is queried with the WinQuerySystemAtomTable function.  


==Example Code==
==Example Code==
This example creates an accelerator-table handle for an in memory accelerator table consisting of 3 accelerator keys, using US codepage 437.  
This example creates an Atom Table of default size, adds the atom "newatom" to the new table, and then destroys the table.  
<pre>
<pre>
#define INCL_WINACCELERATORS    /* Window Accelerator Functions */
#define INCL_WINATOM        /* Window Atom functions                */
#define INCL_WININPUT          /* Key constants                */
#define INCL_WINFRAMEMGR        /* Frame control constants      */
#include <os2.h>
#include <os2.h>


ULONG        ulAccelLen     = 0;         /* Accelerator-table length      */
ATOM     atom;             /* New atom value                        */
HACCEL      hAccel          = NULLHANDLE; /* Accelerator-table handle     */
HATOMTBL  hatomtblAtomTbl;   /* Atom-table handle                     */
PACCELTABLE pacctAccelTable = NULL;       /* Pointer to Accelerator-tab le */
HATOMTBL hatomtblDestroy;   /* Result of destroy table              */
HAB          hab            = NULLHANDLE; /* Anchor block handle          */
char      pszAtomName[10];   /* Atom name                            */
 
ULONG    ulInitial = 0;     /* Initial atom table size (use default) */
ACCEL  acctable[] = {
ULONG    ulBuckets = 0;     /* Size of hash table (use default)     */
        AF_SYSCOMMAND | AF_ALT | AF_VIRTUALKEY,VK_F7,SC_MOVE,
        AF_SYSCOMMAND | AF_ALT | AF_VIRTUALKEY,VK_F8,SC_SIZE,
        AF_SYSCOMMAND | AF_ALT | AF_VIRTUALKEY,VK_F12,SC_CLOSE};
 
        /* Get memory for the Accelerator-table and initialize it. */
 
  ulAccelLen = sizeof( acctable ) + sizeof( ACCELTABLE );
  pacctAccelTable = (PACCELTABLE) malloc ( ulAccelLen );


  pacctAccelTable->cAccel = 3;                /* Number of ACCEL entries */
/* Create an atom table of the default size */
  pacctAccelTable->codepage = 437;            /* Code page */
hatomtblAtomTbl = WinCreateAtomTable(ulInitial, ulBuckets);
  pacctAccelTable->aaccel[0] = acctable[0];    /* ACCEL entries... */
  pacctAccelTable->aaccel[1] = acctable[1];
  pacctAccelTable->aaccel[2] = acctable[2];


  hAccel = WinCreateAccelTable( hab, pacctAccelTable );
/* Define the name of the new atom and add it to the table */
strcpy(pszAtomName,"newatom");
atom = WinAddAtom(hatomtblAtomTbl, pszAtomName);
hatomtblDestroy = WinDestroyAtomTable(hatomtblAtomTbl);
</pre>
</pre>


Definition
Definition
<pre>
<pre>
#define INCL_WINACCELERATORS /* Or use INCL_WIN, INCL_PM, */
#define INCL_WINATOM /* Or use INCL_WIN, INCL_PM, */
#include <os2.h>
#include <os2.h>


HAB            hab;             /*  Anchor-block handle. */
ULONG      ulInitial;       /*  Initial bytes. */
PACCELTABLE    pacctAccelTable; /*  Accelerator table. */
ULONG      ulBuckets;       /*  Size of the hash table. */
HACCEL        haccelhAccel;     /*  Accelerator-table handle. */
HATOMTBL    hatomtblAtomTbl; /*  Atom-table handle. */


haccelhAccel = WinCreateAccelTable(hab, pacctAccelTable);
hatomtblAtomTbl = WinCreateAtomTable(ulInitial, ulBuckets);
</pre>
</pre>


==Related Functions==
==Related Functions==
* WinCopyAccelTable
* WinAddAtom
* WinDestroyAccelTable
* WinDeleteAtom
* WinLoadAccelTable
* WinDestroyAtomTable
* WinQueryAccelTable
* WinFindAtom
* WinSetAccelTable
* WinQueryAtomLength
* WinTranslateAccel
* WinQueryAtomName
* WinQueryAtomUsage
* WinQuerySystemAtomTable


[[Category:Win]]
[[Category:Win]]

Revision as of 02:40, 13 May 2023

This function creates a private empty atom table.

Syntax

WinCreateAtomTable(ulInitial, ulBuckets);

Parameters

ulInitial (ULONG) - input
Initial bytes.
This parameter is ignored for version 3, or higher, of the OS/2 operating system. The ulInitial parameter is dynamically allocated. The initial number of bytes should be set to zero.
For versions prior to version 3 of the OS/2 operating system, this parameter is the initial number of bytes to be reserved for the atom table. This is a lower bound on the amount of memory reserved. The amount of memory actually used by an atom table depends upon the actual number of atoms stored in the table. If zero, the size of the atom table is the minimum size needed to store the atom hash table. The minimum size of atom table allocated is 16+(2*ulBuckets).
ulBuckets (ULONG) - input
Size of the hash table.
Used to access atoms. If zero, the default value of 37 is used. The best results are achieved if a prime number is used.

Returns

hatomtblAtomTbl (HATOMTBL) - returns
Atom-table handle.
NULLHANDLE
Call failed.
Other
Atom-table handle. This must be passed as a parameter in subsequent atom manager calls.

Remarks

The atom table is owned by the process from which this function is issued. It cannot be accessed directly from any other process. If it is still in existence when the process terminates, it will automatically be deleted by the system.

There is a system atom table which is created at boot time, which cannot be destroyed, and which can be accessed by any process in the system. The handle of the system atom table is queried with the WinQuerySystemAtomTable function.

Example Code

This example creates an Atom Table of default size, adds the atom "newatom" to the new table, and then destroys the table.

#define INCL_WINATOM         /* Window Atom functions                 */
#include <os2.h>

ATOM      atom;              /* New atom value                        */
HATOMTBL  hatomtblAtomTbl;   /* Atom-table handle                     */
HATOMTBL  hatomtblDestroy;   /* Result of destroy table               */
char      pszAtomName[10];   /* Atom name                             */
ULONG     ulInitial = 0;     /* Initial atom table size (use default) */
ULONG     ulBuckets = 0;     /* Size of hash table (use default)      */

/* Create an atom table of the default size */
hatomtblAtomTbl = WinCreateAtomTable(ulInitial, ulBuckets);

/* Define the name of the new atom and add it to the table */
strcpy(pszAtomName,"newatom");
atom = WinAddAtom(hatomtblAtomTbl, pszAtomName);
hatomtblDestroy = WinDestroyAtomTable(hatomtblAtomTbl);

Definition

#define INCL_WINATOM /* Or use INCL_WIN, INCL_PM, */
#include <os2.h>

ULONG       ulInitial;        /*  Initial bytes. */
ULONG       ulBuckets;        /*  Size of the hash table. */
HATOMTBL    hatomtblAtomTbl;  /*  Atom-table handle. */

hatomtblAtomTbl = WinCreateAtomTable(ulInitial, ulBuckets);

Related Functions

  • WinAddAtom
  • WinDeleteAtom
  • WinDestroyAtomTable
  • WinFindAtom
  • WinQueryAtomLength
  • WinQueryAtomName
  • WinQueryAtomUsage
  • WinQuerySystemAtomTable