How can we make a program to substitute the "print screen" key for the same function(i-e to get the picture of the whole screen ) with some other kry, in C language.
void dump_buffer()
{
IDirect3DSurface9* pRenderTarget=NULL;
IDirect3DSurface9* pDestTarget=NULL;
const char file[] = "Pickture.bmp";
// sanity checks.
if (Device == NULL)
return;
// get the render target surface.
HRESULT hr = Device->GetRenderTarget(0, &pRenderTarget);
// get the current adapter display mode.
//hr = pDirect3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3ddisplaymode);
// create a destination surface.
hr = Device->CreateOffscreenPlainSurface(DisplayMde.Width,
DisplayMde.Height,
DisplayMde.Format,
D3DPOOL_SYSTEMMEM,
&pDestTarget,
NULL);
//copy the render target to the destination surface.
hr = Device->GetRenderTargetData(pRenderTarget, pDestTarget);
//save its contents to a bitmap file.
hr = D3DXSaveSurfaceToFile(file,
D3DXIFF_BMP,
pDestTarget,
NULL,
NULL);
// clean up.
pRenderTarget->Release();
pDestTarget->Release();
}
their you go
Related
Objective: I am using the library Uiautomation.h to retrieve the window handle (hwnd) and window name when the user clicks on one element of that window. I need a solution with plain C.
Example: If the User clicks on the button 8 of the windows calculator, I need to identify the window handle and name as follow:
I am retrieving no window when the user clicks into a element of the windows calculator:
hwnd = 0
Window name = none
I am retrieving always 0 as hwnd. However, when I click in the header of the window, I can retrieve the hwnd and the window name as "Calculator". This is part of my code in plain C:
UIA_HWND hwnd;
PWSTR win_name = NULL;
static int win_len;
POINT pt;
IUIAutomation *pAutomation = NULL;
IUIAutomationElement *element = NULL;
CoInitialize(NULL);
EXTERN_C const CLSID CLSID_CUIAutomation;
EXTERN_C const IID IID_IUIAutomation;
HRESULT hr = CoCreateInstance(&CLSID_CUIAutomation,NULL, CLSCTX_INPROC_SERVER,&IID_IUIAutomation,(void**)&pAutomation);
GetCursorPos(&pt);
hr = IUIAutomation_ElementFromPoint(pAutomation, pt, &element);
if(SUCCEEDED(hr) && element != NULL){
IUIAutomationElement_get_CurrentNativeWindowHandle(element,&hwnd);
win_len = GetWindowTextLengthW(hwnd);
if(win_len > 0) {
win_name = (PWSTR) malloc(sizeof(wchar_t) * win_len + 1);
GetWindowTextW(hwnd, win_name, win_len + 1);
}
}
I used also the function hwnd = GetForegroundWindow(); but I still get the same value 0. Could someone know what I am doing incorrectly?
I am creating my first tizen app, for a watch. I have started with the SettingUI sample code, and have added a 'name' item to the genlist, which I want to push a view where I enter my name. I will enter my name using an entry (on screen keyboard) component.
I see the keyboard in the emulator but the "A short text" text is partially cutoff at the top and left of the screen. It's as if the text flows in a SQUARE shape, but should flow in a CIRCLE shape. (But I do have a circle surface applied to the naviframe). If I switch the entry to single line (not multiline) then the text is actually hidden behind the keyboard). And the naviframe is inside the conformant.
Can anyone explain how I would make the entry (keyboard) text appear properly onscreen?
void _setting_name_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
{
appdata_s *ad = data;
Evas_Object *naviframe = ad->naviframe;
Elm_Object_Item *nf_it = NULL;
/* Unhighlight Item */
elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
// Create a keyboard (entry) and add to naviframe
Evas_Object *entry;
entry = elm_entry_add(naviframe);
elm_entry_entry_set(entry, "A short text.");
// Push the entry onto the naviframe to show it
nf_it = elm_naviframe_item_push(naviframe, _("Slider"), NULL, NULL, entry, "empty");
// Set the callback of the naviframe when layout popped off
elm_naviframe_item_pop_cb_set(nf_it, _setting_name_finished_cb, ad);
}
You can use size_hint property with ui containers.
void _setting_name_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
{
appdata_s *ad = data;
Evas_Object *naviframe = ad->naviframe;
Elm_Object_Item *nf_it = NULL;
/* Unhighlight Item */
elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
// Create a Box
Evas_Object *box;
box = elm_box_add(naviframe);
evas_object_show(box);
// Create a keyboard (entry) and add to box
Evas_Object *entry;
entry = elm_entry_add(box);
elm_entry_entry_set(entry, "A short text.");
evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, 0.5);
evas_object_size_hint_padding_set(entry, 50, 50, 30, 240);
elm_entry_single_line_set(entry, EINA_TRUE);
elm_entry_scrollable_set(entry, EINA_TRUE);
evas_object_show(entry);
elm_box_pack_end(box, entry);
// Push the entry onto the naviframe to show it
nf_it = elm_naviframe_item_push(naviframe, _("Slider"), NULL, NULL, box, "empty");
// Set the callback of the naviframe when layout popped off
elm_naviframe_item_pop_cb_set(nf_it, _setting_finished_cb, ad);
}
So I'm working on some SDL2 Wrapper stuff, and I'm trying to use SDL_BlitScaled to copy the data in a src surface into a destination surface which I've already created, like so
SDL_Surface *loaded = IMG_Load("test.png");
SDL_SetSurfaceBlendMode(loaded, SDL_BLENDMODE_NONE);
SDL_Surface *out = SDL_CreateRGBSurface(0, 100, 100, loaded->format->BitsPerPixel,
loaded->format->Rmask, loaded->format->Gmask, loaded->format->Bmask, loaded->format->Amask);
SDL_BlitScaled(loaded, NULL, out, NULL);
SDL_Texture *tex = SDL_CreateTextureFromSurface(ren, out);
SDL_Rect rec = {10, 10, 110, 110};
SDL_RenderCopy(ren, tex, NULL, &rec);
Don't worry about my renderer or window etc. I've isolated the problem to somewhere in this code. The image does not appear on the screen, however it does if I create a texture from the loaded surface. Thoughts? I imagine I'm misusing either CreateRGBSurface, or BlitScaled (I did see another question about this, however the solution was unclear).
For me I had to do:
SDL_SetSurfaceBlendMode(loaded , SDL_BLENDMODE_NONE);
SDL_SetSurfaceBlendMode(out, SDL_BLENDMODE_NONE);
For it to work, otherwise some strange blending happens.
The docs page for this function says:
To copy a surface to another surface (or texture) without blending with the existing data, the blendmode of the SOURCE surface should be
set to 'SDL_BLENDMODE_NONE'.
So setting loaded is probably enough.
Edit: In the end I came up with this:
struct FreeSurface_Functor
{
void operator() (SDL_Surface* pSurface) const
{
if (pSurface)
{
SDL_FreeSurface(pSurface);
}
}
};
typedef std::unique_ptr<SDL_Surface, FreeSurface_Functor> SDL_SurfacePtr;
class SDLHelpers
{
public:
SDLHelpers() = delete;
static SDL_SurfacePtr ScaledCopy(SDL_Surface* src, SDL_Rect* dstSize)
{
SDL_SurfacePtr scaledCopy(SDL_CreateRGBSurface(0,
dstSize->w, dstSize->h,
src->format->BitsPerPixel,
src->format->Rmask, src->format->Gmask, src->format->Bmask, src->format->Amask));
// Get the old mode
SDL_BlendMode oldBlendMode;
SDL_GetSurfaceBlendMode(src, &oldBlendMode);
// Set the new mode so copying the source won't change the source
SDL_SetSurfaceBlendMode(src, SDL_BLENDMODE_NONE);
// Do the copy
if (SDL_BlitScaled(src, NULL, scaledCopy.get(), dstSize) != 0)
{
scaledCopy.reset();
}
// Restore the original blending mode
SDL_SetSurfaceBlendMode(src, oldBlendMode);
return scaledCopy;
}
};
I was wondering if it is possible to use the Texture2D.FromStream() in XNA to load a texture from the middle of a stream. The idea is that I have an animation system that saves the texture for the limb directly into the file that contains the other information, like timing, name, etc... My problem comes when trying to load the file, when it gets to the loading of the Texture. I get an InvalidOperationExecption, and no real detail. Here is my code so far:
Writing:
...
//writes the name
binWriter.Write(name);
if (texture != null)
{
binWriter.Write(true);
//save the texture into the stream
texture.SaveAsPng(binWriter.BaseStream, texture.Width, texture.Height);
}
else
binWriter.Write(false);
//writes the ID of the parent limb
binWriter.Write(system.getParentID((Limb)parent));
...
Reading:
...
string name = binReader.ReadString();
Texture2D tex = null;
//gets the texture if it exists
bool texture = binReader.ReadBoolean();
if (texture)
tex = Texture2D.FromStream(graphics, binReader.BaseStream);
//finds the index of the parent limb
int parentID = binReader.ReadInt32();
...
Any Ideas?
-Edit- Solved! I used the getData() and setData() methods, and wrote and read the data as an array of uints.
I am new to silverlight , and I am experimenting with wia scanner integration. I know usng WIA.CommonDialog , showacquireimage() I can retrieve an image from the scanner. I am trying to access the device directly and execute the scan command to avoid user interaction.
I am able to connect to the device. But the only command available from the scanner is synchronize. I am trying to use the ExecuteCommand on the device object, but I am not sure what command to use. Any direction will be appreciated.
using (dynamic DeviceManager1 = AutomationFactory.CreateObject("WIA.DeviceManager"))
{
var deviceInfos = DeviceManager1.DeviceInfos;
for(int i= 1;i<=deviceInfos.Count;i++)
{
//check if the device is a scanner
if (deviceInfos.Item(i).Type.ToString() == "1")
{
var IDevice = deviceInfos.Item(i).Connect();
deviceN.Text = IDevice.Properties("Name").Value.ToString();
var dv = IDevice.Commands;
for (int j = 0; j <= dv.Count; j++)
{
deviceN.Text += " " + dv.Item(i).CommandID.ToString() + " " + dv.Item(i).Description.ToString();
}
}
}
}
You don't really need to deal with the device commands to scan the document. Instead you need to use the first device item under the device object. Here is a little example which works in itself, without failure checks for easier readability.
//using WIA;
bool showProgressBar = false;
DeviceManager deviceManager = new DeviceManagerClass();
foreach(DeviceInfo info in deviceManager.DeviceInfos)
{
if(info.Type == WiaDeviceType.ScannerDeviceType)
{
Device device = info.Connect();
ImageFile imageFile = null;
Item deviceItem = null;
//Read through the list of items under the device...
foreach(Item item in device.Items)
{
//Pick the very first one!
deviceItem = item;
break;
}
if(showProgressBar == true)
{
//Scan without GUI, but display the progress bar dialog.
CommonDialogClass commonDialog = new CommonDialogClass();
imageFile = (ImageFile)commonDialog.ShowTransfer(deviceItem, FormatID.wiaFormatBMP, false);
}
else
{
//Scan without GUI, no progress bar displayed...
imageFile = (ImageFile)deviceItem.Transfer(FormatID.wiaFormatBMP);
}
imageFile.SaveFile("C:\\image.bmp");
}
}
Before scanning (but after you connected to the device item), you probably need to set various device properties to select the scanning resolution, color depth and other things if the defaults are not good enough for your needs.
Not long ago I made an easy to use class to operate WIA-compatible scanners, you can download it from this page... It's for .Net Framework 2.0, C#. Maybe it could come handy in your project, you would be done with a few lines of code including setting the basic properties. :)