Skip to content

Commit

Permalink
Samples that show Win32 apps using the share contract. Project types …
Browse files Browse the repository at this point in the history
…include a straight up Win32 app (in C++), a WinForms .NET app and a WPF app.
  • Loading branch information
arunjeetsingh committed Apr 14, 2015
1 parent 4ba0a58 commit bda5e0c
Show file tree
Hide file tree
Showing 39 changed files with 2,076 additions and 0 deletions.
61 changes: 61 additions & 0 deletions Win32ShareSourceSamples/Win32ShareSourceSamples.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.22609.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfShareSource", "WpfShareSource\WpfShareSource.csproj", "{EA312D52-E025-4F8D-8469-B6D7D8574468}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinForms_Share", "WinForms_Share\share\WinForms_Share.csproj", "{3BA5E5D5-A15F-433B-B06D-8112F93F8112}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Win32_Share_Desktop", "Win32_Share_Desktop\Win32_Share_Desktop\Win32_Share_Desktop.vcxproj", "{74CA8B6F-043E-4DE1-98C3-EAD1212B8312}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EA312D52-E025-4F8D-8469-B6D7D8574468}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EA312D52-E025-4F8D-8469-B6D7D8574468}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EA312D52-E025-4F8D-8469-B6D7D8574468}.Debug|x86.ActiveCfg = Debug|Any CPU
{EA312D52-E025-4F8D-8469-B6D7D8574468}.Debug|x86.Build.0 = Debug|Any CPU
{EA312D52-E025-4F8D-8469-B6D7D8574468}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EA312D52-E025-4F8D-8469-B6D7D8574468}.Release|Any CPU.Build.0 = Release|Any CPU
{EA312D52-E025-4F8D-8469-B6D7D8574468}.Release|x86.ActiveCfg = Release|Any CPU
{EA312D52-E025-4F8D-8469-B6D7D8574468}.Release|x86.Build.0 = Release|Any CPU
{3BA5E5D5-A15F-433B-B06D-8112F93F8112}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3BA5E5D5-A15F-433B-B06D-8112F93F8112}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3BA5E5D5-A15F-433B-B06D-8112F93F8112}.Debug|x86.ActiveCfg = Debug|Any CPU
{3BA5E5D5-A15F-433B-B06D-8112F93F8112}.Debug|x86.Build.0 = Debug|Any CPU
{3BA5E5D5-A15F-433B-B06D-8112F93F8112}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3BA5E5D5-A15F-433B-B06D-8112F93F8112}.Release|Any CPU.Build.0 = Release|Any CPU
{3BA5E5D5-A15F-433B-B06D-8112F93F8112}.Release|x86.ActiveCfg = Release|Any CPU
{3BA5E5D5-A15F-433B-B06D-8112F93F8112}.Release|x86.Build.0 = Release|Any CPU
{74CA8B6F-043E-4DE1-98C3-EAD1212B8312}.Debug|Any CPU.ActiveCfg = Debug|Win32
{74CA8B6F-043E-4DE1-98C3-EAD1212B8312}.Debug|x86.ActiveCfg = Debug|Win32
{74CA8B6F-043E-4DE1-98C3-EAD1212B8312}.Debug|x86.Build.0 = Debug|Win32
{74CA8B6F-043E-4DE1-98C3-EAD1212B8312}.Release|Any CPU.ActiveCfg = Release|Win32
{74CA8B6F-043E-4DE1-98C3-EAD1212B8312}.Release|x86.ActiveCfg = Release|Win32
{74CA8B6F-043E-4DE1-98C3-EAD1212B8312}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(TeamFoundationVersionControl) = preSolution
SccNumberOfProjects = 4
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
SccTeamFoundationServer = https://arunjeetsingh.visualstudio.com/defaultcollection
SccLocalPath0 = .
SccProjectUniqueName1 = WpfShareSource\\WpfShareSource.csproj
SccProjectName1 = WpfShareSource
SccLocalPath1 = WpfShareSource
SccProjectUniqueName2 = WinForms_Share\\share\\WinForms_Share.csproj
SccProjectName2 = WinForms_Share/share
SccLocalPath2 = WinForms_Share\\share
SccProjectUniqueName3 = Win32_Share_Desktop\\Win32_Share_Desktop\\Win32_Share_Desktop.vcxproj
SccProjectName3 = Win32_Share_Desktop/Win32_Share_Desktop
SccLocalPath3 = Win32_Share_Desktop\\Win32_Share_Desktop
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30414.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Win32_Share_Desktop", "Win32_Share_Desktop\Win32_Share_Desktop.vcxproj", "{74CA8B6F-043E-4DE1-98C3-EAD1212B8312}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{74CA8B6F-043E-4DE1-98C3-EAD1212B8312}.Debug|Win32.ActiveCfg = Debug|Win32
{74CA8B6F-043E-4DE1-98C3-EAD1212B8312}.Debug|Win32.Build.0 = Debug|Win32
{74CA8B6F-043E-4DE1-98C3-EAD1212B8312}.Release|Win32.ActiveCfg = Release|Win32
{74CA8B6F-043E-4DE1-98C3-EAD1212B8312}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
========================================================================
WIN32 APPLICATION : Win32_Share_Desktop Project Overview
========================================================================

AppWizard has created this Win32_Share_Desktop application for you.

This file contains a summary of what you will find in each of the files that
make up your Win32_Share_Desktop application.


Win32_Share_Desktop.vcxproj
This is the main project file for VC++ projects generated using an Application Wizard.
It contains information about the version of Visual C++ that generated the file, and
information about the platforms, configurations, and project features selected with the
Application Wizard.

Win32_Share_Desktop.vcxproj.filters
This is the filters file for VC++ projects generated using an Application Wizard.
It contains information about the association between the files in your project
and the filters. This association is used in the IDE to show grouping of files with
similar extensions under a specific node (for e.g. ".cpp" files are associated with the
"Source Files" filter).

Win32_Share_Desktop.cpp
This is the main application source file.

/////////////////////////////////////////////////////////////////////////////
AppWizard has created the following resources:

Win32_Share_Desktop.rc
This is a listing of all of the Microsoft Windows resources that the
program uses. It includes the icons, bitmaps, and cursors that are stored
in the RES subdirectory. This file can be directly edited in Microsoft
Visual C++.

Resource.h
This is the standard header file, which defines new resource IDs.
Microsoft Visual C++ reads and updates this file.

Win32_Share_Desktop.ico
This is an icon file, which is used as the application's icon (32x32).
This icon is included by the main resource file Win32_Share_Desktop.rc.

small.ico
This is an icon file, which contains a smaller version (16x16)
of the application's icon. This icon is included by the main resource
file Win32_Share_Desktop.rc.

/////////////////////////////////////////////////////////////////////////////
Other standard files:

StdAfx.h, StdAfx.cpp
These files are used to build a precompiled header (PCH) file
named Win32_Share_Desktop.pch and a precompiled types file named StdAfx.obj.

/////////////////////////////////////////////////////////////////////////////
Other notes:

AppWizard uses "TODO:" comments to indicate parts of the source code you
should add to or customize.

/////////////////////////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
// Win32_Share_Desktop.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "Win32_Share_Desktop.h"
#include <wrl/client.h>
#include <wrl/wrappers/corewrappers.h>
#include <windows.applicationmodel.datatransfer.h>
#include <ShObjIdl.h>
#include <wrl\event.h>

using namespace std;
using namespace Platform;
using namespace ABI::Windows::ApplicationModel::DataTransfer;
using namespace ABI::Windows::Foundation;
using namespace Microsoft::WRL;

#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

// 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);

Microsoft::WRL::ComPtr<IDataTransferManagerInterop> pDTM;
Microsoft::WRL::ComPtr<IDataTransferManagerStatics> dtmStatics;

int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPTSTR lpCmdLine,
_In_ 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_WIN32_SHARE_DESKTOP, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

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

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

// 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.
//
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_WIN32_SHARE_DESKTOP));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_WIN32_SHARE_DESKTOP);
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 = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}

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

::RoInitialize(RO_INIT_SINGLETHREADED);

HRESULT hr = GetActivationFactory(Wrappers::HStringReference(RuntimeClass_Windows_ApplicationModel_DataTransfer_DataTransferManager).Get(), &dtmStatics);
hr = dtmStatics.As(&pDTM);

Microsoft::WRL::ComPtr<IDataTransferManager> spSharingManager;
hr = pDTM->GetForWindow(hWnd, IID_PPV_ARGS(&spSharingManager));

auto callback = Callback < ITypedEventHandler<DataTransferManager*, DataRequestedEventArgs* >> (
[&](IDataTransferManager*, IDataRequestedEventArgs* pArgs) -> HRESULT
{
ComPtr<IDataRequest> spDataRequest;
pArgs->get_Request(&spDataRequest);

// Create Sharing data
ComPtr<IDataPackage> spDataPackage;
spDataRequest->get_Data(&spDataPackage);

ComPtr<IDataPackagePropertySet> spDataPacakgeProperties;
spDataPackage->get_Properties(&spDataPacakgeProperties);

spDataPacakgeProperties->put_Title(Wrappers::HStringReference(L"Sample win32 app").Get());
spDataPacakgeProperties->put_Description(Wrappers::HStringReference(L"Hello...world !!!").Get());

spDataPackage->SetText(Wrappers::HStringReference(L"Say hello!").Get());

return S_OK;
});

EventRegistrationToken _ertSharingContentRequested;

hr = spSharingManager->add_DataRequested(callback.Get(), &_ertSharingContentRequested);

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
//
//
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);
// Parse the menu selections:
switch (wmId)
{
case IDM_SHARETEXT:
{
HRESULT hr = S_OK;
hr = pDTM->ShowShareUIForWindow(hWnd);
//DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
}
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
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;
}

/*
void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
DataPackage ^dataPackage = e.Request->Data;
dataPackage->Properties->Title = "Share Text Example";
dataPackage->Properties->Description = "An example of how to share text.";
dataPackage->SetText("Hello world");
}*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#include "resource.h"
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit bda5e0c

Please sign in to comment.