mwin01.cpp


#include <windows.h>
#include <tchar.h>
#include "openfnm.h"

#define MY_CLASS_NAME   _T("MyClass")
#define MY_WINDOW_TITLE _T("Window Title")

// Global variables
HINSTANCE g_hInst;
CMyOpenFileName g_ofn;

/* Prototype */
LRESULT CALLBACK
  WndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  LPSTR lpCmdLine, int nCmdShow )
{
  MSG msg;
  WNDCLASSEX wcex;
  HWND hwnd;

  g_hInst = hInstance;
	
  /* Register the window class for the main window. */
  if( hPrevInstance == NULL )
  {
    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc = WndProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = LoadIcon(hInstance, _T("MyIcon") );
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName = _T("MyMenu");
    wcex.lpszClassName = MY_CLASS_NAME;
    wcex.hIconSm = 0;

    if ( RegisterClassEx( &wcex ) == 0 )
      return 0;
  }
	
  /* Create our window. */
  hwnd = CreateWindow( MY_CLASS_NAME, MY_WINDOW_TITLE, WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
    (HWND)NULL, (HMENU)NULL, hInstance, (LPVOID)NULL );
  /*
   * If the window cannot be created, terminate
   * the application.
   */
  if( hwnd == NULL )
    return 0;

  /* Show the window and paint its contents. */
  ShowWindow( hwnd, nCmdShow );
  UpdateWindow( hwnd );

  /* Start the message loop. */
  while( GetMessage( &msg, (HWND)NULL, 0, 0 ) )
  {
    TranslateMessage( &msg );
    DispatchMessage( &msg );
  }

  /* Return the exit code to the system. */
  return msg.wParam;
}