home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Troubleshooting Netware Systems
/
CSTRIAL0196.BIN
/
attach
/
msj
/
v10n05
/
gotcha.exe
/
CD32DEMO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-01
|
8KB
|
241 lines
//
// CD32DEMO.C -- Demonstrates modifying the new Explorer-Like
// file open dialog.
//
#define INMAIN // Only define this for the file with WinMain in it!
#include "cd32demo.h"
#include <commdlg.h>
#include <dlgs.h>
// Private function prototypes (this file scope only)
LONG WndProc_WM_COMMAND ( WINDOWS_PARAMS );
BOOL bShowCustomOpenFileDialog ( HWND hWndParent );
DLGPROC CustomTemplateDlgProc (DIALOG_PARAMS);
/**************************************************************
* *
* WinMain *
* *
**************************************************************/
int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow )
{
MSG msg ;
WNDCLASS wndclass ;
if (!hPrevInstance)
{
// Register Parent Window Class
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNCLIENT;
wndclass.lpfnWndProc = (WNDPROC)CD32DEMO_WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon ( hInstance, "BASE1");
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = GetStockObject ( GRAY_BRUSH ) ;
wndclass.lpszMenuName = (LPSTR)"PlainMenu" ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
return FALSE;
}
ghInst = hInstance;
ghWnd = CreateWindow (szAppName,
szCaption,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0,
CW_USEDEFAULT, 0,
(HWND)NULL,
(HMENU)NULL,
hInstance,
(LPVOID)NULL) ;
ShowWindow ( ghWnd, nCmdShow );
UpdateWindow ( ghWnd );
while (GetMessage((LPMSG)&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
/*********************************************************************
* *
* WndProc: Main Message Translator *
* *
*********************************************************************/
WINPROC CD32DEMO_WndProc ( WINDOWS_PARAMS )
{
switch ( msg )
{
case WM_DESTROY :
PostQuitMessage (0) ;
break ;
case WM_COMMAND :
return WndProc_WM_COMMAND ( hWnd, msg, wParam, lParam );
break;
default :
return DefWindowProc ( hWnd, msg, wParam, lParam );
}
return 0L ;
}
/*********************************************************************
* *
* *
* *
*********************************************************************/
LONG WndProc_WM_COMMAND ( WINDOWS_PARAMS )
{
CRACKER_VARS
CRACK_MESSAGEsc
switch ( CRACKER_wID )
{
case IDM_FILEOPEN :
bShowCustomOpenFileDialog ( hWnd );
break;
default:
return DefWindowProc ( hWnd, msg, wParam, lParam ) ;
break;
}
}
/*********************************************************************
* *
* *
* *
*********************************************************************/
BOOL bShowCustomOpenFileDialog ( HWND hWndParent )
{
OPENFILENAME OpenFileName;
TCHAR szFile[MAX_PATH] = "\0";
lstrcpy( szFile, "");
// Fill in the OPENFILENAME structure to support a template and hook.
OpenFileName.lStructSize = sizeof(OPENFILENAME);
OpenFileName.hwndOwner = hWndParent;
OpenFileName.hInstance = ghInst;
OpenFileName.lpstrFilter = NULL;
OpenFileName.lpstrCustomFilter = NULL;
OpenFileName.nMaxCustFilter = 0;
OpenFileName.nFilterIndex = 0;
OpenFileName.lpstrFile = szFile;
OpenFileName.nMaxFile = sizeof(szFile);
OpenFileName.lpstrFileTitle = NULL;
OpenFileName.nMaxFileTitle = 0;
OpenFileName.lpstrInitialDir = NULL;
OpenFileName.lpstrTitle = "Open File";
OpenFileName.nFileOffset = 0;
OpenFileName.nFileExtension = 0;
OpenFileName.lpstrDefExt = NULL;
OpenFileName.lCustData = (LPARAM)NULL;
OpenFileName.lpfnHook = CustomTemplateDlgProc; // See below
OpenFileName.lpTemplateName = MAKEINTRESOURCE(IDD_DIALOG1); // In RC file
OpenFileName.Flags = OFN_SHOWHELP | OFN_EXPLORER | OFN_ENABLEHOOK |
OFN_ENABLETEMPLATE;
// Call the common dialog function.
return GetOpenFileName(&OpenFileName);
}
/*********************************************************************
* *
* *
* *
*********************************************************************/
DLGPROC CustomTemplateDlgProc (DIALOG_PARAMS)
{
CRACKER_VARS
switch (msg)
{
case WM_NOTIFY: // This is sent by the common dialog to our child dialog
switch (((LPOFNOTIFY)lParam)->hdr.code)
{
case CDN_SELCHANGE: // User changed file selection
{
char szFullName[MAX_PATH];
char szText[MAX_PATH + 2 + 32];
BOOL bErr = TRUE;
// Get the full path of the file the user selected
// Notice how we use the parent of this dialog, which
// is the actual common dialog.
if (CommDlg_OpenSave_GetFilePath(GetParent(hDlg),
szFullName, sizeof(szFullName)) <= sizeof(szFullName))
{
HFILE hFile;
OFSTRUCT of;
LONG dwSize;
// Calculate its size
if (hFile = OpenFile ( szFullName, &of, OF_READ ))
{
// SetFilePointer replaces _llseek
dwSize = SetFilePointer((HANDLE)hFile, 0, NULL, FILE_END);
// Close yer file
_lclose (hFile);
// Format the string
wsprintf ( szText, "%s, %d bytes", szFullName, dwSize);
// Set the text in our child dialog
SetDlgItemText(hDlg, IDC_NAMESIZE, szText);
// We made it, Yogi!
bErr = FALSE;
}
}
if (bErr) SetDlgItemText(hDlg, IDC_NAMESIZE, "");
} // end case
} // end switch
break;
case WM_COMMAND: // User causes a command notification in our child dialog
CRACK_MESSAGEsc
switch ( CRACKER_wID )
{
case IDC_CHEESE: // Clicked on the cheese button!
MessageBox ( GetParent(hDlg), "David Campbell Likes Cheese", "MSJ", MB_OK );
break;
default:
return FALSE;
}
break;
default:
return FALSE;
}
return TRUE;
}