The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
[UWP] Drag & drop text into Win32 text editor RRS feed

  • Question

  • Hi,

    There are editors like EditPlus (similar to UltraEdit). If I drag text from my C# UWP app and drop it into the editor, the text will not be taken. If I drop the text from my app into WordPad, the text will be inserted. If I drag and drop the text from WordPad into EditPlus, it will also be inserted there.

    Why can't I drag and drop the text from my app into other Win32 text applications?

    What do I have to do for it?

    private async void borderSmth_DragStarting(UIElement sender, DragStartingEventArgs args)
    {
    	string text = "Hello!";
    
    	args.Data.SetText(text);
    	args.Data.Properties.Title = text;
    	args.Data.RequestedOperation = DataPackageOperation.Copy;
    	args.Data.Properties.ApplicationName = "MyApp";
    }

    Best Regards,
    Heiko

    Saturday, November 9, 2019 6:57 PM

All replies

  • Hi,

    I made a sample for the behavior you said. I created a UWP app that I could drag text and a WPF app that could receive a dropped object. 

    But everything works well on my side. WPF app could receive the text that dragged from UWP apps. So your code in UWP apps to set dragged data should be correct. I suspect the problem is related to how the win32 text application handles the dragged data.  If you have the source code of the win32 text application, you could debug the drop event in the app to see if the win32 application is handling the event correctly. But this is more related to win32 development.

    Best regards,

    Roy


    "Developing Universal Windows apps" forum will be migrating to a new home on Microsoft Q&A (Preview)!
    We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A (Preview)!
    For more information, please refer to the sticky post.

    Monday, November 11, 2019 4:31 AM
    Moderator
  • Hi,

    Thank you for your reply. Both apps, WorPad and EditPlus, know nothing about each other. I was hoping to find out what makes WordPad different from my example and if what makes WordPad different is possible in UWP at all.

    With Spy++ I have compared various messages. When dropping text from the UWP app to EditPlus, there are significantly fewer messages sent to EditPlus. When successfully dropping text from the UWP app to WordPad or from WordPad to EditPlus, messages like WM_IME_SETCONTEXT and WM_GETOBJECT appear.

    Messages in EditPlus when dragging text from the UWP app, without success:

    <00001> 000106F6 S WM_NCHITTEST xPos:789 yPos:389
    <00002> 000106F6 R WM_NCHITTEST nHittest:HTCLIENT
    <00003> 000106F6 S WM_NCHITTEST xPos:789 yPos:389
    <00004> 000106F6 R WM_NCHITTEST nHittest:HTCLIENT
    <00005> 000106F6 S WM_SETCURSOR hwnd:000106F6 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
    <00006> 000106F6 R WM_SETCURSOR fHaltProcessing:False
    <00007> 000106F6 P WM_MOUSEMOVE fwKeys:0000 xPos:138 yPos:288

    Messages in EditPlus when successfully dragging text from WordPad:

    <00001> 000106F6 S WM_IME_SETCONTEXT fSet:1 iShow:C000000F
    <00002> 000106F6 R WM_IME_SETCONTEXT
    <00003> 000106F6 S WM_GETOBJECT dwFlags:FFFFFFFF dwObjId:FFFFFFFC
    <00004> 000106F6 R WM_GETOBJECT dwRet:FFFFFFFF
    <00005> 000106F6 S WM_GETOBJECT dwFlags:00000000 dwObjId:FFFFFFF4
    <00006> 000106F6 R WM_GETOBJECT dwRet:00000000
    <00007> 000106F6 S WM_SETFOCUS hwndLoseFocus:000106EC
    <00008> 000106F6 R WM_SETFOCUS
    <00009> 000106F6 S WM_KILLFOCUS hwndGetFocus:000106F6
    <00010> 000106F6 S WM_PAINT hdc:00000000
    <00011> 000106F6 S WM_ERASEBKGND hdc:14011062
    <00012> 000106F6 R WM_ERASEBKGND fErased:True
    <00013> 000106F6 R WM_PAINT
    <00014> 000106F6 R WM_KILLFOCUS
    <00015> 000106F6 S WM_IME_SETCONTEXT fSet:0 iShow:C000000F
    <00016> 000106F6 R WM_IME_SETCONTEXT
    <00017> 000106F6 S WM_IME_SETCONTEXT fSet:1 iShow:C000000F
    <00018> 000106F6 R WM_IME_SETCONTEXT
    <00019> 000106F6 S WM_GETOBJECT dwFlags:FFFFFFFF dwObjId:FFFFFFFC
    <00020> 000106F6 R WM_GETOBJECT dwRet:FFFFFFFF
    <00021> 000106F6 S WM_GETOBJECT dwFlags:00000000 dwObjId:FFFFFFF4
    <00022> 000106F6 R WM_GETOBJECT dwRet:00000000
    <00023> 000106F6 S WM_SETFOCUS hwndLoseFocus:000106F6
    <00024> 000106F6 R WM_SETFOCUS
    <00025> 000106F6 P WM_PAINT hdc:00000000
    <00026> 000106F6 S WM_ERASEBKGND hdc:14011062
    <00027> 000106F6 R WM_ERASEBKGND fErased:True
    <00028> 000106F6 S WM_NCHITTEST xPos:766 yPos:325
    <00029> 000106F6 R WM_NCHITTEST nHittest:HTCLIENT
    <00030> 000106F6 S WM_NCHITTEST xPos:766 yPos:325
    <00031> 000106F6 R WM_NCHITTEST nHittest:HTCLIENT
    <00032> 000106F6 S WM_SETCURSOR hwnd:000106F6 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
    <00033> 000106F6 R WM_SETCURSOR fHaltProcessing:False
    <00034> 000106F6 P WM_MOUSEMOVE fwKeys:0000 xPos:115 yPos:224
    <00035> 000106F6 P WM_TIMER wTimerID:104 tmprc:00000000

    Messages in WordPad when successfully dragging text from the UWP app:

    <00065> 00060978 S WM_NCACTIVATE fActive:True
    <00066> 00060978 R WM_NCACTIVATE
    <00067> 00060978 S WM_ACTIVATE fActive:WA_ACTIVE fMinimized:False hwndPrevious:(null)
    <00068> 00060978 S WM_NCACTIVATE fActive:False
    <00069> 00060978 R WM_NCACTIVATE fDeactivateOK:True
    <00070> 00060978 S WM_ACTIVATE fActive:WA_INACTIVE fMinimized:False hwndPrevious:000D0780
    <00071> 00060978 R WM_ACTIVATE
    <00072> 00060978 S WM_IME_SETCONTEXT fSet:1 iShow:C000000F
    <00073> 00060978 R WM_IME_SETCONTEXT
    <00074> 00060978 S WM_GETOBJECT dwFlags:FFFFFFFF dwObjId:FFFFFFFC
    <00075> 00060978 R WM_GETOBJECT dwRet:FFFFFFFF
    <00076> 00060978 S EM_GETPASSWORDCHAR
    <00077> 00060978 R EM_GETPASSWORDCHAR ch:0 (no password character)
    <00078> 00060978 S WM_SETFOCUS hwndLoseFocus:000D0780
    <00079> 00060978 R WM_SETFOCUS
    <00080> 00060978 S WM_KILLFOCUS hwndGetFocus:00060978
    <00081> 00060978 R WM_KILLFOCUS
    <00082> 00060978 S WM_IME_SETCONTEXT fSet:0 iShow:C000000F
    <00083> 00060978 R WM_IME_SETCONTEXT
    <00084> 00060978 S WM_IME_SETCONTEXT fSet:1 iShow:C000000F
    <00085> 00060978 R WM_IME_SETCONTEXT
    <00086> 00060978 S WM_GETOBJECT dwFlags:FFFFFFFF dwObjId:FFFFFFFC
    <00087> 00060978 R WM_GETOBJECT dwRet:FFFFFFFF
    <00088> 00060978 S EM_GETPASSWORDCHAR
    <00089> 00060978 R EM_GETPASSWORDCHAR ch:0 (no password character)
    <00090> 00060978 S WM_SETFOCUS hwndLoseFocus:00060978
    <00091> 00060978 R WM_SETFOCUS
    <00092> 00060978 R WM_ACTIVATE
    <00093> 00060978 P WM_PAINT hdc:00000000
    <00094> 00060978 S EM_GETZOOM
    <00095> 00060978 R EM_GETZOOM fSucceeded:True nNumerator:45296 nDenominator:45288
    <00096> 00060978 P WM_COMMAND wNotifyCode:0 (sent from a menu) wID:59398

    I also used a DataProvider method instead of setting the text immediately, but also without success:

    args.Data.SetDataProvider(StandardDataFormats.Text, TextProvider);
    
    private void TextProvider(DataProviderRequest request)
    {
    	DataProviderDeferral	def = request.GetDeferral();
    
    	request.SetData("Hello!");
    	def.Complete();
    }

    Best Regards,
    Heiko

    Tuesday, November 12, 2019 12:08 PM
  • Hi,

    The key problem should be that how the EditPlus handles the drop action. I suspect the EditPlus doesn't handle the drop action correctly when the data source comes from UWP apps. You could just contact the developer of EditPlus to check if they had tested drag and drop with UWP apps.

    By the way, We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A (Preview)!

    Best regards,

    Roy


    "Developing Universal Windows apps" forum will be migrating to a new home on Microsoft Q&A (Preview)!
    We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A (Preview)!
    For more information, please refer to the sticky post.


    Wednesday, November 13, 2019 9:20 AM
    Moderator