wincamera.cpp

本文详细解析了 Windows Camera 应用程序的入口点 wincamera.cpp,包括全局变量定义、函数前向声明及主消息循环的实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

// wincamera.cpp : 定义应用程序的入口点。
//


#include "stdafx.h"
#include "wincamera.h"


#define MAX_LOADSTRING 100


// 全局变量:
HINSTANCE hInst; // 当前实例
TCHAR szTitle[MAX_LOADSTRING]; // 标题栏文本
TCHAR szWindowClass[MAX_LOADSTRING]; // 主窗口类名


// 此代码模块中包含的函数的前向声明:
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: 在此放置代码。
MSG msg;
HACCEL hAccelTable;


// 初始化全局字符串
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_WINCAMERA, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);


// 执行应用程序初始化:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}


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


// 主消息循环:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}


return (int) msg.wParam;
}






//
//  函数: MyRegisterClass()
//
//  目的: 注册窗口类。
//
//  注释:
//
//    仅当希望
//    此代码与添加到 Windows 95 中的“RegisterClassEx”
//    函数之前的 Win32 系统兼容时,才需要此函数及其用法。调用此函数十分重要,
//    这样应用程序就可以获得关联的
//    “格式正确的”小图标。
//
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_WINCAMERA));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_WINCAMERA);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));


return RegisterClassEx(&wcex);
}


//
//   函数: InitInstance(HINSTANCE, int)
//
//   目的: 保存实例句柄并创建主窗口
//
//   注释:
//
//        在此函数中,我们在全局变量中保存实例句柄并
//        创建和显示主程序窗口。
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;


hInst = hInstance; // 将实例句柄存储在全局变量中


hWnd = CreateWindow(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;
}


//
//  函数: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  目的: 处理主窗口的消息。
//
//  WM_COMMAND - 处理应用程序菜单
//  WM_PAINT - 绘制主窗口
//  WM_DESTROY - 发送退出消息并返回
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;


switch (message)
{
case WM_COMMAND:
wmId    = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// 分析菜单选择:
switch (wmId)
{
case IDM_EXIT:
DestroyWindow(hWnd);
break;
case IDM_PREVIEW:
if (pControl==NULL)
{
Preview(hWnd);
}
break;
case IDM_STOP:
if (pControl!=NULL)
{
pControl->Stop();
isPlayed=false;
}
break;
case IDM_PLAY:
if (pControl!=NULL)
{
pControl->Run();
isPlayed=true;
}
break;
case ID_ACCPREVIEW:
if (pControl==NULL)
{
Preview(hWnd);
}
break;
case ID_ACCPLAYORSTOP:
if (pControl!=NULL)
{
if (isPlayed)
{
pControl->Stop();
isPlayed=false;
}
else
{
pControl->Run();
isPlayed=true;
}
}
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}


//// “关于”框的消息处理程序。
//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;
//}
// }


void Preview(HWND hWnd)
{
hr= pro.InitCaptureGraphBuilder(&IGB,&ICGB);


hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
IID_ICreateDevEnum, (void **)&pSysDevEnum);
hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0);


if (hr == S_OK) 
{


ULONG cFetched;
while(pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK)
{
//IPropertyBag *pPropBag;
//hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, 
// (void **)&pPropBag);
//if (SUCCEEDED(hr))
// {
// VARIANT varName;
// VariantInit(&varName);
// hr = pPropBag->Read(L"FriendlyName", &varName, 0);
// if (SUCCEEDED(hr))
// {
/*MessageBox(varName.bstrVal);*/




hr=pMoniker->BindToObject(0,0,IID_IBaseFilter,(void**)&pBaseFilter);
if (E_INVALIDARG == hr)
{
MessageBox(NULL, TEXT("Error"), NULL, MB_OK);
}
hr= IGB->AddFilter(pBaseFilter,L"Capture Filter");
if (E_INVALIDARG == hr)
{
MessageBox(NULL, TEXT("Error"), NULL, MB_OK);
}
hr=ICGB->RenderStream(&PIN_CATEGORY_PREVIEW,&MEDIATYPE_Video,pBaseFilter,NULL,NULL);
if (E_INVALIDARG == hr)
{
MessageBox(NULL, TEXT("Error"), NULL, MB_OK);
return;
}


hr=IGB->QueryInterface(IID_IVideoWindow,(void**)&pWindow);
if (E_INVALIDARG == hr)
{
MessageBox(NULL, TEXT("Error"), NULL, MB_OK);
}
hr=IGB->QueryInterface(IID_IMediaControl,(void**)&pControl);
if (E_INVALIDARG == hr)
{
MessageBox(NULL, TEXT("Error"), NULL, MB_OK);
}
/*
pControl->Run();
Sleep(5000);
pControl->Stop();
pWindow->put_Owner((OAHWND)hWnd);
pWindow->put_WindowStyle(WS_CHILD);
pWindow->get_Width(&pWidth);
pWindow->get_Height(&pHeight);
pWindow->SetWindowPosition(0,0,pWidth,pHeight);
*/
/*}
VariantClear(&varName);
pPropBag->Release();
}*/
pMoniker->Release();
}
pEnumCat->Release();
}
pSysDevEnum->Release();
}
我在ardupilot/library中新添加了两个文件,编译到最后出现报错usr/bin/ld: lib/libArduPlane_libs.a(AP_CANManager.cpp.0.o): in function `AP_CANManager::init()': AP_CANManager.cpp:(.text._ZN13AP_CANManager4initEv+0x556): undefined reference to `AP_ToshibaCAN::AP_ToshibaCAN()' collect2: error: ld returned 1 exit status Waf: Leaving directory `/home/hjhj3/ardupilot/build/sitl' Build failed -> task in 'bin/arduplane' failed (exit status 1): {task 127115774264480: cxxprogram AP_Arming.cpp.53.o,AP_ExternalControl_Plane.cpp.53.o,Attitude.cpp.53.o,GCS_MAVLink_Plane.cpp.53.o,GCS_Plane.cpp.53.o,Log.cpp.53.o,Parameters.cpp.53.o,Plane.cpp.53.o,RC_Channel_Plane.cpp.53.o,VTOL_Assist.cpp.53.o,afs_plane.cpp.53.o,altitude.cpp.53.o,avoidance_adsb.cpp.53.o,commands.cpp.53.o,commands_logic.cpp.53.o,control_modes.cpp.53.o,ekf_check.cpp.53.o,events.cpp.53.o,failsafe.cpp.53.o,fence.cpp.53.o,is_flying.cpp.53.o,mode.cpp.53.o,mode_LoiterAltQLand.cpp.53.o,mode_acro.cpp.53.o,mode_auto.cpp.53.o,mode_autoland.cpp.53.o,mode_autotune.cpp.53.o,mode_avoidADSB.cpp.53.o,mode_circle.cpp.53.o,mode_cruise.cpp.53.o,mode_fbwa.cpp.53.o,mode_fbwb.cpp.53.o,mode_guided.cpp.53.o,mode_loiter.cpp.53.o,mode_manual.cpp.53.o,mode_qacro.cpp.53.o,mode_qautotune.cpp.53.o,mode_qhover.cpp.53.o,mode_qland.cpp.53.o,mode_qloiter.cpp.53.o,mode_qrtl.cpp.53.o,mode_qstabilize.cpp.53.o,mode_rtl.cpp.53.o,mode_stabilize.cpp.53.o,mode_takeoff.cpp.53.o,mode_thermal.cpp.53.o,mode_training.cpp.53.o,motor_test.cpp.53.o,navigation.cpp.53.o,parachute.cpp.53.o,pullup.cpp.53.o,qautotune.cpp.53.o,quadplane.cpp.53.o,radio.cpp.53.o,reverse_thrust.cpp.53.o,sensors.cpp.53.o,servos.cpp.53.o,soaring.cpp.53.o,system.cpp.53.o,tailsitter.cpp.53.o,takeoff.cpp.53.o,tiltrotor.cpp.53.o,tuning.cpp.53.o -> arduplane} (run with -v to display more information)
最新发布
03-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值