Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

333 lines
10 KiB

  1. /*
  2. OLE SERVER DEMO
  3. SrvrDemo.h
  4. This file contains typedefs, defines, global variable declarations, and
  5. function prototypes.
  6. (c) Copyright Microsoft Corp. 1990 - 1992 All Rights Reserved
  7. */
  8. /*
  9. Explanation of Function Comments.
  10. Every function has a comment preceding it which gives the following
  11. information:
  12. 1) Function name.
  13. 2) A description of what the function does.
  14. 3) A list of parameters, each with its type and a short description.
  15. 4) A list of return values, each with an explanation of the condition that
  16. will cause the function to return that value.
  17. 5) A customization section giving tips on how to customize this function
  18. for your OLE application.
  19. If the customization section says "None" then you may find the function
  20. usable as is.
  21. If the customization section says "Re-implement" then the function
  22. should still serve the same purpose and do what is indicated in the
  23. function comment, but will probably need to be re-implemented for
  24. your particular application. Any Server Demo code relating to OLE
  25. will be useful as a guide in your re-implementation.
  26. If the customization section says "Server Demo specific" then the
  27. function will probably have no counterpart in your application.
  28. */
  29. /* Menu Identifiers */
  30. // File menu
  31. #define IDM_NEW 100
  32. #define IDM_OPEN 101
  33. #define IDM_SAVE 102
  34. #define IDM_SAVEAS 103
  35. #define IDM_EXIT 104
  36. #define IDM_ABOUT 105
  37. #define IDM_UPDATE 106
  38. // Edit menu
  39. #define IDM_CUT 107
  40. #define IDM_COPY 108
  41. #define IDM_DELETE 109
  42. // Color menu
  43. #define IDM_RED 110
  44. #define IDM_GREEN 111
  45. #define IDM_BLUE 112
  46. #define IDM_WHITE 113
  47. #define IDM_GRAY 114
  48. #define IDM_CYAN 115
  49. #define IDM_MAGENTA 116
  50. #define IDM_YELLOW 117
  51. // New object menu
  52. #define IDM_NEWOBJ 118
  53. #define IDM_NEXTOBJ 119
  54. #define IDD_CONTINUEEDIT 120
  55. #define IDD_UPDATEEXIT 121
  56. #define IDD_TEXT 122
  57. #define OBJECT_WIDTH 120
  58. #define OBJECT_HEIGHT 60
  59. // number HIMETRIC units per inch
  60. #define HIMETRIC_PER_INCH 2540
  61. /* Types */
  62. // Document type
  63. typedef enum
  64. {
  65. doctypeNew, // The document is untitled.
  66. doctypeFromFile, // The document exists in a file and may be linked.
  67. doctypeEmbedded // The document is an embedded document.
  68. } DOCTYPE;
  69. // Device context type, passed to DrawObj.
  70. typedef enum
  71. {
  72. dctypeScreen,
  73. dctypeBitmap,
  74. dctypeMetafile,
  75. dctypeEnhMetafile
  76. } DCTYPE ;
  77. // Version
  78. typedef WORD VERSION;
  79. // Verb
  80. typedef enum
  81. {
  82. verbPlay = OLEVERB_PRIMARY,
  83. verbEdit
  84. } VERB;
  85. // Server structure
  86. typedef struct
  87. {
  88. OLESERVER olesrvr; // This must be the first field so that
  89. // an LPOLESERVER can be cast to a SRVR*.
  90. LHSERVER lhsrvr; // Registration handle
  91. } SRVR ;
  92. // How many objects (distinct numbers) will we allow?
  93. #define cfObjNums 20
  94. // How many distinct clients can be associated with the object?
  95. #define clpoleclient 20
  96. // Document structure
  97. typedef struct
  98. {
  99. OLESERVERDOC oledoc; // This must be the first field so that an
  100. // LPOLESERVERDOC can be cast to an DOC*.
  101. LHSERVERDOC lhdoc; // Registration handle
  102. DOCTYPE doctype; // Document type
  103. ATOM aName; // Document name
  104. HPALETTE hpal; // Handle to a logical color palette
  105. BYTE rgfObjNums[cfObjNums+1]; // What object numbers have been used
  106. } DOC, *DOCPTR ;
  107. // Native data structure
  108. typedef struct
  109. {
  110. INT idmColor;
  111. INT nWidth;
  112. INT nHeight;
  113. INT nX;
  114. INT nY;
  115. INT nHiMetricWidth; // Used by an object handler. These two fields
  116. INT nHiMetricHeight; // always correspond to nWidth and nHeight.
  117. VERSION version;
  118. CHAR szName[10]; // "Object nn"
  119. } NATIVE, FAR *LPNATIVE;
  120. // Object structure
  121. /* Ordinarily, an OBJ structure would not contain native data. Rather, it
  122. would contain a pointer (or some other reference) to the native data.
  123. This method would allow multiple objects containing the same native data.
  124. Each OBJ structure would be created on the fly when some portion of the
  125. document was to be made into an object. Each OBJ structure would have
  126. only one LPOLECLIENT, which would be passed in to DocGetObject.
  127. */
  128. typedef struct
  129. {
  130. OLEOBJECT oleobject; // This must be the first field so that an
  131. // LPOLEOBJECT can be cast to a LPOBJ.
  132. HANDLE hObj; // A circular handle to this structure,
  133. // used to delete this structure.
  134. LPOLECLIENT lpoleclient[clpoleclient];
  135. // Clients associated with the object.
  136. // The array is NULL terminated.
  137. HWND hwnd; // The object's own window
  138. ATOM aName; // Unique identifier for each object within a doc
  139. HPALETTE hpal; // Logical palette to use in drawing object
  140. NATIVE native; // Object data in native format
  141. } OBJ, FAR *LPOBJ ;
  142. typedef struct {
  143. CHAR *pClassName;
  144. CHAR *pFileSpec;
  145. CHAR *pHumanReadable;
  146. CHAR *pExeName;
  147. } CLASS_STRINGS;
  148. /* Defines */
  149. // The name of the application, used in message boxes and title bars.
  150. #define szAppName "Server Demo"
  151. // THe class name in the registration database.
  152. #define szClassName "ServerDemo"
  153. // Used to check for "-Embedding" on command line.
  154. #define szEmbeddingFlag "Embedding"
  155. // Maximum length of a fully-qualified pathname.
  156. #define cchFilenameMax 256
  157. // Maximum number of HBRUSHes.
  158. #define chbrMax 9
  159. // Number of extra bytes in the window structure for an object
  160. #define cbWindExtra 4
  161. // Offset (in the extra space) of the pointer to the object
  162. #define ibLpobj 0
  163. /* Global variable declarations. (See SrvrDemo.c for descriptions.) */
  164. extern HANDLE hInst;
  165. extern HWND hwndMain;
  166. extern SRVR srvrMain;
  167. extern DOC docMain;
  168. extern BOOL fDocChanged;
  169. extern BOOL fEmbedding;
  170. extern BOOL fRevokeSrvrOnSrvrRelease;
  171. extern BOOL fWaitingForDocRelease;
  172. extern BOOL fWaitingForSrvrRelease;
  173. extern BOOL fUnblock;
  174. extern CHAR szClient[];
  175. extern CHAR szClientDoc[];
  176. extern HBRUSH hbrColor[chbrMax];
  177. extern VERSION version;
  178. extern OLECLIPFORMAT cfObjectLink;
  179. extern OLECLIPFORMAT cfOwnerLink;
  180. extern OLECLIPFORMAT cfNative;
  181. extern OLESERVERDOCVTBL docvtbl;
  182. extern OLEOBJECTVTBL objvtbl;
  183. extern OLESERVERVTBL srvrvtbl;
  184. /* Function Prototypes */
  185. // Various functions
  186. BOOL CreateDocFromFile (LPSTR lpszDoc, LHSERVERDOC lhdoc, DOCTYPE doctype);
  187. BOOL CreateNewDoc (LONG lhdoc, LPSTR lpszDoc, DOCTYPE doctype);
  188. LPOBJ CreateNewObj (BOOL fDoc_Changed);
  189. VOID CutOrCopyObj (BOOL fOpIsCopy);
  190. VOID DestroyDoc (VOID);
  191. VOID DestroyObj (HWND hwnd);
  192. VOID DeviceToHiMetric ( LPPOINT lppt);
  193. VOID EmbeddingModeOff (VOID) ;
  194. VOID EmbeddingModeOn (VOID);
  195. VOID UpdateFileMenu (INT);
  196. VOID ErrorBox (CHAR *jwf);
  197. BOOL GetFileOpenFilename (LPSTR lpszFilename);
  198. BOOL GetFileSaveFilename (LPSTR lpszFilename);
  199. VOID HiMetricToDevice ( LPPOINT lppt);
  200. LPOBJ HwndToLpobj (HWND hwndObj);
  201. BOOL InitServer (HWND hwnd, HANDLE hInst);
  202. VOID InitVTbls (VOID);
  203. BOOL OpenDoc (VOID);
  204. VOID PaintObj (HWND hwnd);
  205. OLESTATUS RevokeDoc (VOID);
  206. VOID RevokeObj (LPOBJ lpobj);
  207. INT SaveChangesOption (BOOL *pfUpdateLater);
  208. BOOL SaveDoc (VOID);
  209. BOOL SaveDocAs (VOID);
  210. VOID SavedServerDoc (VOID);
  211. LPOBJ SelectedObject (VOID);
  212. HWND SelectedObjectWindow (VOID);
  213. VOID SendDocMsg (WORD wMessage );
  214. VOID SendObjMsg (LPOBJ lpobj, WORD wMessage);
  215. VOID SetTitle (LPSTR lpszDoc, BOOL bEmbedded);
  216. VOID SetHiMetricFields (LPOBJ lpobj);
  217. VOID SizeClientArea (HWND hwndMain, RECT rectReq, BOOL fFrame);
  218. VOID SizeObj (HWND hwnd, RECT rect, BOOL fMove);
  219. OLESTATUS StartRevokingServer (VOID);
  220. VOID Wait (BOOL *pf);
  221. LPSTR Abbrev (LPSTR lpsz);
  222. BOOL APIENTRY fnFailedUpdate (HWND, UINT, WPARAM, LONG);
  223. int Main(USHORT argc, CHAR **argv) ;
  224. // Window handlers
  225. BOOL APIENTRY About (HWND, UINT, WPARAM, LPARAM);
  226. LONG APIENTRY MainWndProc (HWND, UINT, WPARAM, LPARAM);
  227. LONG APIENTRY ObjWndProc (HWND, UINT, WPARAM, LPARAM);
  228. // Server methods
  229. OLESTATUS APIENTRY SrvrCreate (LPOLESERVER, LHSERVERDOC, OLE_LPCSTR, OLE_LPCSTR, LPOLESERVERDOC FAR *);
  230. OLESTATUS APIENTRY SrvrCreateFromTemplate (LPOLESERVER, LHSERVERDOC, OLE_LPCSTR, OLE_LPCSTR, OLE_LPCSTR, LPOLESERVERDOC FAR *);
  231. OLESTATUS APIENTRY SrvrEdit (LPOLESERVER, LHSERVERDOC, OLE_LPCSTR, OLE_LPCSTR, LPOLESERVERDOC FAR * );
  232. OLESTATUS APIENTRY SrvrExecute (LPOLESERVER, HANDLE);
  233. OLESTATUS APIENTRY SrvrExit (LPOLESERVER);
  234. OLESTATUS APIENTRY SrvrOpen (LPOLESERVER, LHSERVERDOC, OLE_LPCSTR, LPOLESERVERDOC FAR *);
  235. OLESTATUS APIENTRY SrvrRelease (LPOLESERVER);
  236. // Document methods
  237. OLESTATUS APIENTRY DocClose (LPOLESERVERDOC);
  238. OLESTATUS APIENTRY DocExecute (LPOLESERVERDOC, HANDLE);
  239. OLESTATUS APIENTRY DocGetObject (LPOLESERVERDOC, OLE_LPCSTR, LPOLEOBJECT FAR *, LPOLECLIENT);
  240. OLESTATUS APIENTRY DocRelease (LPOLESERVERDOC);
  241. OLESTATUS APIENTRY DocSave (LPOLESERVERDOC);
  242. OLESTATUS APIENTRY DocSetColorScheme (LPOLESERVERDOC, OLE_CONST LOGPALETTE FAR*);
  243. OLESTATUS APIENTRY DocSetDocDimensions (LPOLESERVERDOC, OLE_CONST RECT FAR *);
  244. OLESTATUS APIENTRY DocSetHostNames (LPOLESERVERDOC, OLE_LPCSTR, OLE_LPCSTR);
  245. // Object methods
  246. OLESTATUS APIENTRY ObjDoVerb (LPOLEOBJECT, UINT, BOOL, BOOL);
  247. OLESTATUS APIENTRY ObjGetData (LPOLEOBJECT, OLECLIPFORMAT, LPHANDLE);
  248. LPVOID APIENTRY ObjQueryProtocol (LPOLEOBJECT, OLE_LPCSTR);
  249. OLESTATUS APIENTRY ObjRelease (LPOLEOBJECT);
  250. OLESTATUS APIENTRY ObjSetBounds (LPOLEOBJECT, OLE_CONST RECT FAR*);
  251. OLESTATUS APIENTRY ObjSetColorScheme (LPOLEOBJECT, OLE_CONST LOGPALETTE FAR*);
  252. OLESTATUS APIENTRY ObjSetData (LPOLEOBJECT, OLECLIPFORMAT, HANDLE);
  253. OLESTATUS APIENTRY ObjSetTargetDevice (LPOLEOBJECT, HANDLE);
  254. OLESTATUS APIENTRY ObjShow (LPOLEOBJECT, BOOL);
  255. OLECLIPFORMAT APIENTRY ObjEnumFormats (LPOLEOBJECT, OLECLIPFORMAT);
  256.