#include <windows.h>
#include <commctrl.h>
#include "resource.h"
#pragma comment(linker, "/opt:nowin98")
#define USE_COM
/************************ Static Function Declarations
**********************/
static void cmsback_SelectFolder (HWND hWnd);
/********************************************************************/
HINSTANCE hInstance;
char szAppName[30];
BOOL CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInst, // Application Instance Handle
HINSTANCE hPrevInstance, // Previous Instance Handle
LPSTR lpszCmdLine, // Pointer to Command Line
int nCmdShow) // Show Window Option
{
MSG msg;
HWND hWndMain;
WNDCLASS wndclass;
hInstance = hInst;
lstrcpy(szAppName, "cmsback");
#ifdef USE_COM
//# test1
// CoInitilize();
// # test2
OleInitialize(NULL);
#endif
if(NULL == (hWndMain = CreateDialog(hInstance,
MAKEINTRESOURCE(cm0back),
NULL,
MainWndProc)))
{
MessageBox(NULL, "Unable to display main dialog", "System Error",
MB_OK);
return FALSE;
}
#ifdef USE_COM
SetWindowText(hWndMain, "OFN Test (Use COM)");
#else
SetWindowText(hWndMain, "OFN Test (Without COM)");
#endif
ShowWindow(hWndMain, nCmdShow);
UpdateWindow(hWndMain);
while(GetMessage(&msg, NULL, 0, 0))
if(!IsDialogMessage(hWndMain, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
#ifdef USE_COM
OleUninitialize();
#endif
return msg.wParam;
}
BOOL CALLBACK MainWndProc(HWND hWnd, UINT uMessage, WPARAM wParam,
LPARAM lParam)
{
WORD CtlId;
WORD Notify;
HWND CtlWnd;
switch(uMessage)
{
case WM_INITDIALOG :
return TRUE;
case WM_COMMAND :
#ifdef WIN32
CtlId = LOWORD(wParam);
Notify = HIWORD(wParam);
CtlWnd = (HWND)lParam;
#else
CtlId = wParam;
Notify = HIWORD(lParam);
CtlWnd = (HWND)LOWORD(lParam);
#endif
if(!CtlWnd)
{ // Process Menu Commands
switch(CtlId) // Determine which Menu ID
{
}
}
else
{
switch(CtlId)
{
case CMSBACK_PBBROWSE :
{
if (Notify == BN_CLICKED)
cmsback_SelectFolder(hWnd);
}
break;
case IDCANCEL :
{
PostMessage(hWnd, WM_CLOSE, 0, 0);
}
break;
}
}
break;
case WM_CLOSE :
{
DestroyWindow(hWnd);
return TRUE;
}
case WM_DESTROY :
{
PostQuitMessage(0);
break;
}
default :
return FALSE;
}
return FALSE;
}
/**************************************************************************
*
*
* Function: cmsback_SelectFolder()
*
* Description: This function looks after the Folder Selecltion.
*
*
* Entry Conditions: The Window Handle Must be Passed.
*
*
* Exit Conditions: None.
*
*
*/
static void cmsback_SelectFolder(HWND hWnd)
{
OPENFILENAME FileInfo;
char FullPath[260];
TCHAR curDir[MAX_PATH];
GetCurrentDirectory(MAX_PATH, curDir);
/* Clear the File Information. */
memset(&FileInfo, (BYTE)0, sizeof(FileInfo));
/* Initialise the FileInfo Structure. */
FileInfo.lStructSize = sizeof(FileInfo);
FileInfo.hwndOwner = hWnd; // The Owner Window Handle.
FileInfo.lpstrFilter = "All Files\0*.*\0"; // File Filter.
FileInfo.nFilterIndex = 1;
FileInfo.lpstrFile = FullPath;
FileInfo.nMaxFile = sizeof(FullPath);
FileInfo.lpstrFile[0] = '\0';
FileInfo.lpstrInitialDir = curDir;
FileInfo.lpstrTitle = "Crash Test #12";
FileInfo.Flags = OFN_HIDEREADONLY |
OFN_FILEMUSTEXIST |
OFN_PATHMUSTEXIST;
/* Display the Open File Dialog. */
if (GetOpenFileName(&FileInfo) == 0)
{
#if 0
MessageBox(GetDesktopWindow(),
"User Clicked Cancel",
"Information",
MB_OK | MB_ICONHAND | MB_TASKMODAL);
#endif
return;
}
MessageBox(GetDesktopWindow(),
"User Clicked Open",
"Information",
MB_OK | MB_ICONHAND | MB_TASKMODAL);
}