How can I get data from dialog of window? - xlib

I am a newbie in Xlib world. In my project,I want to share my window to another via Remote desktop protocol, but they only saw content of window and didn't see anything if click on menu item of window. I used XGetImage to get data of specifies window. But If that window contain dialog ( see image here) I couldn't get data of dialog .
I use freeRDP source code, I modify in X11_shadow.c
function:
int x11_shadow_screen_grab(x11ShadowSubsystem* subsystem){
...
image = XGetImage(subsystem->display, 58720435, 0, 0, surface->width,
surface->height, AllPlanes,ZPixmap); //with 58720435 is window id of chrome
... }
In my opinion, the most important here is how can I get data of dialog in Window. I have a solution :
1. get window id of that dialog ( I am not sure the dialog has owner Window ID)
2. Use XGetImage get data of that dialog.
But It's not working.
I works on Linux environment.
Are there any solutions for my problems?
Thank you very much

Related

MFC: how to show a welcome dialog first?

When launch the program, I want to show a welcome dialog first before showing the main window. My current approach is like below.
BOOL CMyApp::InitInstance()
{
...
// The one and only window has been initialized, so show and update it
m_pMainWnd->ShowWindow(SW_HIDE);
//m_pMainWnd->UpdateWindow();
// call DragAcceptFiles only if there's a suffix
// In an SDI app, this should occur after ProcessShellCommand
CWelcomeDialog welcome_dialog;
welcome_dialog.DoModal();
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
Towards the end of InitInstance(), originally it uses (SW_SHOW). At first, I try commenting it out but it still shows. So I change to (SW_HIDE). It works but has unpleasant visual artifacts. Is there way to stop showing the main window as early as possible?
Another issue is that when I hide main window and show the dialog, the dialog is not in the center position of the main window.
In general, how to implement a welcome dialog and to show it well-centered before anything else?

How do I open browser + click with TestComplete?

I'm trying to just open http://espn.go.com/ and then click on the "NBA" tab using TestComplete.
Could someone tell me how to do this to get me started?
Thanks!
In the example below, you need a unique property name and value of the tab you want to click to be able to find it on the page. You can find this by clicking the tab using the Object Spy tool in test complete.
function nbaTest(){
var nbaTab;
//open browser at espn page
Browsers.Item("iexplore").Run("http://espn.go.com");
//search page for nba tab using a unique property name and corresponding property value of the nba tab
nbaTab = Sys.browser('iexplore').page("*").Find(propertyName,propertyValue,"1000","TRUE");
if (nbaTab.exists){
nbaTab.click();
}
else{
Log.Warning("NBA tab not found");
return;
}
}
I've tried using TestComplete' Recording feature - the script looks reliable. This is what was recorded:
var page;
Browsers.Item(btIExplorer).Navigate("http://espn.go.com/");
page = Aliases.browser.Page("http://espn.go.com/");
page.Panel(1).Panel("content").Panel("nav_wrapper").Panel("nav_wrapper_container").Panel("nav_main").Link("lpos_sitenavdefault_lid_sitenav_nba").Click();
Keyword test to open http://espn.go.com/ and then click on the "NBA" tab:
Steps:
Run TestComplete (I'm using version 10)
Launch the recording (By clicking "Record New Test" or "Append to Test")
Open IE and type the URL http://espn.go.com/ on address bar -> Click NBA tab -> Close the browser
Stop recording and see the KeywordTest you recorded in TestComplete IDE
My KeywordTest I recorded was as below:
Run Browser Parametrized (Internet Explorer, "", pX64) "http://espn.go.com/", ... Launches the specified browser and opens the specified URL in it.
pageEspnTheWorldwideLeaderInSpor Wait Waits until the browser loads the page and is ready to accept user input.
linkTennisM HoverMouse 0, 0 Moves the mouse pointer over the 'linkTennisM' control.
pageEspnTheWorldwideLeaderInSpor Wait Waits until the browser loads the page and is ready to accept user input.
panelModContainerModTabsModNoFoo ClickTab "NBA" Selects the 'NBA' tab of the 'panelModContainerModTabsModNoFoo' tab control.
linkNba HoverMouse 8, 6 Moves the mouse pointer over the 'linkNba' control.
panelHeader HoverMouse 658, 25 Moves the mouse pointer over the 'panelHeader' control.
ToolbarWindow32 ClickItemXY "&File", 16, 8, false Clicks at point (16, 8) of the '&File' item of the 'ToolbarWindow32' toolbar.
PopupMenu Click "Exit" Moves the mouse cursor to the menu item specified and then simulates a single click.
Not sure if this will help but you might be able to automate the step of opening your browser as well.
I use:
Call Sys.OleObject("WScript.Shell").Exec("cmd /c start /MAX iexplore ""http://espn.go.com""")
From there, you can automate the rest as usual (might need to wait for the page to load here as well).

XLIB Decoration questions

I'm writing a small window manager, that add a basic decoration around a window, but actually i have several question about adding/remove decoration of a window.
First Question
Actually the decoration is added during MapNotify event, but it seems to be not a good idea, because it add decoration also to a menu opened by an application everytime the mapnotify is fired with a new window, but i want only to add decoration to main window. Maybe i have to check if the current window is a child of another window ? Actually my code just create the decoration window with a specific name, so at every MapNotify request i give the decoration window a dummy name (Parent) to distinguish it from all other windows in that way if the MapNotify event is launched on a decoration window, at least it doesn't add another decoration.
But i don't understand if MapNotify is launched not only for parent window but also for childrend probably the risk is that i add more than one decoration window.
The actual code is the following:
void map_notify_handler(XEvent local_event, Display* display, ScreenInfos infos){
printf("Map Notify\n");
XWindowAttributes win_attr;
char *child_name;
XGetWindowAttributes(display, local_event.xmap.window, &win_attr);
XFetchName(display, local_event.xmap.window, &child_name);
printf("Attributes: W: %d - H: %d - Name: %s\n", win_attr.width, win_attr.height, child_name);
if(child_name!=NULL){
if(strcmp(child_name, "Parent")){
Window new_win = draw_window_with_name(display, RootWindow(display, infos.screen_num), "Parent", infos.screen_num,
win_attr.x, win_attr.y, win_attr.width, win_attr.height+DECORATION_HEIGHT, 0,
BlackPixel(display, infos.screen_num));
XMapWindow(display, new_win);
XReparentWindow(display,local_event.xmap.window, new_win,0, DECORATION_HEIGHT);
XSelectInput(display, local_event.xmap.window, SubstructureNotifyMask);
put_text(display, new_win, child_name, "9x15", 10, 10, BlackPixel(display,infos.screen_num), WhitePixel(display, infos.screen_num));
}
}
XFree(child_name);
}
So how to avoid adding of decoration on every window except the main application window (or the popup windows, there is a way to distinguish the type of window? How can i figure it out?)
Second Question
WHen i exit a program the window that is destroyed is just the application window not the parent decoration, how to destroy the current window and also the decoration?
I tried with the following:
void destroy_notify_handler(XEvent local_event, Display *display){
Window window = local_event.xdestroywindow.event;
XDestroyWindow(display, window);
}
But i receive the following error:
Error occurred: BadWindow (invalid Window parameter)
I use event instead of window because it seems that it contains the parent window (i read it from there: http://tronche.com/gui/x/xlib/events/window-state-change/destroy.html)
But even if i use window i have the same problem.
Or maybe i have to destroy the parent window earlier? Maybe during UnMapNotify? But how to understand if the event is launched just because the window is going to be closed or for some other reasons?
Thanks for the help :)
Read EWMH spec and you'll find answers to all questions.
Check "override redirect" window flag
You are trying
to destroy window which is already destroyed. Instead of using
event.xdestroywindow.event window id just delete your decoration
window.
Don't forget to add client window to save set if you are
writing reparenting WM. That way if you kill wm application windows
are not destroyed but reparented back to root window

Get Context Menu text of specific TaskBar button

I've got some code that grabs the TaskBar buttons and their text from the windows TaskBar using User32.SendMessage with the TB_GETBUTTON message to retrieve a TBBUTTON structure (Win32 API via C# P/Invokes). But I'm trying to figure out how to then, once I have the handle to the button, grab the associated context menu text. There is some status information on there for a specific application that I would like to retrieve. The button text gets me some of it, but I need to the context menu text to complete it.
Any ideas?
This is not completely clear... Context menus don't have text, as such - they have menu items, each one of which will have text. By "context menu text", do you mean the text of the menu items in the taskbar button's popup/context menu? For example, "Restore", "Minimize" etc in the screenshot below?
If so, I suspect you're going about this the wrong way:
This menu doesn't belong to the button, but is the system menu of the window represented by the taskbar button. If the button has a context menu, this is probably for a grouped collection of windows, not one specific window (or even windows for one process.)
Making judgements based on the context menu of a window sounds like a dodgy approach to me, especially based on text since that will change depending on where in the world your user is located. Applications can also change the contents of this menu so there's no guarantee it will contain something you expect to be there. It would be better to check the window style, if it's minimized, etc, to find out the information that also affects the contents of the menu.
I'm going to answer this based on what your needs seem to be from the question, not what you've directly asked, since (a) it's not possible as asked and (b) I think you're trying to do something else. (As a general guideline, in a question it's good to state why you're trying to do something - and even maybe ask about that, ie 'how do I achieve X' - in case there's a better method than the one you're using. Here, X is probably 'find out information about this window' not 'get the text of the context menu', because that's probably only one possible method to get to X.) Also I think extracting data from the internals of a third-party application like Explorer (the taskbar is an Explorer window) is fragile and prone to break in future versions of Windows.
The system menu or window information (whichever one) belongs to application windows. Unless taskbar buttons are grouped (and then it's the subitems) one taskbar button corresponds to one specific window in the system. So what you want to do is find these windows. You do this by:
Using the EnumWindows function
Then for each window that is passed to the callback, checking the extended window style using GetWindowLong with GWL_EXSTYLE to see if the WS_EX_APPWINDOW bit is set
In addition, sometimes other windows are shown: these heuristics should help.
Each one of these windows is a window that should appear on the taskbar, Alt-Tab dialog, etc.
You say you're getting the text of the taskbar button - this is probably the window caption of the window, and GetWindowText is the canonical (read: probably a lot more reliable) way to get the caption of a window belonging to another process.
If you really want the popup menu, then:
Use GetSystemMenu to retrieve the handle for the system menu for the window. Applications can customise this, so if your app is doing this (and that's why you want the popup menu) ensure you pass false to the bRevert parameter
You can then get the number of menu items using GetMenuItemCount and for each one call GetMenuItemInfo to get info about each menu item. Pass true to the fByPosition parameter to indicate you're accessing the menus by position (since you know the count, you're getting item 0, 1, 2... count-1).
This fills a MENUITEMINFO structure, which (I think, I haven't ever had to code this so I haven't tested) will tell you the text associated with an item via the dwTypeData field "if the MIIM_STRING flag is set in the fMask member".
If you really want information about the window status, you can get this information using methods like IsIconic to see if it's minimized, GetWindowLong again to get other information, etc. I'd suggest you ask another SO question about how to get whatever specific information about a window for details.
Hope that helps!

How to create full screen window with MFC?

I want to create full screen topmost (screen saver) window with MFC? How to create such full screen window in MFC? I tried to create win32 application and i am able to create fullscreen top most window but i want to create using MFC so later i can put different MFC controls on that window?
Please help me.
Thanks,
Jim.
I think removing the border from the dialog resource and showing the window as maximized (ShowWindow(SW_SHOWMAXIMIZED)) should do the job.
As for topmost use the System Modal style in the dialog resource.
I do it with a Dialog Box app. In the resource editor properties for the dialog resource, set Border=None and Title Bar=False to eliminate all border elements. In OnInitDialog, use the following to resize the dialog to the entire desktop:
CRect rcDesktop;
rcDesktop.left = GetSystemMetrics(SM_XVIRTUALSCREEN);
rcDesktop.right = rcDesktop.left + GetSystemMetrics(SM_CXVIRTUALSCREEN);
rcDesktop.top = GetSystemMetrics(SM_YVIRTUALSCREEN);
rcDesktop.bottom = rcDesktop.top + GetSystemMetrics(SM_CYVIRTUALSCREEN);
MoveWindow(rcDesktop, FALSE);
This code works on multiple monitors, unlike maximizing the window.
No need to worry about making the window topmost, Windows will display it on a dedicated desktop with no other windows present.
You should be able to adapt the example code here to do what you want:
MSDN: Initializing a dialog box

Resources