home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 8
/
CDASC08.ISO
/
NEWS
/
4418
/
DEMO
/
SOURCE.ZIP
/
BMPEF.CPP
next >
Wrap
C/C++ Source or Header
|
1993-08-24
|
17KB
|
464 lines
/****************************************************************************
PROGRAM:
PURPOSE: BmpEf template for Windows applications
FUNCTIONS:
WinMain() - calls initialization function, processes message loop
InitApplication() - initializes window data and registers window
InitInstance() - saves instance handle and creates main window
MainWndProc() - processes messages
About() - processes messages for "About" dialog box
COMMENTS:
****************************************************************************/
#include <windows.h>
#include <windowsx.h>
#include <shellapi.h>
#include <commdlg.h>
#include <string.h>
#include "winx31ad.h"
#include "usect3D.h"
#include "gv_tbar.h"
#define HEREGLOBAL
#include "bmpef.h"
#include "statetoo.h"
HBITMAP HBitTB;
HWND hWndTB;
HWND hWndDraw;
HWND hWndClient;
#define WINDOWMENU 2 /* position of window menu */
/****************************************************************************
FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
****************************************************************************/
int PASCAL WinMain(
HANDLE hInstance, /* current instance */
HANDLE hPrevInstance, /* previous instance */
LPSTR lpCmdLine, /* command line */
int nCmdShow) /* show-window type (open/icon) */
{
MSG msg; /* message */
LoadRegistCtlModule(hInstance);
useCtl3dAutoSubclass(hInstance);
if (!hPrevInstance) /* Other instances of app running? */
if (!InitApplication(hInstance)) /* Initialize shared things */
return (FALSE); /* Exits if unable to initialize */
/* Perform initializations that apply to a specific instance */
if (!InitInstance(hInstance, nCmdShow))
return (FALSE);
/* Acquire and dispatch messages until a WM_QUIT message is received. */
while (GetMessage(&msg, /* message structure */
NULL, /* handle of window receiving the message */
NULL, /* lowest message to examine */
NULL)) /* highest message to examine */
{
TranslateMessage(&msg); /* Translates virtual key codes */
DispatchMessage(&msg); /* Dispatches message to window */
}
UnregTBClass (hInstance);
useCtl3dUnregister(hInstance);
return (msg.wParam); /* Returns the value from PostQuitMessage */
}
/****************************************************************************
FUNCTION: InitApplication(HANDLE)
PURPOSE: Initializes window data and registers window class
****************************************************************************/
BOOL InitApplication(HANDLE hInstance)
{
WNDCLASS wc,wc2;
/* Fill in window class structure with parameters that describe the */
/* main window. */
wc.style = 0 ; //CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0; /* No per-class extra data. */
wc.cbWndExtra = 0; /* No per-window extra data. */
wc.hInstance = hInstance; /* Application that owns the class. */
wc.hIcon = LoadIcon(hInstance,"BMPEFICON");
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = "BMPEFMENU"; /* Name of menu resource in .RC file. */
wc.lpszClassName = "BmpEfWClass"; /* Name used in call to CreateWindow. */
wc2.style = 0 ; //CS_HREDRAW | CS_VREDRAW;
wc2.lpfnWndProc = DrawWndProc;
wc2.cbClsExtra = 0;
wc2.cbWndExtra = sizeof(LPVOID);
wc2.hInstance = hInstance;
wc2.hIcon = NULL;
wc2.hCursor = LoadCursor(NULL, IDC_ARROW);
wc2.hbrBackground = GetStockObject(LTGRAY_BRUSH);
wc2.lpszMenuName =NULL ;
wc2.lpszClassName = "BmpEfWDrawClass";
/* Register the window class and return success/failure code. */
wc2.style = wc2.style | CS_OWNDC;
return (RegisterClass(&wc) && RegisterTBClass(hInstance) && RegisterClass(&wc2));
}
/****************************************************************************
FUNCTION: InitInstance(HANDLE, int)
PURPOSE: Saves instance handle and creates main window
COMMENTS:
This function is called at initialization time for every instance of
this application.
****************************************************************************/
BOOL InitInstance(
HANDLE hInstance, /* Current instance identifier. */
int nCmdShow) /* Param for first ShowWindow() call. */
{
HWND hWnd; /* Main window handle. */
ghInst = hInstance;
HBitTB = LoadBitmap (ghInst,"TOOLBMP") ;
/* Create a main window for this application instance. */
hWnd = CreateWindow(
"BmpEfWClass", /* See RegisterClass() call. */
"BmpEf Sample Application", /* Text for window title bar. */
WS_OVERLAPPEDWINDOW, /* Window style. */
CW_USEDEFAULT, /* Default horizontal position. */
CW_USEDEFAULT, /* Default vertical position. */
CW_USEDEFAULT, /* Default width. */
CW_USEDEFAULT, /* Default height. */
NULL, /* Overlapped windows have no parent. */
NULL, /* Use the window class menu. */
hInstance, /* This instance owns this window. */
NULL /* Pointer not needed. */
);
/* If window could not be created, return "failure" */
if (!hWnd)
return (FALSE);
/* Make the window visible; update its client area; and return "success" */
ShowWindow(hWnd, nCmdShow); /* Show the window */
UpdateWindow(hWnd); /* Sends WM_PAINT message */
return (TRUE); /* Returns the value from PostQuitMessage */
}
/****************************************************************************
FUNCTION: MainWndProc(HWND, UINT, WPARAM, LPARAM)
****************************************************************************/
HWND CreateChild(LPSTR lpFn)
{
MDICREATESTRUCT mcs;
mcs.szClass = "BmpEfWDrawClass";
mcs.szTitle = "BmpEf";
mcs.hOwner = ghInst;
mcs.x = CW_USEDEFAULT;
mcs.y = CW_USEDEFAULT;
mcs.cx = CW_USEDEFAULT;
mcs.cy = CW_USEDEFAULT;
mcs.style = 0 ;
mcs.lParam = (LPARAM)lpFn;
return (HWND)SendMessage(hWndClient,WM_MDICREATE,0,
(LPARAM)((LPMDICREATESTRUCT)&mcs));
}
BOOL DoOpen(HWND hWnd)
{
char szFileTitle[256];
OPENFILENAME ofn;
char szFilter [256] ;
char szExt[]="BMP";
int i,iLnsz;
LPSTR lpszFile;
LPSTR lpszPosSpace,lpszNextSpace;
char szFullName[256];
#define SIZEBUFOPEN 32700
if ((lpszFile = (LPSTR)GlobalAllocPtr(GHND,SIZEBUFOPEN+2))==NULL) return FALSE;
LoadString(ghInst,IDS_TYPECDLG,szFilter,sizeof(szFilter)-1);
iLnsz=lstrlen(szFilter);
for (i=0;i<iLnsz;i++)
if (szFilter[i] == '|') szFilter[i] = '\0';
_fmemset(&ofn, 0, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hWnd;
ofn.lpstrFilter = (LPSTR)szFilter ;
ofn.nFilterIndex = 1;
ofn.lpstrFile = lpszFile;
ofn.nMaxFile = SIZEBUFOPEN;
ofn.lpstrDefExt=szExt;
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = sizeof(szFileTitle);
//ofn.lpstrInitialDir = szDirName;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT;
if (GetOpenFileName(&ofn)==FALSE)
{
GlobalFreePtr(lpszFile);
return FALSE;
}
SetCursor(LoadCursor(NULL,IDC_WAIT));
if ((lpszPosSpace=_fstrchr(lpszFile,(int)' '))==NULL)
{
if (!CreateChild(lpszFile))
{
//wsprintf(szMsg,szErr,lpszFile);
//MessageBox(hWnd,szMsg,NULL,MB_OK);
}
//else fDirty = TRUE;
}
else
{
*lpszPosSpace='\0';
if (*(lpszFile+lstrlen(lpszFile)-1)=='\\')
*(lpszFile+lstrlen(lpszFile)-1)='\0';
do
{
lpszNextSpace=_fstrchr(lpszPosSpace+1,(int)' ');
if (lpszNextSpace!=NULL) *lpszNextSpace='\0';
lstrcpy(szFullName,lpszFile);
lstrcat(szFullName,"\\");
lstrcat(szFullName,lpszPosSpace+1);
if (!CreateChild(szFullName))
{
//wsprintf(szMsg,szErr,(LPSTR)szFullName);
//if (MessageBox(hWnd,szMsg,NULL,MB_OKCANCEL)==IDCANCEL)
// {
// break;
// }
}
//else fDirty = TRUE;
}
while ((lpszPosSpace=lpszNextSpace)!=NULL);
}
SetCursor(LoadCursor(NULL,IDC_ARROW));
return TRUE;
}
long CALLBACK __export MainWndProc(
HWND hWnd, /* window handle */
UINT message, /* type of message */
WPARAM wParam, /* additional information */
LPARAM lParam) /* additional information */
{
RECT rect;
CLIENTCREATESTRUCT clientCreate;
switch (message) {
case WM_CREATE:
#ifdef WIN32
SetWindowText(hWnd,"BMPEF32 - (c) Gilles VOLLANT");
#else
SetWindowText(hWnd,"BMPEF16 - (c) Gilles VOLLANT");
#endif
GetClientRect(hWnd,&rect);
rect.bottom=SIZEY;
hWndTB=CreateTB(hWnd,ghInst,HBitTB,rect);
AddBtn(hWndTB,IDM_NEW,0,BSTY_ACTION,0,0,0,0,0);
AddBtn(hWndTB,IDM_OPEN,1,BSTY_ACTION,0,0,0,0,0);
AddBtn(hWndTB,IDM_SAVEAS,2,BSTY_ACTION,0,0,0,0,0);
AddBtn(hWndTB,IDM_ROTATE,9,BSTY_ACTION,0,0,0,0,0);
//AddBtn(hWndTB,IDM_SETUPPRN,9,BSTY_ACTION,0,0,0,0,0);
//AddBtn(hWndTB,IDM_COPY ,4,BSTY_ACTION,0,0,0,0,0);
//AddBtn(hWndTB,IDM_PRINT ,9,BSTY_ACTION,0,0,0,0,0);
//AddBtn(hWndTB,IDM_OPENPARAMBOX,6,BSTY_ACTION,0,0*5,0,0,0);
DoSetTextInfo(" ");
clientCreate.hWindowMenu = GetSubMenu (GetMenu(hWnd),WINDOWMENU);
clientCreate.idFirstChild = IDM_FIRSTCHILD;
hWndClient = CreateWindow(
"MDICLIENT",
NULL,
WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
hWnd,
0,
ghInst,
(LPSTR)&clientCreate
);
DragAcceptFiles(hWnd,TRUE);
break;
case WM_SIZE:
GetClientRect(hWnd,&rect);
SetWindowPos(hWndTB,NULL,0,0,rect.right,SIZEY,SWP_NOZORDER);
SetWindowPos(hWndClient,NULL,0,SIZEY,rect.right,rect.bottom-(2*SIZEY),SWP_NOZORDER);
rect.top = rect.bottom - SIZEY;
DoSetInfo(hWnd,&rect);
return NULL;
case WM_PAINT:
{
HDC hDC;
PAINTSTRUCT ps;
hDC = BeginPaint(hWnd,&ps);
DoPaintInfo(hDC);
EndPaint(hWnd,&ps);
break;
}
case WM_DROPFILES:
{
HANDLE hDrop = (HANDLE)wParam;
UINT uiNbFile,i;
char szFn[128];
uiNbFile = DragQueryFile(hDrop,(UINT)-1,0,0);
for (i=0;i<uiNbFile;i++)
{
DragQueryFile(hDrop,i,szFn,sizeof(szFn)-1);
CreateChild(szFn);
}
DragFinish(hDrop);
break;
}
case WM_COMMAND: /* message: command from application menu */
switch (GET_WM_COMMAND_ID(wParam,lParam))
{
case IDM_TILE:
SendMessage(hWndClient,WM_MDITILE,0,0);
return 0;
case IDM_CASCADE:
SendMessage(hWndClient,WM_MDICASCADE,0,0);
return 0;
case IDM_ARRANGE:
SendMessage(hWndClient,WM_MDIICONARRANGE,0,0);
return 0;
case IDM_OPEN:
DoOpen(hWnd);
break;
case IDM_ABOUT :
DialogBox(ghInst, /* current instance */
"AboutBox", /* resource to use */
hWnd, /* parent handle */
(DLGPROC)About); /* About() instance address */
break;
case IDM_EXIT:
SendMessage(hWnd,WM_CLOSE,0,0);
break;
default:
{
HWND hWndChild;
hWndChild = (HWND)SendMessage(hWndClient,WM_MDIGETACTIVE,0,0);
if (IsWindow(hWndChild))
SendMessage(hWndChild,message,wParam,lParam);
}
}
break;
case WM_ACTIVATE :
case WM_QUERYNEWPALETTE:
{
HWND hWndChild;
hWndChild = (HWND)SendMessage(hWndClient,WM_MDIGETACTIVE,0,0);
if (IsWindow(hWndChild))
return SendMessage(hWndChild,message,wParam,lParam);
break;
}
case WM_DESTROY: /* message: window being destroyed */
PostQuitMessage(0);
break;
}
return (DefFrameProc(hWnd,hWndClient, message, wParam, lParam));
}
/****************************************************************************
FUNCTION: About(HWND, unsigned, WORD, LONG)
PURPOSE: Processes messages for "About" dialog box
MESSAGES:
WM_INITDIALOG - initialize dialog box
WM_COMMAND - Input received
COMMENTS:
No initialization is needed for this particular dialog box, but TRUE
must be returned to Windows.
Wait for user to click on "Ok" button, then close the dialog box.
****************************************************************************/
BOOL CALLBACK __export About(
HWND hDlg, /* window handle of the dialog box */
unsigned message, /* type of message */
WORD wParam, /* message-specific information */
LONG lParam)
{
switch (message) {
case WM_INITDIALOG: /* message: initialize dialog box */
return (TRUE);
case WM_COMMAND: /* message: received a command */
if (wParam == IDOK /* "OK" box selected? */
|| wParam == IDCANCEL) { /* System menu close command? */
EndDialog(hDlg, TRUE); /* Exits the dialog box */
return (TRUE);
}
break;
}
return (FALSE); /* Didn't process a message */
}