I just implemented drag&drop in my application. It goes two ways:
From my app to Windows Explorer: exports files
From Windows Explorer to my app: imports files
One side effect is that I can also drag files from my application to my application (the same window), which is not intended.
Is there a elegant way to make sure, that a drag&drop operation I started won't be accepted by my application? E.g. check if the source of the drop operation != my application?
You need to register the fact that you initiated a drag from inside your application with some sort of facility or service. If you receive a drop on your application, ask the facility/service if the drag was initiated within your application. If so, discard. Reset the facility/service afterwards (in any case).
I just figured out a way to do this.
Now I set two types of data on my drag&drop data object:
The file names I want to export
A Unicode-Text object containing the name of my application
In my Drop-handler I check if a Unicode-Text object is present and if it contains my application's name. If so, I abort the drop operation.
Related
I have a carefully formatted report in Access 2013 and I'm trying to create a UI that will print this report upon a button click. I would be open to a C# WPF or Form app or perhaps an HTML page that could contain this button.
Does anyone know if this is possible and if so what the code would be?
My end goal is to have the user be able to print this report without having to access the database directly. I am open to other languages/platforms.
At the end of the day you still need Access installed, and at the end of the day you still have to launch Access, and at the end of the day you still 100% relying on Access.
Thus to print an Access report you still have to launch Access. It not at all clear why then you cannot built your required UI in Access since you still 100% relying on Access for this report.
You thus will have to automate Access and rely on Access. You can use any system or language that supports COM object automation.
So in say windows scripting, you could go:
Dim app As Object
Set app = CreateObject("access.application")
app.OpenCurrentDatabase ("path to database")
app.DoCmd.OpenReport ("ReprotName")
app.CloseCurrentDatabase
app.Quit
The above same code would work in vb.net. Note that the “default” to open the report will send it to the printer without preview.
Also keep in mind that since you are creating an instance of the Access application, then all of the startup code and forms will launch and run. If such startup code and the startup form being run requires ANY user interaction, then the above will not work. Because of the above “many” issues, you likely best create an application that has linked tables to the data, and contains your required report. This approach will thus avoid all of the existing application code and startup forms running.
So in any case you WILL have to launch the application and deal with all of the startup forms etc. As noted, often then it makes sense to copy out the report to a separate application with linked tables for your purpose.
Keep also in mind that the Access runtime (as opposed to full version) does not support nor allow use of CreateObject - you have to resort to shell() with startup parameters to launch + run the report.
Last but not least, you can from the Access UI simply DRAG the report to your desktop. The result is a one click button on your desktop that will launch the report in question.
Hello all i have a rather specific Question and please consider my apologies if this is not a standard stack-overflow question ,
i need to know is it possible to get all control names of another exe e.g.
i have a c# application and i want to get all control names of another standalone application running on my computer say b.exe so if b.exe have a textbox and a button in it i want to have names of textbox and button in my c# exe and also i want to have a listener for click events of b.exe
till now whatever i have researched is nothing special actually i dont want full code snaps i just want a guideline can i do it thorugh pinvoke? or winapi? please explain what is pinvoke and winapi and is it possible through application hooking ? once again i need a guideline a way to follow so please help me out regarding this, i know i can get active windows name through pinvoke or winapi but my requirements are little high
1 . Access to control names:
Unfortunately I do not .NET (C#) but under Visual C++ this would be impossible.
The reason is: The controls do not have names in the executable any longer but the names are simply converted to numbers.
Example "myTextControl" would be 1234 in the executable. The information about the (original) name of the control gets completely lost while compiling.
2 . Accessing controls in other executables:
I think under .NET (C#) it is not as easy as under native programming languages (directly accessing the Windows API) but it is possible to access controls of other executables as long as you know the number (e.g. 1234).
Therefore you'll have to find out the window handle of the dialog window containing the control and then you can send messages to the control. Unfortunately many messages containing pointers will require some very tricky hacks. Messages without pointer work well.
3 . Creating a listener for a control in other executables:
Creating a listener (e.g. a click listener) on a control in another EXE is possible however very tricky: This would require writing a native (this means: not .NET / C#) DLL file which is then combined with the Windows API function "SetWindowsHookEx".
I do not think that a .NET API (required for C#) already exists that will do this because there are only few use cases for this.
I am working on a application, which would be the face of lot of other tools running in background. I am facing an issue. During the launch of a background application ,it needs to load a specific file(file-->load--> file name).
Let the front end application be Fapp and the background application be Bapp. Is it possible for Fapp to get the handle of Bapp's menu item and trigger the load function. I am able to get the handle for buttons but not able to do the same for menu items.
Now we are achieving this using AutoIt, I am trying to achieve this in C# itself.
After you have obtained the handle of the window that you want to invoke its menus, then you may use
HMENU GetMenu(HWND) windows api to get menu
HMENU GetSubMenu(HMENU, int) to get to the file menu and again to open menu.
BOOL GetMenuItemInfo( ... ) to get info about menu
and you can use PostMessage((IntPtr)hWnd, WM_COMMAND, 0, ID_MENU_ITEM); (related post) to perform a click on that item.
all these apis are what AutoIt calls (I think). This solution works if your Bapp is a normal windows application with a normal windows menu, not a fancy WPF app, or a ribbon. If this is the case, then what you see as menu probably is not a menu (technically anyway)
Are you sure this is the right way to get two applications talking to each other?
If you don't have source code for BApp, and it also doesn't have an API that you can use, then pretending to be an interactive user could be the only way to interact with it. Just be aware that it is fraught with issues, consider what will happen when
BApp isn't already running
BApp has a modal dialog open
BApp is in the middle of an operation (or hanging) and its menu is disabled
BApp is updated to a new version and its UI changes
An interactive user changes focus, in the middle of an operation.
An alternative to this would be to do the same thing that you do when you are unit testing an application with a UI. This is because you are doing the same thing, automating an application by making calls that execute its functions, in this case to test the results are as expected. Since this is a WPF post lets assume that you are writing an application with MVVM, and the best way (to avoid brittleness when we are change the UI) is to ignore the UI (View) and call the layer that sits underneath i.e. the VM (ViewModel).
In fact its quite easy just to add a self-hosted WCF connection inside your BApp application so that it can be called externally.
this._host = new ServiceHost(service);
this._host.AddServiceEndpoint(typeof(IContract), new NetTcpBinding(), address);
this._host.Open();
This would then enable you to get the two talking totally independently.
If your Bapp is able to somehow invoke Win32 API - then this can be achieved by sending a custom WM_USER message to your Fapp - using SendMessage(). In your Fapp you handle this message and take appropriate action.
I don't think getting handle to a control and invoking its handler is the right way.
I have a few questions on good programming design. I'm going to first describe the project I'm building so you are better equipped to help me out.
I am coding a Remote Assistance Tool similar to TeamViewer, Microsoft Remote Desktop, CrossLoop. It will incorporate concepts like UDP networking (using Lidgren networking library), NAT traversal (since many computers are invisible behind routers nowadays), Mirror Drivers (using DFMirage's Mirror Driver (http://www.demoforge.com/dfmirage.htm) for realtime screen grabbing on the remote computer).
That being said, this program has a concept of being a client-server architecture, but I made only one program with both the functionality of client and server. That way, when the user runs my program, they can switch between giving assistance and receiving assistance without having to download a separate client or server module.
I have a Windows Form that allows the user to choose between giving assistance and receiving assistance. I have another Windows Form for a file explorer module. I have another Windows Form for a chat module. I have another Windows Form form for a registry editor module. I have another Windows Form for the live control module. So I've got a Form for each module, which raises the first question:
1. Should I process module-specific commands inside the code of the respective Windows Form? Meaning, let's say I get a command with some data that enumerates the remote user's files for a specific directory. Obviously, I would have to update this on the File Explorer Windows Form and add the entries to the ListView. Should I be processing this code inside the Windows Form though? Or should I be handling this in another class (although I have to eventually pass the data to the Form to draw, of course). Or is it like a hybrid in which I process most of the data in another class and pass the final result to the Form to draw?
So I've got like 5-6 forms, one for each module. The user starts up my program, enters the remote machine's ID (not IP, ID, because we are registering with an intermediary server to enable NAT traversal), their password, and connects. Now let's suppose the connection is successful. Then the user is presented with a form with all the different modules. So he can open up a File Explorer, or he can mess with the Registry Editor, or he can choose to Chat with his buddy. So now the program is sort of idle, just waiting for the user to do something. If the user opens up Live Control, then the program will be spending most of it's time receiving packets from the remote machine and drawing them to the form to provide a 'live' view.
2. Second design question. A spin off question #1. How would I pass module-specific commands to their respective Windows Forms? What I mean is, I have a class like "NetworkHandler.cs" that checks for messages from the remote machine. NetworkHandler.cs is a static class globally accessible. So let's say I get a command that enumerates the remote user's files for a specific directory. How would I "give" that command to the File Explorer Form. I was thinking of making an OnCommandReceivedEvent inside NetworkHandler, and having each form register to that event. When the NetworkHandler received a command, it would raise the event, all forms would check it to see if it was relevant, and the appropriate form would take action. Is this an appropriate/the best solution available?
3. The networking library I'm using, Lidgren, provides two options for checking networking messages. One can either poll ReadMessage() to return null or a message, or one can use an AutoResetEvent OnMessageReceived (I'm guessing this is like an event). Which one is more appropriate?
Put as little code as possible in the form. You should create a seperate class/set of classes to handle this and make the form use them to draw.
An event seems like a good idea. I wouldn't let the form subscribe, but have another class do the processing and just pass the processed data to the form (through another event).
I would use the event, because it probably checks async, which is what you want. You do not want to lock the form while waiting on messages.
My C# program has a list of files that can be dragged from it and dropped into another program. My requirements are that the file be copied to a different directory first.
So, can I be notified of the drop operation so that I can only copy the file if operation succeeds? I'd rather wait till I know it needs to be copied before actually performing the copy.
Also, is it possible to know what program the drop operation is occurring in? Ideally I'd like to alter the filepath based on who or what its being dropped.
The solution to this can be in any .NET language or C/C++ with COM.
There are a few ambiguities in your question. What operation needs to be successful?
For everything you want to know about drag and drop, browse through these search results (multiple pages worth):
Raymond Chen on drag and drop
So, you intend to modify the data being dropped based on the drop target? I don't think this is possible; after all, you populate the data when the drag is initiated.