MainWnd.cpp
Upload User: qianbin
Upload Date: 2009-10-23
Package Size: 617k
Code Size: 4k
Category:

Video Capture

Development Platform:

Visual C++

  1. // MainWnd.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "VfwExample.h"
  5. #include "MainWnd.h"
  6. #include "TipsWareVideoCapture.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. TipsWareVideoCapture *gp_capture_engine;
  13. /////////////////////////////////////////////////////////////////////////////
  14. // MainWnd
  15. MainWnd::MainWnd() : StandardWnd()
  16. {
  17. m_caption_main = "VFW_Ex.";
  18. m_accelerators_key = ::LoadAccelerators(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME));
  19. m_tray_tip = "[VfwExample] 涝聪促";
  20. }
  21. MainWnd::~MainWnd()
  22. {
  23. }
  24. void MainWnd::TrayStateSetup(int parm_command, const char *parm_tip_string)
  25. {
  26. NOTIFYICONDATA taskbar_notify_data;
  27. strcpy(taskbar_notify_data.szTip, parm_tip_string);
  28. switch(parm_command){
  29. case NIM_ADD :
  30. taskbar_notify_data.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
  31. break;
  32. case NIM_DELETE :
  33. taskbar_notify_data.uFlags = 0;
  34. break;
  35. case NIM_MODIFY :
  36. taskbar_notify_data.uFlags = NIF_TIP | NIF_ICON;
  37. break;
  38. }
  39. taskbar_notify_data.uID = (UINT)IDR_MAINFRAME;
  40. taskbar_notify_data.cbSize = sizeof(NOTIFYICONDATA);
  41. taskbar_notify_data.hWnd = this->m_hWnd;
  42. taskbar_notify_data.uCallbackMessage = LM_TRAY_TIP_MESSAGE;
  43. taskbar_notify_data.hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  44. Shell_NotifyIcon(parm_command, &taskbar_notify_data);
  45. }
  46. BEGIN_MESSAGE_MAP(MainWnd, StandardWnd)
  47. //{{AFX_MSG_MAP(MainWnd)
  48. ON_WM_PAINT()
  49. ON_WM_CREATE()
  50. ON_WM_DESTROY()
  51. ON_WM_SYSCOMMAND()
  52. //}}AFX_MSG_MAP
  53. ON_MESSAGE(LM_TRAY_TIP_MESSAGE, OnTrayMessage)
  54. END_MESSAGE_MAP()
  55. /////////////////////////////////////////////////////////////////////////////
  56. // MainWnd message handlers
  57. void MainWnd::OnPaint() 
  58. {
  59. // CPaintDC dc(this);
  60. StandardWnd::OnPaint();
  61. }
  62. int MainWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  63. {
  64. if(StandardWnd::OnCreate(lpCreateStruct) == -1) return -1;
  65. SetWindowSystemMenu(1, 0, 1);
  66. ::SetCursor(::LoadCursor(NULL, IDC_ARROW));
  67. TrayStateSetup(NIM_ADD, (const char *)m_tray_tip);
  68. // VFW甫 积己茄促.
  69. gp_capture_engine = new TipsWareVideoCapture(this);
  70. gp_capture_engine->SetWindowSize(5, 36);
  71. if(gp_capture_engine->InitialVideoCapture(this)){
  72. gp_capture_engine->SetVideoSize(176, 144);
  73. if((gp_capture_engine->GetImageX() != 176) || (gp_capture_engine->GetImageY() != 144)){
  74. MessageBox("厚叼坷 康惑 农扁甫 176*144 农扁肺 嘎苗林技夸!!", "康惑 器镐 促矫瘤沥", MB_ICONASTERISK | MB_ICONINFORMATION);
  75. gp_capture_engine->SetVideoFormat();
  76. }
  77. return 0;
  78. } else {
  79. delete gp_capture_engine;
  80. gp_capture_engine = NULL;
  81. return -1;
  82. }
  83. return 0;
  84. }
  85. void MainWnd::OnDestroy() 
  86. {
  87. if(gp_capture_engine != NULL){
  88. gp_capture_engine->DisconnectCaptureDriver();
  89. delete gp_capture_engine;
  90. gp_capture_engine = NULL;
  91. }
  92. TrayStateSetup(NIM_DELETE, (const char *)m_tray_tip);
  93. StandardWnd::OnDestroy();
  94. }
  95. BOOL MainWnd::PreCreateWindow(CREATESTRUCT& cs) 
  96. {
  97. cs.lpszClass = "VfwExample";
  98. return StandardWnd::PreCreateWindow(cs);
  99. }
  100. BOOL MainWnd::PreTranslateMessage(MSG* pMsg) 
  101. {
  102. if(::TranslateAccelerator(this->m_hWnd, m_accelerators_key, pMsg)) return TRUE;
  103. return StandardWnd::PreTranslateMessage(pMsg);
  104. }
  105. LRESULT MainWnd::OnTrayMessage(WPARAM wParam,LPARAM lParam)
  106. {
  107. if(UINT(wParam)==IDR_MAINFRAME){
  108. if(lParam==WM_LBUTTONDOWN){
  109. OnTrayLeftButton();
  110. }
  111. }
  112. return 0;
  113. }
  114. void MainWnd::OnTrayLeftButton()
  115. {
  116. ShowWindow(SW_SHOWNORMAL);
  117. BringWindowToTop();
  118. SetForegroundWindow();
  119. }
  120. void MainWnd::OnSysCommand(UINT nID, LPARAM lParam) 
  121. {
  122. if((nID & 0xFFF0) == SC_MINIMIZE) {
  123. ShowWindow(SW_HIDE);
  124. return;
  125. }
  126. StandardWnd::OnSysCommand(nID, lParam);
  127. }