注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Kandy

长风破浪会有时,直挂云帆济沧海!

 
 
 

日志

 
 

显示元文件代码  

2009-09-21 17:52:34|  分类: 默认分类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

// EMF.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "EMF.h"

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;        // current instance
TCHAR szTitle[MAX_LOADSTRING];     // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];   // the main window class name
TCHAR szAppName[] = TEXT ("EmfView") ;
// Forward declarations of functions included in this code module:
ATOM    MyRegisterClass(HINSTANCE hInstance);
BOOL    InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
 UNREFERENCED_PARAMETER(hPrevInstance);
 UNREFERENCED_PARAMETER(lpCmdLine);

  // TODO: Place code here.
 MSG msg;
 HACCEL hAccelTable;

 // Initialize global strings
 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
 LoadString(hInstance, IDC_EMF, szWindowClass, MAX_LOADSTRING);
 MyRegisterClass(hInstance);

 // Perform application initialization:
 if (!InitInstance (hInstance, nCmdShow))
 {
  return FALSE;
 }

 hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_EMF));

 // Main message loop:
 while (GetMessage(&msg, NULL, 0, 0))
 {
  if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  {
   TranslateMessage(&msg);
   DispatchMessage(&msg);
  }
 }

 return (int) msg.wParam;
}

 

//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    This function and its usage are only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
 WNDCLASSEX wcex;

 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, MAKEINTRESOURCE(IDI_EMF));
 wcex.hCursor  = LoadCursor(NULL, IDC_ARROW);
 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
 wcex.lpszMenuName = MAKEINTRESOURCE(IDC_EMF);
 wcex.lpszClassName = szWindowClass;
 wcex.hIconSm  = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

 return RegisterClassEx(&wcex);
}

//
//   FUNCTION: InitInstance(HINSTANCE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND - process the application menu
//  WM_PAINT - Paint the main window
//  WM_DESTROY - post a quit message and return
//
//
HPALETTE CreatePaletteFromMetaFile (HENHMETAFILE hemf)
{
 HPALETTE    hPalette;
 int         iNum ;
 LOGPALETTE *plp ;

 if (!hemf)
  return NULL ;
 if (0 == (iNum = GetEnhMetaFilePaletteEntries (hemf, 0, NULL)))
  return NULL ;
 plp =(LOGPALETTE*) malloc (sizeof (LOGPALETTE) + (iNum - 1) * sizeof (PALETTEENTRY)) ;
 plp->palVersion    = 0x0300 ;
 plp->palNumEntries = iNum ;

 GetEnhMetaFilePaletteEntries (hemf, iNum, plp->palPalEntry) ;
 hPalette = CreatePalette (plp) ;
 free (plp) ;
 return hPalette ;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
 int wmId, wmEvent;
 HDC                hdc;
 HPALETTE           hPalette ;
 PAINTSTRUCT         ps ;
 RECT               rect ;
 static HENHMETAFILE hemf ;
 OPENFILENAME ofn;
 static TCHAR  szFileName [MAX_PATH];
 static TCHAR szTitleName [MAX_PATH];
 static TCHAR  szFilter[] =TEXT ("Enhanced Metafiles (*.EMF)\0*.emf\0All Files (*.*)\0*.*\0\0") ;

 switch (message)
 {
 case WM_COMMAND:
  wmId    = LOWORD(wParam);
  wmEvent = HIWORD(wParam);
  // Parse the menu selections:
  switch (wmId)
  {
  case IDM_ABOUT:
   DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
   break;
  case IDM_EXIT:
   DestroyWindow(hWnd);
   break;
  case ID_FILE_OPEN:
   ofn.lStructSize          = sizeof (OPENFILENAME) ;
   ofn.hwndOwner            = hWnd ;
   ofn.hInstance            = NULL ;
   ofn.lpstrFilter          = szFilter ;
   ofn.lpstrCustomFilter       = NULL ;
   ofn.nMaxCustFilter       = 0 ;
   ofn.nFilterIndex         = 0 ;
   ofn.lpstrFile            = szFileName ;
   ofn.nMaxFile             = MAX_PATH ;
   ofn.lpstrFileTitle       = szTitleName ;
   ofn.nMaxFileTitle        = MAX_PATH ;
   ofn.lpstrInitialDir      = NULL ;
   ofn.lpstrTitle           = NULL ;
   ofn.Flags                = 0 ;
   ofn.nFileOffset          = 0 ;
   ofn.nFileExtension       = 0 ;
   ofn.lpstrDefExt          = TEXT ("emf") ;
   ofn.lCustData            = 0 ;
   ofn.lpfnHook             = NULL ;
   ofn.lpTemplateName       = NULL ;
   break;
  default:
   return DefWindowProc(hWnd, message, wParam, lParam);
  }
  GetOpenFileName(&ofn);
  if (hemf)
  {
   DeleteEnhMetaFile (hemf) ;
   hemf = NULL ;
  }
  hemf = GetEnhMetaFile (szFileName) ;
  InvalidateRect (hWnd, NULL, TRUE) ;

  if (hemf == NULL)
  {
   MessageBox ( hWnd, TEXT ("Cannot load metafile"),
    szAppName, MB_ICONEXCLAMATION | MB_OK) ;
  }
  break;
 case WM_PAINT:
  hdc = BeginPaint(hWnd, &ps);
  // TODO: Add any drawing code here...
  if (hemf)
  {
   if ( hPalette = CreatePaletteFromMetaFile (hemf))
   {
    SelectPalette (hdc, hPalette, FALSE) ;
    RealizePalette (hdc) ;
   }
   GetClientRect (hWnd, &rect) ;
   PlayEnhMetaFile (hdc, hemf, &rect) ;

   if (hPalette)
    DeleteObject (hPalette) ;
  }
  EndPaint(hWnd, &ps);
  break;
 case WM_DESTROY:
  if (hemf)
   DeleteEnhMetaFile (hemf) ;
  PostQuitMessage(0);
  break;
 default:
  return DefWindowProc(hWnd, message, wParam, lParam);
 }
 return 0;
}

// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
 UNREFERENCED_PARAMETER(lParam);
 switch (message)
 {
 case WM_INITDIALOG:
  return (INT_PTR)TRUE;

 case WM_COMMAND:
  if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  {
   EndDialog(hDlg, LOWORD(wParam));
   return (INT_PTR)TRUE;
  }
  break;
 }
 return (INT_PTR)FALSE;
}

  评论这张
 
阅读(105)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017