How To CaptureScreen at Virtual Desktop? - winapi

I run test program windows8 or 7 64/32bit
but i can't capture screen when running virtual desktop
here is my code
hwnd h1 = createwindows(....) or dialog.. //if this line remove capture code works fine
hDesktopCurrent = NULL;
hOriginalInput = NULL;
hDesktopCurrent = GetThreadDesktop(GetCurrentThreadId());
hOriginalInput = OpenInputDesktop(0, FALSE, DESKTOP_SWITCHDESKTOP);
hDeskVirtual= NULL;
attr.nLength = sizeof(attr);
attr.lpSecurityDescriptor = NULL;
attr.bInheritHandle = true;
hDeskVirtual= CreateDesktopEx(
"my_new_desktop_1",
NULL,
NULL,
0,
GENERIC_ALL,
&attr,
0,
NULL);
SwitchDesktop(hDeskVirtual);
SetThreadDesktop(hDeskVirtual);
//capture here
SwitchDesktop(originaldesktop);
SetThreadDesktop(originaldesktop);
ps:
When I nerver create any windows hwnd before switchdesktop
(ex:createwindows,creatdialog...) it works perfertly capture..
but I create any windows frame or dialog,
it didn't work
that only captured BlackScreen
plz..help me!

Related

How to use ShellExecuteEx() without stealing the focus of the opener window

I am trying to open a browser through my application but I do not want it to run in the foreground and steal the focus from my application.
The code:
case WM_COMMAND:
{
SHELLEXECUTEINFO ShExecInfo;
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = NULL;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = L"open";
ShExecInfo.lpFile = L"http://www.microsoft.com";
ShExecInfo.lpParameters = NULL;
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_HIDE;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
SetForegroundWindow(hwnd);
}
return 0;
In my application, there is a button which is sending the command message to execute the opening code, but my application goes to the background and the browser comes to the foreground.
How to solve this problem?
I suggest you start the browser using CreateProcess() instead and in the STARTUPINFO structure you initialize, use STARTF_USESHOWWINDOW in the dwFlags and in wShowWindow, be sure to include the SW_SHOWNOACTIVATE flag. That should allow the process to start but not become the active window.

A code which is ported from xlib to xcb doesn't work

Here is an example code which sends a mouse click (using xlib). For simplicity events are sent to the fullscreen window (root and window coordinates are the same) and window id is obtained using wmctrl.
Display *display = XOpenDisplay(NULL);
XWarpPointer(display, None, RootWindow(display, DefaultScreen(display)), 0, 0, 0, 0, 300, 200);
XEvent event;
memset(&event, 0x00, sizeof(event));
event.type = ButtonPress;
event.xbutton.button = button;
event.xbutton.same_screen = True;
event.xbutton.root = RootWindow(display, DefaultScreen(display));
event.xbutton.window = 81788929;
event.xbutton.subwindow = 0;
event.xbutton.x_root = 300;
event.xbutton.y_root = 200;
event.xbutton.x = 300;
event.xbutton.y = 200;
event.xbutton.state = 0;
XSendEvent(display, PointerWindow, True, ButtonPressMask, &event);
XFlush(display);
XCloseDisplay(display);
Above code works fine. I ported it to xcb:
Display *display = XOpenDisplay(NULL);
XWarpPointer(display, None, RootWindow(display, DefaultScreen(display)), 0, 0, 0, 0, 300, 200);
xcb_button_press_event_t event;
memset(&event, 0x00, sizeof(event));
event.event = 81788929;
event.same_screen = 1;
event.root = RootWindow(display, DefaultScreen(display));
event.root_x = 300;
event.root_y = 200;
event.event_x = 300;
event.event_y = 200;
event.child = 0;
event.state = 0;
xcb_connection_t *conn = XGetXCBConnection(display);
xcb_send_event(conn, false, 81788929, XCB_EVENT_MASK_BUTTON_PRESS, (char*)(&event));
xcb_flush(conn);
XCloseDisplay(display);
XCB code doesn't work: destination window doesn't get any event. What is wrong ?
Edit1
When I use following code for a connection:
xcb_connection_t *conn;
xcb_screen_t *screen;
conn = xcb_connect (NULL, NULL);
screen = xcb_setup_roots_iterator (xcb_get_setup (conn)).data;
and later:
event.root = screen->root;
it also doesn't work.
Nowhere in your code there are error checks. Anyway, I suspect that XGetXCBConnection(display); does not return you a valid Xcb connection. Why you may ask? Because for this to work Xlib must have been built as a wrapper around Xcb and the internal structures properly been set up.
I suggest you create the connection and open the display purely with Xcb and see if this solves the problem.

how to host html control in my window using a buffer which contents a html file

I am developing a visual c++ applicatio(x64). what actually i am trying to do is that suppose we have a html file in window explorer(i mean file with file extension ".html"). when we single click on it we get its preview on preview pane(so we don't need to open this file we can see the file in preview pane on a single click to a file).
I have developed a similar type of application but in my case when i click on the "html file" i just get the code of that html file in preview pane(the code which you can see if you open that html file in notepad). which is not expected to happen but I want to have the preview of that "html file" not the code of that html file.
I think i need to host some browser control which will transform my html code in preview pane to the display of html file(If i am correct ???) How to do that ??
Here is my code for that-
IHTMLDocument2 * pDoc=NULL;
HRESULT hr2 = CoCreateInstance(CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER, IID_IHTMLDocument2, (LPVOID *) &pDoc);
if (pDoc)
{
IPersistStreamInit *pPersist = NULL;
pDoc->QueryInterface(IID_IPersistStreamInit,(LPVOID *) &pPersist);
if (pPersist)
{
IMarkupServices *pMS = NULL;
pPersist->InitNew();
pPersist->Release();
pDoc->QueryInterface(IID_IMarkupServices,(LPVOID *) &pMS);
if (pMS)
{
IMarkupContainer *pMC = NULL;
IMarkupPointer *pMkStart = NULL;
IMarkupPointer *pMkFinish = NULL;
pMS->CreateMarkupPointer(&pMkStart);
pMS->CreateMarkupPointer(&pMkFinish);
pMS->ParseString(HtmlFileContents,0,&pMC,pMkStart,pMkFinish);
//this HtmlFileContents is actually a buffer of olechar type which contains the code of html file (the code which you see when you open the html file in notepad)
if (pMC)
{
IHTMLDocument2 *pNewDoc = NULL;
pMC->QueryInterface(IID_IHTMLDocument,(LPVOID *) &pNewDoc);
if (pNewDoc)
{
IHTMLElement *pBody;
pNewDoc->get_body(&pBody);
if (pBody)
{
BSTR strText;
pBody->get_innerText(&strText);
hr = instance->CreatePreviewWindowForHtml(strText); // this function is responsible for displaying the html file in window. you can see its definition below after this code.
SysFreeString(strText);
pBody->Release();
}
pNewDoc->Release();
}
pMC->Release();
}
if (pMkStart)
pMkStart->Release();
if (pMkFinish)
pMkFinish->Release();
pMS->Release();
pMS->Release();
}
}
pDoc->Release();
}
return true;
and the function defintion of CreatePreviewWindowForHtml() is as below-
CreatePreviewWindowForHtml(PCWSTR pszRtfWide)
{
assert(m_hwndPreview3 == NULL);
HRESULT hr = E_FAIL;
if (m_hwndPreview3 == NULL)
{
HRESULT hr5 = HRESULT_FROM_WIN32(GetLastError());
}
if (m_hinstEditLibrary == NULL)
{
// MSFTEDIT_CLASS used below comes from this binary
m_hinstEditLibrary = LoadLibraryW(L"msftedit.dll");
}
if (m_hinstEditLibrary == NULL)
{
hr = HRESULT_FROM_WIN32(GetLastError());
}
else
{
// Create the preview window
HWND pr = m_hwndPreview3 = CreateWindowExW(0, MSFTEDIT_CLASS, NULL,
WS_CHILD | WS_VSCROLL | WS_VISIBLE | ES_MULTILINE | ES_READONLY, // Always create read-only
m_rcParent.left, m_rcParent.top, RECTWIDTH(m_rcParent), RECTHEIGHT(m_rcParent),
m_hwndPreview, NULL, NULL,NULL);
if (m_hwndPreview3 == NULL)
{
MessageBoxA(m_hwndPreview3,strerror(hr),"BTN WND2", MB_ICONINFORMATION);
}
else
{
int const cchRtf = 1 + wcslen(pszRtfWide);
PSTR pszRtf = (PSTR)CoTaskMemAlloc(cchRtf);
if (pszRtf)
{
WideCharToMultiByte(CP_ACP, 0, pszRtfWide, cchRtf, pszRtf, cchRtf, NULL, NULL);
SETTEXTEX st = { ST_DEFAULT, CP_ACP };
LRESULT hr4=SendMessage(m_hwndPreview3, EM_SETTEXTEX, (WPARAM) &st, (LPARAM) pszRtfWide);
if (SUCCEEDED(hr4))
{
hr = AdjustDialogPositionAndSize();
SendMessage(m_hwndPreview3, EM_SETTEXTEX, (WPARAM) &st, (LPARAM) pszRtfWide);
}
CoTaskMemFree(pszRtf);
hr = S_OK;
}
else
{
hr = E_OUTOFMEMORY;
}
}
}
return hr;
}
Any ideas why i have the html code in my window ?? What to do in the code in order to get the preview of html file in my window rather then html code ??
Please tell me if any doubts in understanding me ??
You have the html code in your window because you choose a richedit as the text renderer and your text did not start with "{\rtf".
If you want html display, you need an html renderer instead of a rich edit, something like MFC's CHtmlEditCtrl. If you don't want to use MFC you can write an ActiveX container to host the webbrowser control directly.

ExtTextOutW() with ETO_IGNORELANGUAGE failed to capture the record

I am working on a sample in this I am creating a EMF file with some text in it.
To add a text I am using the API ExtTextOutW() with ETO_IGNORELANGUAGE option.
Return value of this API is TRUE. But when I open the EMF file the text is not present.
Then I saw the records. There is no entey for the ExtTextOutW.
Bellw is the code.
HDC hDC = GetDC(hWnd);
RECT Rect = {0, 0, 21590, 27940};
//Create the EMF file DC
HDC hEMFDC = ::CreateEnhMetaFile(hDC, L"c:\\del\\1.emf", &Rect, L"Test");
if (NULL != hEMFDC)
{
RECT Rect = {0, 0, 300, 155};
HBRUSH hb = CreateSolidBrush(0X00FFFF00);
FillRect(hEMFDC, &Rect, hb);
DeleteObject(hb);
int dx[12] = {25,25,25,25,25,25, 25,25,25,25,25,25};
WCHAR wcsBuffer[] = L"Text Message";
ExtTextOutW(hEMFDC, 10, 10, ETO_IGNORELANGUAGE, NULL, wcsBuffer, wcslen(wcsBuffer), dx);
HENHMETAFILE hmf = CloseEnhMetaFile(hEMFDC);
DeleteEnhMetaFile(hmf);
hEMFDC = NULL;
}
ReleaseDC(hWnd, hDC);
Please let me know any thing I am doing wrong in the above code.
Did you read the documentation for ExtTextOut[W] (MSDN), especially the part for the flags like ETO_IGNORELANGUAGE:
Reserved for system use. If an application sets this flag, it loses
international scripting support and in some cases it may display no
text at all.
Just try it without this flag.

Determining the default message store under Windows Mobile

The following piece of test code runs under Windows Mobile.
It's objective is to seek out the default message store so I can get the proper account name for programmatically compiling an email.
IMAPISession *mapiSession;
HRESULT hr = S_OK;
MAPIInitialize (NULL);
IMAPITable *msgTable;
SRowSet *pRows;
IMsgStore *msgStore;
if (MAPILogonEx(0,NULL,NULL,0,&mapiSession) != S_OK)
{
// MessageBox(g_hWnd,_T("Failed to logon"),_T("Error"),0);
}
else
{
SizedSPropTagArray(3, PropTagArr) = {3,{PR_DISPLAY_NAME,
PR_ENTRYID,
PR_DEFAULT_STORE}};
hr = mapiSession->GetMsgStoresTable(MAPI_UNICODE,&msgTable);
hr = msgTable->SetColumns((LPSPropTagArray)&PropTagArr, 0);
if (!hr)
{
do
{
hr = msgTable->QueryRows(1,0,&pRows);
LPSPropValue lpProp;
lpProp = &pRows->aRow[0].lpProps[0];
// if(_tcscmp( lpProp->Value.LPSZ, _T("SMS") ) == 0 )
// break;
lpProp = &pRows->aRow[0].lpProps[0];
if (lpProp->ulPropTag == PR_DEFAULT_STORE)
break;
lpProp = &pRows->aRow[0].lpProps[1];
if (lpProp->ulPropTag == PR_DEFAULT_STORE)
break;
lpProp = &pRows->aRow[0].lpProps[2];
if (lpProp->ulPropTag == PR_DEFAULT_STORE)
break;
FreeProws(pRows);
pRows = NULL;
}while (!hr);
hr = mapiSession->OpenMsgStore (0,
pRows->aRow[0].lpProps[1].Value.bin.cb,
(ENTRYID*)pRows->aRow[0].lpProps[1].Value.bin.lpb,
NULL,
MDB_NO_DIALOG | MAPI_BEST_ACCESS,
&msgStore);
... BUT, fails to get the PR_DEFAULT_STORE property on a Windows Mobile device. I'm guessing Microsoft didn't implement it accurately. And so, lpProp->ulPropTag will never == PR_DEFAULT_STORE. It's always 0000.
Has anyone had success getting PR_DEFAULT_STORE using MAPI under Windows Mobile?
Is there another way of the determining the default message store?

Resources