How to keep the focus on the top window of 1st screen after clicking 2nd screen - c++

we have one desktop(1st screen) to display the image and another touchscreen(2nd screen) for the control, we wrote a virtual keyboard(html&javascript) on touchscreen, ideally when we touch the keys on the touchscreen, we could input text in editbox(in an input dialog window) in the 1st desktop. Now the problem is the mouse is lost(originally it is in a input dialog in 1st desktop) when we touch the touchscreen, so we have to create a global window in C++ program, and manually copy each possible input dialog window to this global window when it is in use, also we need to set focus for each possible editbox in this input dialog window. please see this:
for each possible input dialog, we add
extern HWND activeInputWindow;
activeInputWindow=m_Edit_Name.m_hWnd;
also for each possible input box in this window we have to add
activeInputWindow=GetDlgItem(IDC_EDIT_TEST)->m_hWnd;
then the program always do this to get back the original window after clicking the touchscreen(2nd window)
extern HWND activeInputWindow;
if(IsWindow(activeInputWindow))
::SetFocus(activeInputWindow);
suppose we have 10 input window and 10 input boxes in each window,then I need to code 100 places! There must have some simple ways, windows osk.exe (virtual keyboard) have no problem for this but we have to use our own virtual keyboard.... I tried GetTopWindow() and GetForegroundWindow() but not working.. Many thanks for the help

This is trying to solve the problem using the wrong tools. What you really want is a window that receives input, but rejects activation. To achieve this, handle the WM_MOUSEACTIVATE message by returning MA_NOACTIVATE. This also works for touch input.
See How can I have a window that rejects activation but still receives pointer input? for all the ins and outs.

The problem is that your virtual keyboard is stealing the focus of the edit control. You'll need to prevent this.
Try to set the flag WS_EX_NOACTIVATE for a window's style or other approaches from this or this answers.

Related

How to find slide show window of Microsoft Power Point

I have a simple c++ wIn32 program that allows you to paint over windows in Windows OS.
This program has a UI that lets a user to choose windows he wants to paint over.
The problem I'm facing is that if a user chooses a specific Microsoft PowerPoint window and than starts a slide show (by pressing 'F5' for example) than another new window is opened on full sceen and my program is unaware of it and does not paint over it.
I need to find out how may I identify this new window, assuming I can perform periodic polling on existing windows using EnumWindows method.
I have tryied using the methods GetAncestor & GetParent on the Slide Show window and on the PowerPoint window to see if they match but both of them return different HWND handle.
Moreover, a solution of identifying that a specific HWND handle is a PowerPoint Slide show window is not sufficient since if I have for example 2 instances of 2 different Power Point windows and the user has chosen to paint only over one of them, than I want to make sure that only if the chosen PowerPoint window is going to slide show window than I will paint over it. If the slide show window was started from the non-chosen PowerPoint window than I don't want to paint over it.

What Function can I use to get the handle of a button?

the situation is as follows:
I have the handle for a window (which i got with the function FindWindowEx() ) and that window has 3 buttons. I would like to know how I can get the handle for 1 of the 3 buttons. I mean I know ppl can use spy++, but I am sure there have to be functions that can do it for me, so my questions are:
Question::
What function or functions can I use to get the handle of a button of a window (already knowing the handle for the window)?
Question2::
How do I get the Button's ID???
You can loop through children of that window with EnumChildWindow.
It lets you define a callback function to be called for every child of the window.
In the callback, you can check if the current child is the button you need.
For example, if you dinamically want to press an OK button, you can check if the window text equals OK. You can get the window text with GetWindowText.
If you know the position in the parent window you can use ChildWindowFromPoint.
For this to work you will probably have to check the windows status first (maximazed or current width-height) to be sure the button is right where you want.
An easy way may also be getting his position relative to another child of the window that's easier to retrieve. For example, if the button is always to the right of a text-box control, you can get coordinates of the text-box and use ChildWindowFromPoint passing those coordinates with something added in the x direction.

When is WM_PAINT called?

When exactly is WM_PAINT called? Im trying to create a dialog based slot machine application, but i've run into a couple of logical issues. My application will consist of:
"Spin" Button
Exit Button
Three BMP images to display the results of the spin(coin/heart/soldier)
How will i show the final result of the spin using the BMP images? Am i correct in using WM_PAINT to attempt to display the images, how will i refresh the screen each time the user presses the spin button to show the new images? I really appreciate the help!
Dialog boxes normally use DefDlgProc as the window procedure. You can't handle WM_PAINT in your DialogProc (it isn't a window procedure). You can use your own window procedure with a dialog but that's probably more trouble than it's worth.
The simplest way to display a bitmap on a dialog is to use a static control with the SS_BITMAP style.
You can change the displayed bitmap by sending the STM_SETIMAGE message to the static control. The control will take care of repainting itself with the new bitmap.
This is OK if you just want to display the result of a spin, but won't work very well if you want to animate the spinning of the reels. To handle this you could create your own static control (i.e. a window for each reel) that would display a portion of a reel bitmap.

effective Overlapping of dialog windows in Visual C++ 6

Hello there I have issue with overlapping of child windows,I have created a software with menu driven interface( IDR_MAINFRAME - CFormView
etc) and upon clicking one of the menu items another child-window appears( Dialog based ) where I do the calculations as a normal
calculator.Now if I open any other entry say conversion of metrics which is also in menu entry then on overlapping with any other such
window the background windows gets horribly disfigured and if i move about the calculator or the metrics conversion calculator randomly
they get disfigured and its a mess.Also I have put up a bitmap image on the background.Upon moving the calculator the background image also
gets erased.
Please let me know about how to handle this issue.I have googled and found that handling of paint messages or WM_ERASEBKGND helps ..but I
have tried this piece of code which just doesn't help in OnEraseBkGnd();
BOOL COfficesoftDlg::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CRect Rect;
GetClientRect(Rect);
//ClientToScreen(&Rect);
//this->ScreenToClient(&Rect);
this->InvalidateRect(Rect);
return CDialog::OnEraseBkgnd(pDC);
}
how can i achieve the smooth overlapping of different windows like a notepad overlapping a word document or even a calculator or even a VC6
IDE in my project.
Please explain it with an example .I am just a newbie and I need to understand in detail...thanks and regards
Override OnEraseBkgnd and return true so it stops erasing the background you're painting. Returning TRUE says that you've done the work. If you simply call the base class implementation, it's going to do this for you, and you'll lose the background until it gets a chance to paint.
You're not getting paint messages to the parent window for some reason. Make sure you're calling the modal in the correct manner. DoModal() works fine. Make sure you're not just creating the modal and showing it.
If your windows are children on the same dialog/window and they overlap or you have children on either dialog/window, make sure that you use clipchildren and clipsiblings (if children on a window overlap). Otherwise they'll get to paint in any order they choose artifacting all over the place.
Ensure that you're painting to memory and bitblting back to your dialog, otherwise you'll get a flashing effect.

Bona fide transiant windows with WinAPI?

I want to create a Window like when a context menu pops up or clicking the menubar. I want a Window that will be like this and that I can take over its paint event. Sort of like what is created when you select a sub tool in Photoshop.
EDIT:I want to know how to create controls like the one that comes when you select a sub tool in Photoshop, these do not seem to have a parent window. Those little description popups are a good example of this type of window, and menu items, those rectangles have no parent window.
Thanks
EDIT2: see this: http://cdn-viper.demandvideo.com/media/CB3C805F-421E-45AE-8359-39D59D8F0165/jpeg/20412728-192C-462A-AF8E-1F30BA77AE05_2.jpg
You will notice the window for the sub tools, it is not constrained to a parent window.
But how do they get a nice shadow
around it, and how does it still stay
with the main window without a parent?
That's your real question.
There are several ways of getting the shadow. One is that the window is actually two windows, the "shadow" plus the "main" window.
When you create the flyout window (that's what it's called), you position it near the toolbar. If the toolbar gets a WM_MOVE message, it's your responsibility to call MoveWindow() on the flyout to keep it lined up.
Edited to add
The dwExStyle parameter of CreateWindowEx() should include WS_EX_LAYERED and probably WS_EX_TRANSPARENT, because the 'shadow' will use alpha blending. The hWndParent parameter is the application's main window. The x and y parameters must be calculated as an offset of whatever button the window is to be associated with.