Home » U++ Library support » Archive » drag & drop
drag & drop [message #650] |
Mon, 23 January 2006 20:58  |
hojtsy
Messages: 241 Registered: January 2006 Location: Budapest, Hungary
|
Experienced Member |
|
|
Is it possible to accept files/links/text drag & dropped from an other application? It seems that I can not even drag&drop text from one text input into an other one inside the same app. If these are not yet possible, could we add them to the wishlist?
Thanks
|
|
|
|
Re: drag & drop [message #8119 is a reply to message #651] |
Sun, 11 February 2007 00:46   |
mobilehunter
Messages: 87 Registered: November 2006
|
Member |
|
|
just testing with codes pieces from TCtrllib directrory.
drag qtf file and the richeditor will open it.
#include <CtrlLib/CtrlLib.h>
#include <RichEdit/RichEdit.h>
#include <shellapi.h>
using namespace Upp;
#define LAYOUTFILE "MainLay.lay"
#include <CtrlCore/lay.h>
/*
DragAcceptFiles
DragFinish
DragQueryFile
DragQueryPoint
*/
class TestDragDrop : public WithMainGUI<TopWindow>
{
public:
TestDragDrop();
~TestDragDrop();
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
private:
void showDroppedFiles(HDROP dropInfo);
private:
RichEdit editor;
typedef TestDragDrop CLASSNAME;
};
TestDragDrop::TestDragDrop()
{
Add(editor.SizePos());
editor.SetFocus();
Open();
HWND hwnd = GetHWND();
DragAcceptFiles(hwnd,true);
}
TestDragDrop::~TestDragDrop()
{
}
void TestDragDrop::showDroppedFiles(HDROP hdrop)
{
//get how many are dropped
int count = DragQueryFile((HDROP)hdrop, (DWORD)-1, 0, 0);
Vector<String> list;
for(int i = 0; i < count; i++) {
//get length of files name
int length = DragQueryFile((HDROP)hdrop, i, 0, 0);
String s;
DragQueryFile((HDROP)hdrop, i, s.GetBuffer(length), length + 1);
s.ReleaseBuffer(length);
//Taken from UWord codes
editor.SetQTF(LoadFile(s));
editor.ClearModify();
}
DragFinish((HDROP)hdrop);
}
LRESULT TestDragDrop::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
HWND hwnd = GetHWND();
switch(message)
{
case WM_DROPFILES:
{
showDroppedFiles((HDROP)wParam);
return 0;
}
default:
return TopWindow::WindowProc(message, wParam, lParam);
}
return true;
}
GUI_APP_MAIN
{
TestDragDrop test;
test.Run();
}
|
|
|
Re: drag & drop [message #8122 is a reply to message #8119] |
Sun, 11 February 2007 09:47   |
 |
mirek
Messages: 14255 Registered: November 2005
|
Ultimate Member |
|
|
Thanks. Really not that complicated, is it? (What IS complicated is to support all variants, including OLE D&D, in-application D&D, X11 D&D etc....)
BTW, according to "U++ programming paradigm", I do not quite like this part:
mobilehunter wrote on Sat, 10 February 2007 18:46 | just testing with codes pieces from TCtrllib directrory.
drag qtf file and the richeditor will open it.
TestDragDrop::TestDragDrop()
{
Add(editor.SizePos());
editor.SetFocus();
Open();
HWND hwnd = GetHWND();
DragAcceptFiles(hwnd,true);
}
|
Opening dialog in constructor is "bad practice" (of course, it works as expected and in experimental code it is OK).
Anyway, notice quite useful methods in Ctrl::
virtual void NcCreate(HWND hwnd);
virtual void NcDestroy();
virtual void PreDestroy();
Mirek
|
|
|
Re: drag & drop [message #8138 is a reply to message #8122] |
Mon, 12 February 2007 07:12  |
mobilehunter
Messages: 87 Registered: November 2006
|
Member |
|
|
I removed the Open and the rest from constructor.
And add this codes.
So i have to put codes that need immediate access to hwnd inside NcCreate, right?
void TestDragDrop::NcCreate(HWND hwnd)
{
Ctrl::NcCreate(hwnd);
DragAcceptFiles(hwnd,true);
}
Thanks for the correction.
|
|
|
Goto Forum:
Current Time: Fri Apr 25 11:56:42 CEST 2025
Total time taken to generate the page: 0.03228 seconds
|