home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Tool Box
/
SIMS_2.iso
/
tool
/
various
/
iniwiz
/
iniwiz.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-12
|
10KB
|
412 lines
//---------------------------------------------------------------------------
// INIWIZ.c
//---------------------------------------------------------------------------
// Contains control procedure for INIWIZ control
//---------------------------------------------------------------------------
#include <windows.h>
#include <vbapi.h>
#include "inires.h"
#include "iniprop.h"
#include "inievent.h"
#include "INIWIZ.h"
VBXINFO INIWIZ[MAX_VBXS];
//---------------------------------------------------------------------------
// Global Variables
//---------------------------------------------------------------------------
HMODULE hModDLL,hMod3d;
typBUFF szFile, szSection, szEntry, szData;
//---------------------------------------------------------------------------
// Local Function Prototypes
//---------------------------------------------------------------------------
static void GetIniFileProperty(HCTL , LPSTR , LPSTR , LPSTR , LPSTR );
static int SearchVBXINFOByHCTL ( HCTL );
static int SearchVBXINFOByHPARENT ( HWND );
static HWND HwndInitAboutPopup(void);
//---------------------------------------------------------------------------
// Initialize library. This routine is called when the first client loads
// the DLL.
//---------------------------------------------------------------------------
int FAR PASCAL LibMain
(
HANDLE hModule,
WORD wDataSeg,
WORD cbHeapSize,
LPSTR lpszCmdLine
)
{
// Avoid warnings on unused (but required) formal parameters
wDataSeg = wDataSeg;
cbHeapSize = cbHeapSize;
lpszCmdLine = lpszCmdLine;
hModDLL = hModule;
return 1;
}
//---------------------------------------------------------------------------
// Register custom control. This routine is called by VB when the custom
// control DLL is loaded for use.
//---------------------------------------------------------------------------
BOOL FAR PASCAL _export VBINITCC
(
USHORT usVersion,
BOOL fRuntime
)
{
WNDCLASS class;
// Avoid warnings on unused (but required) formal parameters
fRuntime = fRuntime;
usVersion = usVersion;
// Register control(s)
if (!VBRegisterModel(hModDLL, &modelINIWIZ)) return FALSE;
class.style = 0;
class.lpfnWndProc = (FARPROC)AboutPopupWndProc;
class.cbClsExtra = 0;
class.cbWndExtra = 0;
class.hInstance = hModDLL;
class.hIcon = NULL;
class.hCursor = NULL;
class.hbrBackground = NULL;
class.lpszMenuName = NULL;
class.lpszClassName = CLASS_ABOUTPOPUP;
if (!RegisterClass(&class))
return FALSE;
return TRUE;
}
//---------------------------------------------------------------------------
// WEP
//---------------------------------------------------------------------------
// C7 and QCWIN provide default a WEP:
//---------------------------------------------------------------------------
#if (_MSC_VER < 610)
int FAR PASCAL WEP(int fSystemExit);
#pragma alloc_text(WEP_TEXT,WEP)
int FAR PASCAL WEP
(
int fSystemExit
)
{
fSystemExit = fSystemExit;
return 1;
}
#endif // C6
//----------------------------------------------------------
// INIWIZ Control Procedure
//----------------------------------------------------------
LONG FAR PASCAL _export INIWIZCtlProc (HCTL hctl, HWND hwnd,
USHORT msg, USHORT wp, LONG lp)
{
LONG lResult ;
int i;
switch (msg)
{
case VBM_SETPROPERTY:
if ( wp == IPROP_INIWIZ_ACTION )
{
switch ((int)lp)
{
case INI_READ :
{
GetIniFileProperty(hctl, szFile, szSection, szEntry , NULL );
GetPrivateProfileString (szSection, szEntry,"" ,
szData, sizeof (szData),
szFile );
VBSetControlProperty (hctl, IPROP_INIWIZ_VALUE, (LONG)(LPSTR) szData );
return 0;
}
case INI_WRITE :
{
GetIniFileProperty(hctl, szFile, szSection, szEntry , szData );
WritePrivateProfileString (szSection, szEntry, szData, szFile );
return 0;
}
case INI_DELENTRY :
{
GetIniFileProperty(hctl, szFile, szSection, szEntry , NULL );
WritePrivateProfileString (szSection, szEntry, NULL , szFile );
return 0;
}
case INI_DELSECTION :
{
GetIniFileProperty(hctl, szFile, szSection, NULL , NULL );
WritePrivateProfileString (szSection, NULL , NULL , szFile );
return 0;
}
}
}
break;
case VBM_INITPROPPOPUP :
if ( wp == IPROP_INIWIZ_ABOUT )
return HwndInitAboutPopup();
break;
case WM_NCCREATE :
{
if ( VBGetMode()== MODE_RUN )
{
HWND hParent;
hParent = GetParent(hwnd);
/* Find an empty spot and initialize the VBX Info Array */
for(i=0;i<MAX_VBXS;i++)
if ( INIWIZ[i].hctl == NULL )
{
INIWIZ[i].hControl = hwnd;
INIWIZ[i].hctl = hctl;
INIWIZ[i].hParent = hParent;
INIWIZ[i].lpfnOldProc = (FARPROC)NULL;
break;
}
else
if ( INIWIZ[i].hParent == hParent )
{
MessageBox ( hwnd,"Too Many INI VBXS on One Form!", NULL, MB_OK );
return 0L;
}
if (i==MAX_VBXS)
{
MessageBox ( hwnd,"Too Many INI VBXS", NULL, MB_OK );
return 0L;
}
}
}
VBSetControlProperty(hctl, IPROP_INIWIZ_ABOUT,
(LONG)(LPSTR)"Click on \"...\" for the About Box");
break;
case WM_CREATE:
switch (VBGetMode())
{
// This will only be processed during run mode.
case MODE_RUN:
if ((i=SearchVBXINFOByHCTL(hctl)) != -1 )
{
FARPROC lpfnOldProc = (FARPROC) NULL ;
// Get the address instance to normal proc.
lpfnOldProc = (FARPROC) GetWindowLong(INIWIZ[i].hParent, GWL_WNDPROC) ;
// Reset the address instance to the new proc.
SetWindowLong (INIWIZ[i].hParent,GWL_WNDPROC, (LONG) SbClsProc) ;
INIWIZ[i].lpfnOldProc = lpfnOldProc;
}
else
return -1L;
break ;
}
break ;
}
// Call the default VB for Windows proc.
return VBDefControlProc(hctl, hwnd, msg, wp, lp);
}
LONG FAR PASCAL _export SbClsProc (HWND hwnd, USHORT msg,USHORT wp, LONG lp)
{
int i;
if ((i=SearchVBXINFOByHPARENT(hwnd)) == -1) return 0L;
switch (msg)
{
case WM_WININICHANGE:
{
if ((LPINIWIZINFO)LpIniDEREF(INIWIZ[i].hctl)->bNotify )
{
CHANGEPARAMS cp;
cp.hlstrSection = VBCreateHlstr((LPSTR)lp, lstrlen((LPSTR)lp));
VBFireEvent(INIWIZ[i].hctl, IEVENT_INIWIZ_CHANGE, &cp );
VBDestroyHlstr(cp.hlstrSection);
return 0;
}
else
break;
}
break;
case WM_DESTROY:
// Reset the Old Window Proc and Also free up the INIWIZ array slot
if ((i=SearchVBXINFOByHPARENT(hwnd)) != -1)
{
SetWindowLong (INIWIZ[i].hParent, GWL_WNDPROC,
(LONG) INIWIZ[i].lpfnOldProc) ;
INIWIZ[i].hctl = NULL;
}
break ;
}
// Call INIWIZCtlProc to process any other messages.
return (CallWindowProc(INIWIZ[i].lpfnOldProc, hwnd, msg, wp, lp));
}
static int SearchVBXINFOByHCTL ( HCTL hCtl )
{
int i;
for(i=0;i<MAX_VBXS;i++)
if ( INIWIZ[i].hctl != NULL )
if (INIWIZ[i].hctl == hCtl )
return i;
return -1 ; // Not Found
}
static int SearchVBXINFOByHPARENT ( HWND hParent)
{
int i;
for(i=0;i<MAX_VBXS;i++)
if ( INIWIZ[i].hctl != NULL )
if (INIWIZ[i].hParent == hParent )
return i;
return -1 ; // Not Found
}
static void GetIniFileProperty(HCTL hCtl, LPSTR lpszFile, LPSTR lpszSection, LPSTR lpszEntry , LPSTR lpszValue )
{
HSZ hszFile, hszSection, hszEntry, hszValue;
if (lpszFile)
{
VBGetControlProperty ( hCtl, IPROP_INIWIZ_FILE , &hszFile );
lstrcpy ( lpszFile , VBDerefHsz(hszFile ));
VBDestroyHsz ( hszFile );
}
if (lpszSection)
{
VBGetControlProperty ( hCtl, IPROP_INIWIZ_SECTION , &hszSection );
lstrcpy ( lpszSection , VBDerefHsz(hszSection ));
VBDestroyHsz ( hszSection );
}
if (lpszEntry)
{
VBGetControlProperty ( hCtl, IPROP_INIWIZ_ENTRY , &hszEntry );
lstrcpy ( lpszEntry , VBDerefHsz(hszEntry ));
VBDestroyHsz ( hszEntry );
}
if (lpszValue)
{
VBGetControlProperty ( hCtl, IPROP_INIWIZ_VALUE , &hszValue );
lstrcpy ( lpszValue , VBDerefHsz(hszValue ));
VBDestroyHsz ( hszValue );
}
}
static HWND HwndInitAboutPopup
(
VOID
)
{
return CreateWindow(CLASS_ABOUTPOPUP, NULL, WS_POPUP,
0, 0, 0, 0, NULL, NULL,
hModDLL, NULL);
}
//---------------------------------------------------------------------------
// We asked to show ourself, remain invisible and post a CM_OPENABOUTDLG to
// ourself. When we receive this message, open the dialog box.
//---------------------------------------------------------------------------
LONG _export FAR PASCAL AboutPopupWndProc
(
HWND hwnd,
USHORT msg,
USHORT wp,
LONG lp
)
{
FARPROC Ctl3dRegister, Ctl3dAutoSubClass,Ctl3dUnRegister;
switch (msg)
{
case WM_SHOWWINDOW:
if (wp)
{
PostMessage(hwnd, CM_OPENABOUTDLG, 0, 0L);
return 0L;
}
break;
case CM_OPENABOUTDLG:
if ( (hMod3d = LoadLibrary ( "CTL3DV2.DLL")) < HINSTANCE_ERROR )
hMod3d = NULL ;
else
{
Ctl3dRegister = GetProcAddress ( hMod3d, "Ctl3dRegister");
Ctl3dAutoSubClass = GetProcAddress ( hMod3d, "Ctl3dAutoSubClass" );
Ctl3dRegister (hModDLL);
Ctl3dAutoSubClass ( hModDLL );
}
VBDialogBoxParam(hModDLL, "AboutDlg", (FARPROC)AboutDlgProc, 0L);
if ( hMod3d )
{
Ctl3dUnRegister = GetProcAddress ( hMod3d, "Ctl3dUnregister");
Ctl3dUnRegister ( hModDLL );
}
FreeLibrary ( hMod3d );
return 0L;
}
return DefWindowProc(hwnd, msg, wp, lp);
}
BOOL FAR PASCAL _export AboutDlgProc
(
HWND hDlg,
USHORT msg,
USHORT wp,
LONG lp
)
{
switch (msg)
{
case WM_COMMAND:
switch (wp)
{
case IDOK:
EndDialog(hDlg, TRUE);
return TRUE;
case IDCANCEL:
EndDialog(hDlg, FALSE );
return TRUE;
}
}
return FALSE;
}