Hello vinTab,
here are the answers to your questions:
A1) Yes you can instantiate an InkPicture through a CComPtr and then attach it to a suitable container (e.g. ATL's CAxWindow). See sample code below.
A2) In this case you want an InkOverlay instead of an InkPicture. InkOverlay and InkPicture are pretty much identical except that InkPicture has its own window while InkOverlay is attached to other windows/controls. See sample code below to learn how to attach InkOverlay to RichEdit.
A3) If you instantiate InkPicture/Overlay as CComPtr, you can access the automation API just as it is documented in the SDK doc. See code sample below to learn how to access the APIs.
#include "stdafx.h"
#include <atlbase.h>
#include <atlwin.h>
#include "msinkaut_i.c"
#include "msinkaut.h"
HINSTANCE hInst;
HWND hWndMain;
CComPtr <IInkPicture> g_spInkPicture;
CComPtr <IInkOverlay> g_spInkOverlay;
CAxWindow* pHostWindow;
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
MSG msg;
IUnknown* punk;
MyRegisterClass(hInstance);
if (!InitInstance (hInstance, nCmdShow))
return FALSE;
CoInitialize(NULL);
LoadLibrary(_T("riched20.dll"));
HWND hWndRE = CreateWindow(_T("RICHEDIT20W"), NULL, WS_CHILD|WS_VISIBLE|WS_BORDER, 100, 100, 150, 50, hWndMain, NULL, NULL, NULL);
g_spInkOverlay.CoCreateInstance(CLSID_InkOverlay);
g_spInkOverlay->put_hWnd((long)hWndRE);
g_spInkOverlay->put_Enabled(VARIANT_TRUE);
pHostWindow = new CAxWindow;
HWND hWndHost = CreateWindow(_T("STATIC"), NULL, WS_CHILD|WS_VISIBLE|WS_BORDER, 300, 100, 150, 50, hWndMain, NULL, hInstance, NULL);
pHostWindow->Attach(hWndHost);
HRESULT hr = g_spInkPicture.CoCreateInstance(CLSID_InkPicture);
hr = g_spInkPicture.QueryInterface(&punk);
hr = pHostWindow->AttachControl(punk, NULL);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
CoUninitialize();
return (int) msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = _T("IPIO_CPP");
wcex.hIconSm = LoadIcon(hInstance, (LPCTSTR)IDI_APPLICATION);
return RegisterClassEx(&wcex);
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance;
hWndMain = CreateWindow(_T("IPIO_CPP"), _T("InkPicture/Overlay Sample"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWndMain)
return FALSE;
ShowWindow(hWndMain, nCmdShow);
UpdateWindow(hWndMain);
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
g_spInkOverlay.Release();
g_spInkPicture.Release();
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
Thanks




Bookmarks