Problems with using TrackPopupMenu on win7 - winapi

I'm trying to create context menu using TrackPopupMenu function in my application, the code I use in it is like the following:
CMenu menu;
if (menu.LoadMenu(IDR_MENU_TRAY))
{
CMenu* pSubMenu = menu.GetSubMenu(0);
if (pSubMenu != NULL)
{
pSubMenu->ModifyMenu(IDM_CLOSE,MF_BYCOMMAND,IDM_CLOSE ,g_cfg->GetLang(TEXT_MAIN_CLOSE,"Exit(&X)"));
pSubMenu->ModifyMenu(IDM_SHOW,MF_BYCOMMAND,IDM_SHOW ,g_cfg->GetLang(TEXT_MAIN_OPEN_SHUTTER,"Open(&O)"));
CPoint point;
GetCursorPos(&point);
SetForegroundWindow();
pSubMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, messageOnlyWnd);
}
}
The code runs perfect on WinXP, while on win7 and vista it doesn't. The Problem on win7 and vista is that it takes a fairly long time to pop up the menu, maybe 1 min or more. But if I turn off the Aero on win7 or vista, it runs smoothly just like on winXP, so I guess somethin must be conflicted with Aero in the code, but I just don't know how to fix it. Is there anyone can help me with that? I will appreciate it a lot if anybody helps me out.

I don't see anything wrong with this code. I've used TrackPopupMenu on Vista without any problems. The source of the problem might lie elsewhere. Try removing the call to SetForegroundWindow. If that doesn't work, try creating an empty project with just the popup menu code.

Related

Mimic Win 7 Favorites on Windows 10 (Shell Namespace Extension)

Hello dear stackoverflow friends
A few months ago I asked you a question about QuickAccess (Pin/Unpin). Unfortunately we are still facing this issue (Unable to unpin virtual objects). After having called Microsoft Support a few times, they replied us we should subscribe to premier support... Too expensive for a small company.
So we have decided to Mimic the Windows 7 Favorites in our Shell Namespace Extension.
No big deal in the Explorer, calling ShellExecuteEx with view's handle and lnk's target object absolute pidl works like a charm.
Too good to be true, yeah, as it is not working as expected in IFileDialogs...
First the lnks (wrapped in a virtual object, but parsing name is Filesystem Path) weren't for obvious reasons shown in the dialogs. So we tried with attributes such as "SFGAO_FOLDER", "SFGAO_FILESYSANCESTOR" etc. but then the shell was calling IShellFolder's EnumObjects and that's not what we want.
So we decided to have a go with the Interface IObjectWithSite, implementing it in our Favorites' folder. We were then able to consume events from IFileDialogs such as OnSelectionChange. Then we tried the same method as in the explorer, getting view handle (first querying IOleWindow interface, getting window handle, creating view in parent IShellFolder using window handle) and calling ShellExecuteEx... And the result is.. A big application (Notepad, Word etc.) crash and a new Explorer Window with the right virtual object selected.
Probably is my approach too complicated, have you got any ideas?
Thanks a lot!
Thank to Simon, I was able to find a solution, still work in progress. The issue is that the IContextMenu, IContextMenu2 and also IContextMenu3 interfaces are implemented in the solution. On Windows 7, the .lnk menu handler was called, fine, on Windows 10 on the other hand you need to call SHCreateDefaultContextMenu, then merging the menu handlers (SHCreateDefaultContextMenu will then Call IShellFolder::GetUIObjectOf with IID_IQueryAssociations). So the code was dated... Thanks!

C# SendKeys and Microsoft SQL Server Management Studio 2012 (SSMS)

Solved! See [SOLUTION]
Thanks for any help you can provide. It's much appreciated!
In a nutshell: I'm trying to send Ctrl+V to SSMS 2012 with SendKeys.Send("^{v}"), but it doesn't work. It's working fine with Notepad, UltraEdit, Word, Excel, Chrome, you name it. It even works in Microsoft Visual Studio 2010.
In details: I have an application that runs in the background. Using a keyboard shortcut, this application displays a popup window with options. Depending on the option I choose it saves what's related to it into the clipboard. I then close that popup window, get the new foreground window (which should be the one I had before displaying the popup) and try to paste what's in my clipboard with SendKeys.
It works with pretty much every application I try it with, except SSMS
If I manually press Ctrl+V it pastes what I have in my clipboard (text usually)
I've added some code to display the title of the window I got with the GetForegroundWindow and it does give me the correct SSMS window
What's sad about all this is that once in a while (very rarely), the text is correctly pasted in SSMS, but it doesn't work the second after.
I never get the MessageBox saying the SetForegroundWindow failed.
If I replace the single SendKey with 3 SendKeys to send "A", "B" and "C", B and C are sent but not A. Yes I've tried using a sleep thinking it needed time to write the first SendKey, but that didn't change anything.
I did try SendKeys.SendWait instead, but didn't get different results.
Here's the code from the moment I close the popup
this.Close();
IntPtr handle = GetForegroundWindow();
if (!handle.Equals(IntPtr.Zero))
{
if (SetForegroundWindow(handle))
{
//Optionnal just to show the window title
const int nChars = 256;
StringBuilder Buff = new StringBuilder(nChars);
if (GetWindowText(handle, Buff, nChars) > 0)
{
MessageBox.Show(Buff.ToString());
}
//[SOLUTION] Sending a useless key seems to solve my SSMS problem without affecting the other applications.
SendKeys.Send("{F14}");
//Sending Ctrl+V
SendKeys.Send("^{v}");
}
else
{
MessageBox.Show("SetForegroundWindow failed");
}
}
Hope someone can help.
Thanks in advance!
See http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx
...
The SendKeys class is susceptible to timing issues, which some developers have had to work around. The updated implementation is still susceptible to timing issues, but is slightly faster and may require changes to the workarounds. The SendKeys class tries to use the previous implementation first, and if that fails, uses the new implementation. As a result, the SendKeys class may behave differently on different operating systems. Additionally, when the SendKeys class uses the new implementation, the SendWait method will not wait for messages to be processed when they are sent to another process.
...

Internet Explorer 8 64bit and Selenium Not working

I am trying to get selenium tests to run. Yet every time I try to run a tests that should run IE I get a error on line 863 of htmlutils.js It says that I should disable my popup blocker. The thing is I went to IE tools-> turn of popup block.
So it is disabled and I get this error.
Is there something else I need to disable. I actually don't even know what version of Internet explorer it is running since I am using Windows 7 Pro 64bit version. So when I do use IE I use 64bit version but I am under the understanding if the site or something like that does not support 64bit it goes to 32bit.
So not sure what I need to do it to make it work.
This is the lines where it does
function openSeparateApplicationWindow(url, suppressMozillaWarning) {
// resize the Selenium window itself
window.resizeTo(1200, 500);
window.moveTo(window.screenX, 0);
var appWindow = window.open(url + '?start=true', 'selenium_main_app_window');
if (appWindow == null) {
var errorMessage = "Couldn't open app window; is the pop-up blocker enabled?"
LOG.error(errorMessage);
throw new Error("Couldn't open app window; is the pop-up blocker enabled?");
}
Where is this log.error message stored? Maybe I can post that too.
I had a similar problem on Vista and IE8
I would get the same error message
Couldn't open app window; is the pop-up blocker enabled?"
Running my remote control as Admin wasn't an option for me, and also a poor idea from a security perspective.
So in the end I manage to solved this by changeing browser from "*ietha" to "*iexploreproxy"
grid_configuration.yml
hub:
port: 4444
...
- name: "Internet Explorer 8 on Vista"
browser: "*iexploreproxy"
...
Alternatively, you can change browser string from the code:
ISelenium selenium = new DefaultSelenium("localhost", 4444, "*iexploreproxy", "http://www.google.com/");
Works like a charm.
The only question remaing is if this somehow affects the outcome of the test cases. So far no, but I'll update this answer in case that would happen.
I ran into this on Windows 7 64bit.
My solution was:
Disable popup block. - Select "Tools/Popup Blocker/Turn off pop-up blocker"
Disable IE protected mode. - Untick "Tools/Internet Options/Security/Enable protected mode"
It'd be better just to disable protected modes for known trusted hosts/addresses. I'll leave that as an exercise for the reader.
I was experiencing the same problem. I ran the Selenium RC server as an administrator and everything worked fine.
I, too, am experiencing this very problem on a Windows 7 64bit box, trying to run Selenium on it to test and ASP .Net MVC application, written in C#.
I am still trying to work out the answer for myself, but I thought I'd post here to tell you of a little progress I have made in getting something to work, albeit in Firefox instead of IE.
Here's the line I changed:
selenium = new DefaultSelenium("localhost", 4444, "*chrome C:/Program Files (x86)/Mozilla Firefox/firefox.exe", "http://www.bbc.co.uk/");
I would ideally like for this to work in Internet Explorer 8, but if for the moment, I can begin getting tests working and later change over to use IE again, then great.
Hope this helps for your problem with it all.
I had the same problem on Windows 7 64bit IE8. The first step was to disable the IE popup blocker. Then, I got a message in the status bar saying that "Pop-ups were blocked on this page. Press the 'Ctrl' key to allow the pop-ups".
It turns out that the Google Toolbar was providing this feature. Disabling it solved the problem. View > Toolbars > Google to toggle.
John.
If you happen to be doing this from JavaScriptMVC, there is a reference you need to change in \jmvc\plugins\test\drivers\selenium.js:
1) Change iexplore to iexploreproxy and you should get better results:
msie : (/iexploreproxy/i).test(browserStartCommand),
2) At this point, you'll find that you still get the popup error, but a separate instance of IE has started. Leave that IE window open and restart the tests, but not Selenium.
3) Next, the windows should show up in the right place, but IE gives the annoying block active content warning. Allow the content to run and restart the tests, but not Selenium itself.
This is super clunky, but it at least gets you past that part. If I find more methodical ways to do these things I'll update as needed.
I have had the same problem and have found another solution which works for me. Just use the *iexploreproxy setting in the browserString.
I used:
selenium = new DefaultSelenium("localhost", 4444, "*iexploreproxy C:/Program Files/Internet Explorer/iexplorer.exe", "http://www.bbc.co.uk/");
I hope that works for others too :)
You can start the test when you disable the Security mode of Internet. Don´t know the correct name for it, but in dutch it is beveiligde modus.
I tried modifiing the security settings to dublicate this security mode, but couldn´t find the correct setting for it. It must therefor block more then you can set manually.

Win32 Dialog closing on startup

I recently asked a question here about a dialog problem I had, but i discovered that the problem lies in such a different area i intentionally thought that I will rephrase my question here.
The problem is that I've been working on a DirectX10 game engine. When the engine inits there should pop up a dialog box which gives the user the possibility to choose settings. To develop this i created a separate solution (visual studio 2008) where i made the dialog resource and the proc function. I tested it there with a small winmain function and it works perfect.
Then I copied the resource and all the code to my main engine and fired it up. The only thing that happens is that the dialog pops up very shortly and it immediately closes without even waiting for user input. Also the MessageBox function does the same thing. I went through every step, but I'm really stuck.
Could any of you please look at the code for me and see if you can find what the *bleep* is going on?
There are three different folders in the zip. VKRenderer is the rending part of the engine where the VKD3D10 is a directX10 implementation of the in VKRenderer defined RenderDevice. In the VKRenderer solution also all the exported functions get exported from VKD3D10. VKD3D10 builds to a dll and VKRenderer to a .lib. Then there is StartupTest which uses the builds to try and start up the engine. The SettingsDialogTest is where i created the settings dialog and all the resources. There you can also find the working version of the settings dialog.
The ZIP file can be downloaded here. (The engine is still under development, so be kind with you comments :P ) THANKS A TON IN ADVANCE
pass = HELP
At a guess, try changing:
INT_PTR i = DialogBoxParam(hinst, L"IDD_SETTINGS", hwnd, DlgProcWrapper,(LPARAM) this );
to
INT_PTR i = DialogBoxParam(hinst, MAKEINTRESOURCE( IDD_SETTINGS ), hwnd, DlgProcWrapper,(LPARAM) this );

how to get the icon of a java application?

I've got a code that lists the running application on a win32 box, and then displays theirs icons.
So far so good, I get the hwnd of the app, then call for GetClassLong(hwnd,GCL_HICONSM), and everything's fine.
But the case of a java apps is a pain to deal with, as the process answering to my calls is javaw.exe, and not the shiny-pimpy java application, who's got a so beautiful icon...
I gave a shot at GetWindowThreadProcessId also, but alas, it's the PID of javaw that's returned...
There's a way to do this though, as the task manager (alt+tab) displays the good icon.
I answer to my own question, thanks to PhiLho who put me on the right track: an article from Codeproject with the right algorithm to get a window icon (wether it's java or not):
//first, try:
SendMessageTimeout(WM_GETICON)
//if no icon found, try
GetClassLong(GCL_HICONSM)
//if still no icon, try
SendMessageTimeout(WM_WM_QUERYDRAGICON)
//if still no icon, you're doomed, return an error, or a void icon
For some reason a java app answers to the first call, but not to the others, which seems to be handled by javaw.exe.
Thanks again PhiLho.
Mmm, it can be done, because Process Viewer has a Show Applications button which does that (even if the main view shows the Java's icon). Alas this freeware isn't open source, so it won't tell its secret... :-(
Sysinternals' ProcMon doesn't do that, alas.
I will dig a bit more... :-)
[EDIT] Both a MS KB article and a Code Project article recommend using WM_QUERYDRAGICON if GCL_HICON fails...

Resources