I have window created using win32 api. How can I detect if a file is dragged (not dropped) over my window? And how to get list of filenames. I know DragAcceptFiles/WM_DROPFILES messages but they don't register for dragging. I get the message when the user drops. So I cannot show if the dragged files can be dropped to that location or the file type is valid etc... I tried with Spy++ I am definitely getting no message, however when I check explorer windows I see that they are passing custom messages (WM_USER+210).
I am searching for a winapi only solution.
To answer my question with the help of Raymond Chen,
Register your window as drop target.
http://www.catch22.net/tuts/drop-target
http://msdn.microsoft.com/en-us/library/windows/desktop/bb776904(v=vs.85).aspx
and read file drop data using
http://msdn.microsoft.com/en-us/library/windows/desktop/bb776902(v=vs.85).aspx
Related
My program/environment...VS2010, C++, MFC100, CWinAppEx, CMDIFrameWndEx. MFC feature pack.
I am creating and handling a CPreviewView derivative. My method treats this preview view as a normal view that the user can keep up and active. Where as the default PreviewView paints over the current view and 'takes over' the child frame.
One thing I can't figure out is how to gain control over the ON_UPDATE_COMMAND_UI message maps that should be directed to all CDocuments. When a CPreviewView is created it somehow disables all the command handlers to CDocuments. The command handlers to CViews are still up and working.
All Documents open in my MDI app don't receive their ON_UPDATE_COMMAND_UI messages. I can move these message handlers out to the View, or Frame but there are too many to do this efficiently.
Does anyone know where in the CPreviewView class turns off document handlers?
First of all, MFC is not a "locked" framework. Its complete source resides on your own PC in the following folder: "your Visual Studio folder"\VC\atlmfc\src\mfc\ (on my PC it is: c:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\src\mfc) The source for CPreviewView is in viewprev.cpp file. I just opened the file and in the DoPrintPreview they are calling this:
pParent->OnSetPreviewMode(TRUE, pState); // Take over Frame Window
According to MSDN this method:
The default implementation disables all standard toolbars and hides the main menu and the main client window. This turns MDI frame windows into temporary SDI frame windows.
I have opened the file called winfrm.cpp and checked that this method is doing, and it does disable all the menu. Obviously, no Update messages will be sent to documents while preview mode is on.
The MSDN article at the hyperlink above says that you need to override the OnSetPreviewMode method for your frame to:
customize the hiding and showing of control bars and other frame window parts during print preview. Call the base class implementation from within the overridden version.
This should not be a problem.
I am new to Windows programming, mostly done Java(Java SE, Java ME, Android, Java EE), so be detailed and gentle.
I want to capture "the name of the file/path that was clicked in windows, like clicking a file on the desktop"?
Further research http://www.codeproject.com/Articles/6362/Global-System-Hooks-in-NET, which is a small c#/c++ nice app that uses Global System Hooks, to capture mouse events such as coordinates,clicks,etc.
So what is the right API or Global System Hook that captures events on file icons?
There is no single API that provides that level of detail.
The WH_MOUSE and WH_MOUSE_LL hooks of SetWindowsHookEx(), or the WM_INPUT message delivered by RegisterRawInputDevices(), can tell when the mouse is being intereacted with, and the GetCursorPos() function can tell you where the mouse cursor is located onscreen at the time of a click, but it cannot tell you what it is clicking on. You have to figure that out manually.
For instance, the Desktop is implemented as a ListView control, so you can use the WindowFromPoint() and GetDesktopWindow() functions to check if the mouse is located at coordinates corresponding to the desktop window itself instead of an application window, and if so then use the LVM_HITTEST and LVM_GETITEM messages to determine which icon onthe desktop is being clicked on and extract its display text. Then use the SHGetDesktopFolder() function and the IShellFolder interface, or the SHParseDisplayName() function, to parse that text and see if it returns a PIDL that represents a path/file, and if so then use SHGetPathFromIDList() to get the actual path/file name.
If you want to do the same thing with the Windows Explorer app, it gets a bit more complicated. Use WindowFromPoint(), GetWindowThreadProcessId(), OpenProcess(), and EnumProcessModules() to determine if the mouse is over the Windows Explorer app. However, its UI changes from on Windows version to the next, but the jist is that you have to manually locate the focused control via AttachThreadInput() and GetActiveWindow(), check if it is a TreeView/ListView control, and if so then use control-specific messages to get information about the item/icon underneath the mouse cursor coordinates, and use IShellFolder again to figure out what the text of that item/icon actually represents.
Shell programming is very complex system and not for the feint of heart to interact with. So you need to ask yourself, why do you need this information in the first place?
I've been messing with Win32 API for abit, and I've got a question regarding the GUI functions.
How does one handle user input that is not managed through popup windows? I've been reading http://www.winprog.org/ but right when the interesting features comes -- lesson9 -- it becomes more abstract and I'm not sure how to do it.
Basically what I am after is the user to write input in two windows and then press a button to send a message that the content of the input is to be processed.
I think the input windows would be some EDIT-class windows and the input BUTTON-class but that's about it.
Any ideas? I'm sure it's simple, it's just makes me want to rip my hair of in native code :p
Cheers
You're correct, you want and EDIT control which is more commonly known as a TextBox and a BUTTON class which is a command button.
To get the the input the Button will send a WM_COMMAND message to its parent window with a BN_CLICKED in the wParam high word. You can identify the particular button from the hWnd you get in that message.
After that you'll need to post a WM_GETTEXT to the edit control to retrieve the users input.
This is all from memory so I highly recommend looking up the msdn pages before you code.
I'm not sure I follow 100%. Yes, you would use EDIT and BUTTON-class controls for that. Where are you getting stuck?
I am curious how spy++ Finder Tool finds out the window handle for the window over which the mouse is.
Is there any WIN32 function for getting the handle of the topmost window that occupies a certain pixel on the display?
There is a WindowFromPoint() function.
Here is a pretty complete example of how to implement the spy++ finder.
http://www.codeproject.com/KB/dialog/windowfinder.aspx
There is some nice information on the internals of Spy++ here: http://blogs.msdn.com/b/vcblog/archive/2007/01/16/spy-internals.aspx. It supports DeusAduro's reply, that Spy++ installs global hooks (actually 3 hooks, one of which is WH_CALLWNDPROC).
You can also find some more info on a Spy++-clone here: http://www.codeproject.com/KB/dialog/windowfinder.aspx.
Also, there should be a download for a very similar app in the SDK here: http://msdn.microsoft.com/en-us/library/Aa231779 but it seems to be broken (no download - like so many links on msdn :( ).
Depending on what you want to get (if it is not a hwnd) you can also get an AutomationElement:
System.Windows.Point pt = new System.Windows.Point(System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y);
AutomationElement ae = AutomationElement.FromPoint(pt);
WindowFromPoint or ChildWindowFromPoint API functions.
Don't quote me on it, but I believe spy++ would install a WH_CALLWNDPROC hook. This then gets sent all the WM_MOUSEMOVE messages before they reach their target windows. Thus as soon as you mouse over a window, spy++ recieves a message telling it which window.
I need to create an application which do the following:
At the beginning we have notepad window open with a lot of text in it.
Our application must scroll through this file and take notepad window screenshot after each scroll action.
I've tried to achieve this using SBM_GETRANGE, SBM_GETRANGE, SBM_SETPOS but it does not work for me.
Please note that emulating keyboard events (e.g. PageDown, PageUp) is not an option for me because this application should also work with other applications which may not support keyboard shortcuts for manipulating scrolls.
Thanks.
Don't try to manipulate the scrollbar directly - instead SetFocus() to the text window, then send Page Down messages. If there are applications where you must manipulate the scrollbar, you should get its window handle and send the messages there.