home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 13
/
mediashare_13.zip
/
mediashare_13
/
ZIPPED
/
PROGRAM
/
WTJ9403.ZIP
/
VBX
/
VBXDECL.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-11-14
|
31KB
|
1,085 lines
/*
* VBXDECL.C -- Dump out C declarations for VBX controls
*
* This source code accompanies the article "Secrets of the Visual Basic API"
* in the February '94 issue of Windows Tech Journal
*
* Copyright (c) 1994 Brett Foster (CIS: 70444,135)
*/
/* Ignore warnings about // comments, unreferenced parameters,
* and inline assembly preventing global optimizations
*/
#pragma warning ( disable : 4001 4100 4704 )
#include <windows.h>
#include <commdlg.h>
#include "winio.h"
#include <vbapi.h>
#include <string.h>
#include <stdlib.h>
static char dummy[0x20 - 0x10] = "foo"; // Must initialize!!
void FAR PASCAL Dispatch(void);
static FARPROC entry = Dispatch; // Must immediately follow dummy!!
// VB "Internal Error" code
#define ERR_INTERNAL 51
// Declarations require _export keyword
#define VBAPIFUN VBAPI _export
typedef void NEAR * NPVOID;
typedef struct tagStdItem {
LPVOID lpInfo;
PSTR pszName;
} STDITEM;
typedef STDITEM STDPROP;
typedef STDITEM STDEVENT;
typedef struct tagItemFlag {
FLONG fl;
PSTR pszName;
} ITEMFLAG;
typedef ITEMFLAG *PITEMFLAG;
// VALSTR - use stringizing operator to produce string
// from identifier name
#define VALSTR(val) val, #val
static STDPROP StdProps[] = {
VALSTR(PPROPINFO_STD_NAME),
VALSTR(PPROPINFO_STD_INDEX),
VALSTR(PPROPINFO_STD_HWND),
VALSTR(PPROPINFO_STD_BACKCOLOR),
VALSTR(PPROPINFO_STD_FORECOLOR),
VALSTR(PPROPINFO_STD_LEFT),
VALSTR(PPROPINFO_STD_TOP),
VALSTR(PPROPINFO_STD_WIDTH),
VALSTR(PPROPINFO_STD_HEIGHT),
VALSTR(PPROPINFO_STD_ENABLED),
VALSTR(PPROPINFO_STD_VISIBLE),
VALSTR(PPROPINFO_STD_MOUSEPOINTER),
VALSTR(PPROPINFO_STD_CAPTION),
VALSTR(PPROPINFO_STD_FONTNAME),
VALSTR(PPROPINFO_STD_FONTBOLD),
VALSTR(PPROPINFO_STD_FONTITALIC),
VALSTR(PPROPINFO_STD_FONTSTRIKE),
VALSTR(PPROPINFO_STD_FONTUNDER),
VALSTR(PPROPINFO_STD_FONTSIZE),
VALSTR(PPROPINFO_STD_TABINDEX),
VALSTR(PPROPINFO_STD_PARENT),
VALSTR(PPROPINFO_STD_DRAGMODE),
VALSTR(PPROPINFO_STD_DRAGICON),
VALSTR(PPROPINFO_STD_BORDERSTYLEOFF),
VALSTR(PPROPINFO_STD_TABSTOP),
VALSTR(PPROPINFO_STD_TAG),
VALSTR(PPROPINFO_STD_TEXT),
VALSTR(PPROPINFO_STD_BORDERSTYLEON),
VALSTR(PPROPINFO_STD_CLIPCONTROLS),
VALSTR(PPROPINFO_STD_NONE),
VALSTR(PPROPINFO_STD_HELPCONTEXTID),
VALSTR(PPROPINFO_STD_LINKMODE),
VALSTR(PPROPINFO_STD_LINKITEM),
VALSTR(PPROPINFO_STD_LINKTOPIC),
VALSTR(PPROPINFO_STD_LINKTIMEOUT),
VALSTR(PPROPINFO_STD_LEFTNORUN),
VALSTR(PPROPINFO_STD_TOPNORUN),
VALSTR(PPROPINFO_STD_ALIGN),
VALSTR(PPROPINFO_STD_IMEMODE),
VALSTR(PPROPINFO_STD_DATASOURCE),
VALSTR(PPROPINFO_STD_DATAFIELD),
VALSTR(PPROPINFO_STD_DATACHANGED),
NULL
};
static STDEVENT StdEvents[] = {
VALSTR(PEVENTINFO_STD_CLICK),
VALSTR(PEVENTINFO_STD_DBLCLICK),
VALSTR(PEVENTINFO_STD_DRAGDROP),
VALSTR(PEVENTINFO_STD_DRAGOVER),
VALSTR(PEVENTINFO_STD_GOTFOCUS),
VALSTR(PEVENTINFO_STD_KEYDOWN),
VALSTR(PEVENTINFO_STD_KEYPRESS),
VALSTR(PEVENTINFO_STD_KEYUP),
VALSTR(PEVENTINFO_STD_LOSTFOCUS),
VALSTR(PEVENTINFO_STD_MOUSEDOWN),
VALSTR(PEVENTINFO_STD_MOUSEMOVE),
VALSTR(PEVENTINFO_STD_MOUSEUP),
VALSTR(PEVENTINFO_STD_LINKERROR),
VALSTR(PEVENTINFO_STD_LINKOPEN),
VALSTR(PEVENTINFO_STD_LINKCLOSE),
VALSTR(PEVENTINFO_STD_LINKNOTIFY),
VALSTR(PEVENTINFO_STD_LINKCHANGE),
VALSTR(PEVENTINFO_STD_NONE),
NULL
};
static ITEMFLAG ClassStyles[] = {
VALSTR(CS_VREDRAW),
VALSTR(CS_HREDRAW),
VALSTR(CS_OWNDC),
VALSTR(CS_CLASSDC),
VALSTR(CS_PARENTDC),
VALSTR(CS_SAVEBITS),
VALSTR(CS_DBLCLKS),
VALSTR(CS_BYTEALIGNCLIENT),
VALSTR(CS_BYTEALIGNWINDOW),
VALSTR(CS_NOCLOSE),
VALSTR(CS_KEYCVTWINDOW),
VALSTR(CS_NOKEYCVT),
VALSTR(CS_GLOBALCLASS),
0
};
static ITEMFLAG WindowStyles[] = {
VALSTR(WS_POPUP),
VALSTR(WS_CHILD),
VALSTR(WS_CLIPSIBLINGS),
VALSTR(WS_CLIPCHILDREN),
VALSTR(WS_VISIBLE),
VALSTR(WS_DISABLED),
VALSTR(WS_MINIMIZE),
VALSTR(WS_MAXIMIZE),
VALSTR(WS_BORDER),
VALSTR(WS_DLGFRAME),
VALSTR(WS_VSCROLL),
VALSTR(WS_HSCROLL),
VALSTR(WS_SYSMENU),
VALSTR(WS_THICKFRAME),
VALSTR(WS_GROUP),
VALSTR(WS_TABSTOP),
0
};
static ITEMFLAG PropTypes[] = {
VALSTR(DT_OBJECT),
VALSTR(DT_HLSTR),
VALSTR(DT_PICTURE),
VALSTR(DT_YSIZE),
VALSTR(DT_YPOS),
VALSTR(DT_XSIZE),
VALSTR(DT_XPOS),
VALSTR(DT_REAL),
VALSTR(DT_ENUM),
VALSTR(DT_COLOR),
VALSTR(DT_BOOL),
VALSTR(DT_LONG),
VALSTR(DT_SHORT),
VALSTR(DT_HSZ),
0
};
static ITEMFLAG PropFlags[] = {
VALSTR(PF_fDefVal),
VALSTR(PF_fEditable),
VALSTR(PF_fGetData),
VALSTR(PF_fGetHszMsg),
VALSTR(PF_fGetMsg),
VALSTR(PF_fLoadDataOnly),
VALSTR(PF_fLoadMsgOnly),
VALSTR(PF_fNoInitDef),
VALSTR(PF_fNoMultiSelect),
VALSTR(PF_fNoRuntimeR),
VALSTR(PF_fNoRuntimeW),
VALSTR(PF_fNoShow),
VALSTR(PF_fPreHwnd),
VALSTR(PF_fPropArray),
VALSTR(PF_fSaveData),
VALSTR(PF_fSaveMsg),
VALSTR(PF_fSetCheck),
VALSTR(PF_fSetData),
VALSTR(PF_fSetMsg),
VALSTR(PF_fUpdateOnEdit),
0
};
static ITEMFLAG EventFlags[] = {
VALSTR(EF_fNoUnload),
0
};
static ITEMFLAG ModelFlags[] = {
VALSTR(MODEL_fArrows),
VALSTR(MODEL_fChildrenOk),
VALSTR(MODEL_fDesInteract),
VALSTR(MODEL_fFocusOk),
VALSTR(MODEL_fGraphical),
VALSTR(MODEL_fInitMsg),
VALSTR(MODEL_fInvisAtRun),
VALSTR(MODEL_fLoadMsg),
VALSTR(MODEL_fMnemonic),
0
};
static ITEMFLAG EventTypes[] = {
VALSTR(ET_FS),
VALSTR(ET_SD),
VALSTR(ET_CY),
VALSTR(ET_R8),
VALSTR(ET_R4),
VALSTR(ET_I4),
VALSTR(ET_I2),
0
};
// Version and mode of the emulation
static USHORT nVersion = VB300_VERSION;
static USHORT nMode = MODE_RUN;
// Pointer to VBINITCC function
typedef BOOL (CALLBACK *VBINITCCPROC)(WORD, BOOL);
static VBINITCCPROC lpfnVBINITCC;
// Pointer to VBTERMCC function
typedef BOOL (CALLBACK *VBTERMCCPROC)();
static VBTERMCCPROC lpfnVBTERMCC;
// Macro to manufacture far pointer from a near in lpModel
#define MKPTR(offs) MAKELP((SELECTOROF(lpModel)),(offs))
// Temporary storage for output strings
static char szBuffer[1000];
// PrintFlags -- Print a set of flags OR'd together
// Can also be used to print any unique value, but the values
// must be listed in order of decreasing magnitude so that
// they won't be misinterpreted
static FLONG PrintFlags(FLONG fl, PITEMFLAG pItemFlag)
{
PSTR szPattern = "%s | ";
if (fl) {
int i;
for (i = 0; pItemFlag[i].fl; i++) {
// Test for this flag
// NOTE: This test must be for equality
// because some flags use multiple bits
if ((fl & pItemFlag[i].fl) == pItemFlag[i].fl) {
fl &= ~pItemFlag[i].fl;
if (!fl) {
// No more flags, drop or bar
szPattern = "%s";
}
printf(szPattern,pItemFlag[i].pszName);
}
}
} else {
// No flags
printf("0");
}
// Return modified flags in case some not accounted for
return(fl);
}
// PrintDeclarations -- Walk through a MODEL structure and print it out
static int NEAR PrintDeclarations(LPMODEL lpModel)
{
LPSTR lpszClassName;
LPPROPLIST lpPropList;
LPEVENTLIST lpEventList;
FLONG fl;
int fNone=FALSE;
// Get class name
lpszClassName = MKPTR(lpModel->npszClassName);
// Generate custom property declarations
lpPropList = MKPTR(lpModel->npproplist);
for (; *lpPropList; lpPropList++) {
LPPROPINFO lpPropInfo;
LPSTR lpszPropName;
if (*lpPropList >= PPROPINFO_STD_LAST) {
// Ignore standard properties for now
continue;
}
// Get pointers
lpPropInfo = MKPTR(*lpPropList);
lpszPropName = MKPTR(lpPropInfo->npszName);
if (lpPropInfo->npszEnumList) {
LPSTR lpszItem;
// Property has an item list
// Generate list declaration
wsprintf(szBuffer,"static CHAR NEAR sz%s[] =\n",
lpszPropName);
printf("%s",szBuffer);
lpszItem = MKPTR(lpPropInfo->npszEnumList);
while (*lpszItem) {
wsprintf(szBuffer,
"\t\"%s\\0\"\\\n",lpszItem);
printf("%s",szBuffer);
lpszItem += _fstrlen(lpszItem) + 1;
}
printf("\t\"\";\n\n");
}
// Generate property declaration
// But make sure not to generate the "None" property
// more than once
if ((*lpszPropName == ' ') && fNone) {
continue;
} else {
LPSTR lpszName;
if (*lpszPropName == ' ') {
fNone = TRUE;
lpszName = "None";
} else {
lpszName = lpszPropName;
}
wsprintf(szBuffer,
"static PROPINFO NEAR %sProp_%s = {\n",
lpszClassName,lpszName);
printf("%s",szBuffer);
wsprintf(szBuffer,"\t\"%s\",\n",lpszPropName);
printf("%s",szBuffer);
}
// Print data type
printf("\t");
fl = PrintFlags(lpPropInfo->fl & PF_datatype,PropTypes);
if (fl) {
printf("0x%02x /* unknown datatype */",fl);
}
printf(" | \n\t");
// Print flags
fl = PrintFlags(lpPropInfo->fl & ~PF_datatype,PropFlags);
if (fl) {
printf("0x%08lx /* unknown flags */",fl);
}
printf(",\n");
// Offset into control structure
if (!lpPropInfo->offsetData || lpPropInfo->infoData) {
// Print offset as a number if it is zero
// or if bit-packing is used
printf("\t%d,\n",lpPropInfo->offsetData);
} else {
// Use OFFSETIN macro, but display numeric
// offset in comment just in case
wsprintf(szBuffer,"\tOFFSETIN(CTLSTRUCT,%s),",
lpszPropName);
printf("%s",szBuffer);
printf(" /* %d */\n",lpPropInfo->offsetData);
}
// Bit-packing stuff
printf("\t0x%02x,\n",lpPropInfo->infoData);
// Default value
if ((lpPropInfo->fl & PF_datatype) == DT_COLOR) {
// Display default color values in hex
printf("\t0x%08lx,\n",lpPropInfo->dataDefault);
} else {
// Other default values displayed in decimal
printf("\t%ld,\n",lpPropInfo->dataDefault);
}
// Enum list
if (lpPropInfo->npszEnumList) {
wsprintf(szBuffer,"\t(PSTR)sz%s,\n",lpszPropName);
printf("%s",szBuffer);
} else {
printf("\tNULL,\n");
}
// Enum max value
printf("\t%d\n",lpPropInfo->enumMax);
// End of declaration
printf("};\n\n");
}
// KLUGE: Doctor standard property list
// The first element has a segment value of 0xffff instead of 0
StdProps[0].lpInfo = (LPVOID)(((FLONG)StdProps[0].lpInfo) & 0xffff);
// Generate property list
wsprintf(szBuffer,"static PPROPINFO %sProps_VB%x[] = \n{\n",
lpszClassName,lpModel->usVersion);
printf("%s",szBuffer);
lpPropList = MKPTR(lpModel->npproplist);
for (; *lpPropList; lpPropList++) {
if (*lpPropList >= PPROPINFO_STD_LAST) {
// Standard property
printf("\t");
fl = ((FLONG)(LPVOID)*lpPropList) & 0xffff;
fl = PrintFlags(fl,(PITEMFLAG)StdProps);
if (fl) {
fl = ~fl;
printf("(PPROPINFO)~0x%03lx /* unknown standard property */",fl);
}
printf(",\n");
} else {
LPPROPINFO lpPropInfo = MKPTR(*lpPropList);
LPSTR lpszPropName = MKPTR(lpPropInfo->npszName);
// Custom property
if (*lpszPropName == ' ') {
// Convention for unused properties in VB 1.0
lpszPropName = "None";
}
wsprintf(szBuffer,"\t&%sProp_%s,\n",
lpszClassName,lpszPropName);
printf("%s",szBuffer);
}
}
printf("\tNULL\n};\n\n");
// Generate custom event declarations
lpEventList = MKPTR(lpModel->npeventlist);
for (; *lpEventList; lpEventList++) {
LPEVENTINFO lpEventInfo;
LPSTR lpszEventName;
LPWORD lpParmTypes;
if (*lpEventList >= PEVENTINFO_STD_LAST) {
// Ignore standard events for now
continue;
}
// Get pointers
lpEventInfo = MKPTR(*lpEventList);
lpszEventName = MKPTR(lpEventInfo->npszName);
lpParmTypes = MKPTR(lpEventInfo->npParmTypes);
if (lpEventInfo->cParms) {
int nParm;
// Declare an array to store the parameter types
wsprintf(szBuffer,"static WORD NEAR ParamTypes_%s[] = { ",
lpszEventName);
printf("%s",szBuffer);
// Supply a declaration for each parameter
nParm = 0;
for (; nParm < (int)lpEventInfo->cParms; nParm++) {
// Print data type
if (nParm) {
printf(", ");
}
fl = PrintFlags(lpParmTypes[nParm],EventTypes);
if (fl) {
printf("%d /* Unknown datatype */",fl);
}
}
printf(" };\n\n");
}
// Generate event declaration
wsprintf(szBuffer,"static EVENTINFO NEAR %sEvent_%s = {\n",
lpszClassName,lpszEventName);
printf("%s",szBuffer);
wsprintf(szBuffer,"\t\"%s\",\n",lpszEventName);
printf("%s",szBuffer);
printf("\t%d,\n\t%d,\n\t",lpEventInfo->cParms,
lpEventInfo->cwParms);
// Parameter types
if (lpEventInfo->cParms) {
wsprintf(szBuffer,"ParamTypes_%s",lpszEventName);
printf("%s",szBuffer);
} else {
printf("NULL");
}
// Parameter profile
lpszEventName = MKPTR(lpEventInfo->npszParmProf);
wsprintf(szBuffer,",\n\t\"%s\",\n\t",lpszEventName);
printf("%s",szBuffer);
// Find flags
fl = PrintFlags(lpEventInfo->fl,EventFlags);
if (fl) {
printf("0x%08lx /* unknown flags */",fl);
}
printf("\n};\n\n");
}
// KLUGE: Doctor standard event list
// The first element has a segment value of 0xffff instead of 0
StdEvents[0].lpInfo = (LPVOID)(((FLONG)StdEvents[0].lpInfo) & 0xffff);
// Generate property list
wsprintf(szBuffer,"static PEVENTINFO %sEvents_VB%x[] = \n{\n",
lpszClassName,lpModel->usVersion);
printf("%s",szBuffer);
lpEventList = MKPTR(lpModel->npeventlist);
for (; *lpEventList; lpEventList++) {
if (*lpEventList >= PEVENTINFO_STD_LAST) {
printf("\t");
fl = ((FLONG)(LPVOID)*lpEventList) & 0xffff;
fl = PrintFlags(fl,(PITEMFLAG)StdEvents);
if (fl) {
printf("(PEVENTINFO)~0x%03lx /* unknown standard event */",fl);
}
printf(",\n");
} else {
LPEVENTINFO lpEventInfo = MKPTR(*lpEventList);
LPSTR lpszEventName = MKPTR(lpEventInfo->npszName);
// Custom event
wsprintf(szBuffer,"\t&%sEvent_%s,\n",
lpszClassName,lpszEventName);
printf("%s",szBuffer);
}
}
printf("\tNULL\n};\n\n");
// Define for bitmap resource id
wsprintf(szBuffer,"#define IDBMP_%s %d\n\n",lpszClassName,
lpModel->idBmpPalette);
printf("%s",szBuffer);
// Generate model declaration
wsprintf(szBuffer,"static MODEL %sModel_VB%x[] = \n{\n",
lpszClassName,lpModel->usVersion);
printf("%s",szBuffer);
printf("\t0x%04x,\n\t",lpModel->usVersion);
// Model flags
fl = PrintFlags(lpModel->fl,ModelFlags);
if (fl) {
printf("0x%08lx /* unknown flags */",fl);
}
printf(",\n");
// Control procedure
wsprintf(szBuffer,"\t(PCTLPROC)%sCtlProc,\n\t",lpszClassName);
printf("%s",szBuffer);
// Class style bits
fl = PrintFlags(lpModel->fsClassStyle,ClassStyles);
if (fl) {
printf("0x%04x",fl);
}
printf(",\n\t");
// Window style bits
fl = PrintFlags(lpModel->flWndStyle,WindowStyles);
if (fl) {
printf("0x%08lx",fl);
}
// Extra bytes for control structure
printf(",\n\tsizeof(CTLSTRUCT),\t/* %d */\n",lpModel->cbCtlExtra);
// Bitmap resource id
wsprintf(szBuffer,"\tIDBMP_%s,\n",lpszClassName,
lpModel->idBmpPalette);
printf("%s",szBuffer);
// Default control name
wsprintf(szBuffer,"\t\"%s\",\n",MKPTR(lpModel->npszDefCtlName));
printf("%s",szBuffer);
// Class name
wsprintf(szBuffer,"\t\"%s\",\n",MKPTR(lpModel->npszClassName));
printf("%s",szBuffer);
// Parent class name
if (lpModel->npszParentClassName) {
wsprintf(szBuffer,"\t\"%s\",\n",
MKPTR(lpModel->npszParentClassName));
printf("%s",szBuffer);
} else {
printf("\tNULL,\n");
}
// Property list
wsprintf(szBuffer,"\t%sProps_VB%x,\n",
lpszClassName,lpModel->usVersion);
printf("%s",szBuffer);
// Event list
wsprintf(szBuffer,"\t%sEvents_VB%x,\n",
lpszClassName,lpModel->usVersion);
printf("%s",szBuffer);
// Default property & event
printf("\t%d,\n\t%d",lpModel->nDefProp,lpModel->nDefEvent);
if (lpModel->usVersion >= VB200_VERSION) {
// Value property field new for VB 2.0
printf(",\n\t%d",lpModel->nValueProp);
}
if (lpModel->usVersion >= VB300_VERSION) {
// Control version field new for VB 3.0
printf(",\n\t%d",lpModel->usCtlVersion);
}
// That's it!
printf("\n};\n\n");
return(0);
}
HANDLE VBAPIFUN VBGetHInstance(void)
{
return((HANDLE)__hInst);
}
USHORT VBAPIFUN VBGetVersion(void)
{
return(nVersion);
}
USHORT VBAPIFUN VBGetMode(void)
{
return(nMode);
}
BOOL VBAPIFUN VBRegisterModel(HINSTANCE hInstance, LPMODEL lpModel)
{
// Avoid compiler warnings
hInstance = hInstance;
PrintDeclarations(lpModel);
return(TRUE);
}
// VBUnknownFunction -- called for any function index
// that we don't know about
// NOTE: stack checking is turned off to prevent BX from
// getting clobbered
#pragma check_stack ( off )
void VBAPIFUN VBUnknownFunction(void)
{
int bxreg;
// Copy the BX register value into a variable
// so we can display the unknown function number
_asm mov bxreg,bx
// Let the user know what happened
wsprintf(szBuffer,"Unknown function %04x",bxreg);
MessageBox(__hMainWnd,szBuffer,__szModule,MB_ICONSTOP);
// Bail out
winio_closeall();
exit(1);
}
#pragma check_stack ( on )
int LoadControl(LPSTR lpszControl)
{
int rc=0;
HMODULE hModule;
// Display hourglass cursor
winio_setbusy();
// Defer painting
winio_setpaint(__hMainWnd,FALSE);
// Load the VBX
hModule = LoadLibrary(lpszControl);
if (hModule >= HINSTANCE_ERROR) {
lpfnVBINITCC = (VBINITCCPROC)GetProcAddress(hModule,"VBINITCC");
lpfnVBTERMCC = (VBTERMCCPROC)GetProcAddress(hModule,"VBTERMCC");
if (lpfnVBINITCC) {
if (lpfnVBINITCC(nVersion,nMode == MODE_RUN)) {
// Only call VBTERMCC if VBINITCC succeeds
if (lpfnVBTERMCC) {
lpfnVBTERMCC();
}
}
}
FreeLibrary(hModule);
if (!lpfnVBINITCC) {
printf("VBX has no VBINITCC function!");
rc = -1;
}
} else {
printf("LoadLibrary failed");
rc = -1;
}
// Enable painting
winio_setpaint(__hMainWnd,TRUE);
// Restore cursor
winio_resetbusy();
return(rc);
}
enum MenuIds {
NOTUSED, // Placeholder for value of 0
OPTION_VB1,
OPTION_VB2,
OPTION_VB3,
OPTION_RUN,
OPTION_DESIGN,
FILE_NEW,
FILE_OPEN
};
static USHORT OptionValues[] = {
0,
VB100_VERSION,
VB200_VERSION,
VB300_VERSION,
MODE_RUN,
MODE_DESIGN,
0
};
static HMENU hmenuOptions;
// FindId -- Returns a menu id based on an option value
static int FindId(USHORT iValue)
{
int i;
for (i = 1; OptionValues[i]; i++) {
if (iValue == OptionValues[i]) {
break;
}
}
return(i);
}
// FileNew -- Clears the buffer
static void _cdecl FileNew(HWND hwnd, int idItem)
{
winio_clear(__hMainWnd);
}
// FileOpen -- Open a new VBX
static void _cdecl FileOpen(HWND hwnd, int idItem)
{
OPENFILENAME of;
char szFile[128];
memset(&of,0,sizeof(of));
of.lStructSize = sizeof(of);
of.hwndOwner = __hMainWnd;
of.lpstrFilter = "VBX Files (*.vbx)\0*.vbx\0All Files (*.*)\0*.*\0\0";
of.lpstrFile = szFile;
*szFile = '\0';
of.nMaxFile = sizeof(szFile);
of.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
of.lpstrDefExt = "vbx";
if (GetOpenFileName(&of)) {
LoadControl(szFile);
}
}
// SetVersion -- handle selection of the VB version from the Options menu
static void _cdecl SetVersion(HWND hwnd, int idItem)
{
// Uncheck the previous selection
CheckMenuItem(hmenuOptions,FindId(nVersion),MF_UNCHECKED);
// Check the new one
CheckMenuItem(hmenuOptions,idItem,MF_CHECKED);
// Set the new version
nVersion = OptionValues[idItem];
}
// SetMode -- handle selection of the VB mode from the Options menu
static void _cdecl SetMode(HWND hwnd, int idItem)
{
// Uncheck the previous selection
CheckMenuItem(hmenuOptions,FindId(nMode),MF_UNCHECKED);
// Check the new one
CheckMenuItem(hmenuOptions,idItem,MF_CHECKED);
// Set the new mode
nMode = OptionValues[idItem];
}
int _cdecl main(int argc, char *argv[])
{
int i;
if (OFFSETOF((LPVOID)&entry) != 0x20) {
printf("Internal error: OFFSETOF(&entry) = 0x%02x (must be 0x20!)",
OFFSETOF((LPVOID)&entry));
return(1);
}
// Add a "New" item to the File menu
InsertMenu(winio_hmenufile(__hMainWnd),0,MF_STRING|MF_BYPOSITION,
FILE_NEW,"&New (Clears buffer)");
winio_setmenufunc(__hMainWnd,FILE_NEW,FileNew);
// Add an "Open" item to the File menu
InsertMenu(winio_hmenufile(__hMainWnd),1,MF_STRING|MF_BYPOSITION,
FILE_OPEN,"&Open...");
winio_setmenufunc(__hMainWnd,FILE_OPEN,FileOpen);
// Add an "Options" menu
hmenuOptions = CreateMenu();
InsertMenu(winio_hmenumain(__hMainWnd),1,
MF_STRING|MF_POPUP|MF_BYPOSITION,
(UINT)hmenuOptions,"&Options");
// Create menu items to select the VB version
AppendMenu(hmenuOptions,MF_STRING|MF_ENABLED,OPTION_VB1,"VB &1.0");
winio_setmenufunc(__hMainWnd,OPTION_VB1,SetVersion);
AppendMenu(hmenuOptions,MF_STRING|MF_ENABLED,OPTION_VB2,"VB &2.0");
winio_setmenufunc(__hMainWnd,OPTION_VB2,SetVersion);
AppendMenu(hmenuOptions,MF_STRING|MF_ENABLED,OPTION_VB3,"VB &3.0");
winio_setmenufunc(__hMainWnd,OPTION_VB3,SetVersion);
// Separator
AppendMenu(hmenuOptions,MF_STRING|MF_ENABLED|MF_SEPARATOR,0,NULL);
// Menu items to select the "mode"
AppendMenu(hmenuOptions,MF_STRING|MF_ENABLED,OPTION_DESIGN,"&Design Mode");
winio_setmenufunc(__hMainWnd,OPTION_DESIGN,SetMode);
AppendMenu(hmenuOptions,MF_STRING|MF_ENABLED,OPTION_RUN,"&Run Mode");
winio_setmenufunc(__hMainWnd,OPTION_RUN,SetMode);
// Check the default options
CheckMenuItem(hmenuOptions,FindId(nVersion),MF_CHECKED);
CheckMenuItem(hmenuOptions,FindId(nMode),MF_CHECKED);
// Refresh the menu onscreen
DrawMenuBar(__hMainWnd);
// Open each VBX named on the command-line
// usage: VBXDECL [vbxfile] ...
for (i = 1; i < argc; i++) {
if (LoadControl(argv[i])) {
// Error, stop here
return(1);
}
}
return(0);
}
// Stubs for unsupported VB API functions
LPVOID VBAPIFUN VBDerefControl(HCTL hctl){return(NULL);}
LONG VBAPIFUN VBDefControlProc(HCTL hctl, HWND hwnd, USHORT msg, USHORT wp, LONG lp){return(0);}
HWND VBAPIFUN VBGetControlHwnd(HCTL hctl){return(NULL);}
LPMODEL VBAPIFUN VBGetControlModel(HCTL hctl){return(NULL);}
LPSTR VBAPIFUN VBGetControlName(HCTL hctl, LPSTR lpszName){*lpszName = '\0'; return(NULL);}
HCTL VBAPIFUN VBGetHwndControl(HWND hwnd){return(NULL);}
LONG VBAPIFUN VBSendControlMsg(HCTL hctl, USHORT msg, USHORT wp, LONG lp){return(0);}
LONG VBAPIFUN VBSuperControlProc(HCTL hctl, USHORT msg, USHORT wp, LONG lp){return(0);}
ERR VBAPIFUN VBRecreateControlHwnd(HCTL hctl){return(ERR_INTERNAL);}
VOID VBAPIFUN VBDirtyForm(HCTL hctl){return;}
ERR VBAPIFUN VBSetErrorMessage(ERR err, LPSTR lpstr){return(ERR_INTERNAL);}
VOID VBAPIFUN VBGetAppTitle(LPSTR lpstr, USHORT cbMax){*lpstr = '\0'; return;}
int VBAPIFUN VBDialogBoxParam(HANDLE hinst, LPSTR pszTemplateName, FARPROC lpDialogFunc, LONG lp){return(-1);}
ULONG VBAPIFUN VBSetControlFlags(HCTL hctl, ULONG mask, ULONG value){return(0);}
HCTL VBAPIFUN VBGetCapture(VOID){return(NULL);}
VOID VBAPIFUN VBSetCapture(HCTL hctl){return;}
VOID VBAPIFUN VBReleaseCapture(VOID){return;}
VOID VBAPIFUN VBMoveControl(HCTL hctl, LPRECT lprect, BOOL fRepaint){return;}
VOID VBAPIFUN VBGetControlRect(HCTL hctl, LPRECT lprect){return;}
VOID VBAPIFUN VBGetRectInContainer(HCTL hctl, LPRECT lprect){return;}
VOID VBAPIFUN VBGetClientRect(HCTL hctl, LPRECT lprect){return;}
VOID VBAPIFUN VBClientToScreen(HCTL hctl, LPPOINT lppt){return;}
VOID VBAPIFUN VBScreenToClient(HCTL hctl, LPPOINT lppt){return;}
BOOL VBAPIFUN VBIsControlVisible(HCTL hctl){return(FALSE);}
BOOL VBAPIFUN VBIsControlEnabled(HCTL hctl){return(FALSE);}
VOID VBAPIFUN VBInvalidateRect(HCTL hctl, LPRECT lprect, BOOL fEraseBkGnd){return;}
VOID VBAPIFUN VBUpdateControl(HCTL hctl){return;}
HCTL VBAPIFUN VBGetControl(HCTL hctl, WORD gc){return(NULL);}
VOID VBAPIFUN VBZOrder(HCTL hctl, WORD zorder){return;}
HSZ VBAPIFUN VBCreateHsz(HANDLE seg, LPSTR lpszString){return(NULL);}
HSZ VBAPIFUN VBDestroyHsz(HSZ hsz){return(NULL);}
LPSTR VBAPIFUN VBDerefHsz(HSZ hsz){return(NULL);}
LPSTR VBAPIFUN VBLockHsz(HSZ hsz){return(NULL);}
VOID VBAPIFUN VBUnlockHsz(HSZ hsz){return;}
HLSTR VBAPIFUN VBCreateHlstr(LPVOID pb, USHORT cbLen){return(NULL);}
HLSTR VBAPIFUN VBCreateTempHlstr(LPVOID pb, USHORT cbLen){return(NULL);}
VOID VBAPIFUN VBDestroyHlstr(HLSTR hlstr){return;}
LPSTR VBAPIFUN VBDerefHlstr(HLSTR hlstr){return(NULL);}
LPSTR VBAPIFUN VBDerefHlstrLen(HLSTR hlstr, LPUSHORT lpcbLen){return(NULL);}
LPSTR VBAPIFUN VBDerefZeroTermHlstr(HLSTR hlstr){return(NULL);}
USHORT VBAPIFUN VBGetHlstr(HLSTR hlstr, LPVOID pb, USHORT cbLen){*(LPSTR)pb = '\0'; return(NULL);}
USHORT VBAPIFUN VBGetHlstrLen(HLSTR hlstr){return(0);}
ERR VBAPIFUN VBSetHlstr(LPHLSTR lphlstr, LPVOID pb, USHORT cbLen){return(ERR_INTERNAL);}
ERR VBAPIFUN VBResizeHlstr(HLSTR hlstr, USHORT newCbLen){return(ERR_INTERNAL);}
ERR VBAPIFUN VBCoerceVariant(LPVAR lpVar, SHORT vtype, LPVOID lpData){return(ERR_INTERNAL);}
SHORT VBAPIFUN VBGetVariantType(LPVAR lpVar){return(ERR_INTERNAL);}
SHORT VBAPIFUN VBGetVariantValue(LPVAR lpVar, LPVAL lpVal){return(ERR_INTERNAL);}
ERR VBAPIFUN VBSetVariantValue(LPVAR lpVar, SHORT vtype, LPVOID lpData){return(ERR_INTERNAL);}
LPVOID VBAPIFUN VBArrayElement(HAD hAD, SHORT cIndex, LPSHORT lpi){return(NULL);}
LONG VBAPIFUN VBArrayBounds(HAD hAD, SHORT index){return(AB_INVALIDINDEX);}
USHORT VBAPIFUN VBArrayElemSize(HAD hAD){return(0);}
LPVOID VBAPIFUN VBArrayFirstElem(HAD hAD){return(NULL);}
SHORT VBAPIFUN VBArrayIndexCount(HAD hAD){return(0);}
VOID VBAPIFUN VBRuntimeError(ERR err){return;}
USHORT VBAPIFUN VBCbSaveFPState(LPVOID pb, USHORT cb){return(0);}
VOID VBAPIFUN VBRestoreFPState(LPVOID pb){return;}
ERR VBAPIFUN VBFireEvent(HCTL hctl, USHORT idEvent, LPVOID lpparams){return(ERR_INTERNAL);}
ERR VBAPIFUN VBGetControlProperty(HCTL hctl, USHORT idProp, LPVOID pdata){return(ERR_INTERNAL);}
ERR VBAPIFUN VBSetControlProperty(HCTL hctl, USHORT idProp, LONG data){return(ERR_INTERNAL);}
HPIC VBAPIFUN VBAllocPic(LPPIC lppic){return(NULL);}
HPIC VBAPIFUN VBAllocPicEx(LPPIC lppic, USHORT usVersion){return(NULL);}
VOID VBAPIFUN VBFreePic(HPIC hpic){return;}
HPIC VBAPIFUN VBGetPic(HPIC hpic, LPPIC lppic){return(NULL);}
HPIC VBAPIFUN VBGetPicEx(HPIC hpic, LPPIC lppic, USHORT usVersion){return(NULL);}
ERR VBAPIFUN VBPicFromCF(LPHPIC lphpic, HANDLE hData, WORD wFormat){return(ERR_INTERNAL);}
HPIC VBAPIFUN VBRefPic(HPIC hpic){return(NULL);}
VOID VBAPIFUN VBPaletteChanged(HCTL hctl){return;}
COLOR VBAPIFUN VBTranslateColor(HCTL hctl, COLOR clr){return(0);}
ERR VBAPIFUN VBReadFormFile(HFORMFILE hformfile, LPVOID pb, WORD cb){return(ERR_INTERNAL);}
ERR VBAPIFUN VBWriteFormFile(HFORMFILE hformfile, LPVOID pb, WORD cb){return(ERR_INTERNAL);}
LONG VBAPIFUN VBSeekFormFile(HFORMFILE hformfile, LONG offset){return(-1);}
LONG VBAPIFUN VBRelSeekFormFile(HFORMFILE hformfile, LONG offset){return(-1);}
ERR VBAPIFUN VBReadBasicFile(USHORT usFileNo, LPVOID pb, WORD cb){return(ERR_INTERNAL);}
ERR VBAPIFUN VBWriteBasicFile(USHORT usFileNo, LPVOID pb, WORD cb){return(ERR_INTERNAL);}
LONG VBAPIFUN VBSeekBasicFile(USHORT usFileNo, LONG offset){return(-1);}
LONG VBAPIFUN VBRelSeekBasicFile(USHORT usFileNo, LONG offset){return(-1);}
LONG VBAPIFUN VBYPixelsToTwips(SHORT Pixels){return(0);}
LONG VBAPIFUN VBXPixelsToTwips(SHORT Pixels){return(0);}
SHORT VBAPIFUN VBYTwipsToPixels(LONG Twips){return(0);}
SHORT VBAPIFUN VBXTwipsToPixels(LONG Twips){return(0);}
ERR VBAPIFUN VBLinkPostAdvise(HCTL hctl){return(ERR_INTERNAL);}
BOOL VBAPIFUN VBPasteLinkOk(HANDLE FAR *phTriplet, HCTL hctl){return(FALSE);}
VOID VBAPIFUN VBLinkMakeItemName(HCTL hctl, LPSTR lpszBuf){return;}
HCTL VBAPIFUN VBGetDataSourceControl(HCTL hctl,BOOL FAR *bIsRegistered){return(NULL);}
SHORT VBAPIFUN VBFormat(SHORT vtype, LPVOID lpData, LPSTR lpszFmt, LPVOID pb, USHORT cb){return(-1);}
FARPROC VBFunctions[] = {
(FARPROC)VBRegisterModel,
(FARPROC)VBDerefControl,
(FARPROC)VBDefControlProc,
(FARPROC)VBFireEvent,
(FARPROC)VBSetControlProperty,
(FARPROC)VBGetControlProperty,
(FARPROC)VBCreateHsz,
(FARPROC)VBDestroyHsz,
(FARPROC)VBDerefHsz,
(FARPROC)VBLockHsz,
(FARPROC)VBUnlockHsz,
(FARPROC)VBGetControlHwnd,
(FARPROC)VBRecreateControlHwnd,
(FARPROC)VBGetControlModel,
(FARPROC)VBSendControlMsg,
(FARPROC)VBReadFormFile,
(FARPROC)VBWriteFormFile,
(FARPROC)VBSuperControlProc,
(FARPROC)VBGetMode,
(FARPROC)VBGetHInstance,
(FARPROC)VBCreateHlstr,
(FARPROC)VBSetHlstr,
(FARPROC)VBDestroyHlstr,
(FARPROC)VBDerefHlstr,
(FARPROC)VBGetHlstrLen,
(FARPROC)VBGetHwndControl,
(FARPROC)VBXPixelsToTwips,
(FARPROC)VBYPixelsToTwips,
(FARPROC)VBXTwipsToPixels,
(FARPROC)VBYTwipsToPixels,
(FARPROC)VBReadBasicFile,
(FARPROC)VBWriteBasicFile,
(FARPROC)VBAllocPic,
(FARPROC)VBFreePic,
(FARPROC)VBGetPic,
(FARPROC)VBRefPic,
(FARPROC)VBPicFromCF,
(FARPROC)VBSetErrorMessage,
(FARPROC)VBGetAppTitle,
(FARPROC)VBDialogBoxParam,
(FARPROC)VBSeekFormFile,
(FARPROC)VBRelSeekFormFile,
(FARPROC)VBGetControlName,
(FARPROC)VBUnknownFunction,
(FARPROC)VBUnknownFunction,
(FARPROC)VBUnknownFunction,
(FARPROC)VBUnknownFunction,
(FARPROC)VBGetVersion,
(FARPROC)VBLinkPostAdvise,
(FARPROC)VBPasteLinkOk,
(FARPROC)VBDirtyForm,
(FARPROC)VBSetControlFlags,
(FARPROC)VBPaletteChanged,
(FARPROC)VBAllocPicEx,
(FARPROC)VBGetPicEx,
(FARPROC)VBTranslateColor,
(FARPROC)VBGetCapture,
(FARPROC)VBSetCapture,
(FARPROC)VBReleaseCapture,
(FARPROC)VBGetControl,
(FARPROC)VBZOrder,
(FARPROC)VBMoveControl,
(FARPROC)VBGetControlRect,
(FARPROC)VBGetRectInContainer,
(FARPROC)VBGetClientRect,
(FARPROC)VBClientToScreen,
(FARPROC)VBScreenToClient,
(FARPROC)VBIsControlVisible,
(FARPROC)VBIsControlEnabled,
(FARPROC)VBInvalidateRect,
(FARPROC)VBUpdateControl,
(FARPROC)VBCoerceVariant,
(FARPROC)VBGetVariantType,
(FARPROC)VBGetVariantValue,
(FARPROC)VBSetVariantValue,
(FARPROC)VBGetHlstr,
(FARPROC)VBResizeHlstr,
(FARPROC)VBDerefHlstrLen,
(FARPROC)VBDerefZeroTermHlstr,
(FARPROC)VBCreateTempHlstr,
(FARPROC)VBArrayElement,
(FARPROC)VBArrayBounds,
(FARPROC)VBArrayElemSize,
(FARPROC)VBArrayFirstElem,
(FARPROC)VBArrayIndexCount,
(FARPROC)VBRuntimeError,
(FARPROC)VBFormat,
(FARPROC)VBCbSaveFPState,
(FARPROC)VBRestoreFPState,
(FARPROC)VBLinkMakeItemName,
};
static int nFunctions = sizeof(VBFunctions) / sizeof(VBFunctions[0]);
#pragma check_stack ( off )
void FAR PASCAL Dispatch(void)
{
__asm {
// Duplicate function epilog
// This is to undo the function prolog
pop di
pop si
leave
// Make sure we have a function for
// this value
cmp bx, ss:nFunctions
ja unknown
// Jump to the appropriate function
jmp dword ptr ss:VBFunctions[bx]
unknown:
// Unknown function
jmp VBUnknownFunction
}
}
#pragma check_stack ( on )