|
raed wrote:
is it possible to add Drag/Drop functionallity to Toolbar buttons.
In short, yes.
You'll need to look up TBN_DRAGOUT notification message.
Cut-and-pasted-and-in-need-of-adapting-for-your-requirements code:
(This does have dependencies on other stuff, which is why its never been an article!)
class CImcToolBar : public CToolBar, public CImcMenuDropTarget
{
public:
CImcToolBar (int nToolResourceID);
protected:
DECLARE_MESSAGE_MAP();
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnDestroy( );
afx_msg void OnBeginDragging ( NMHDR * pNotifyStruct, LRESULT* result );
virtual BOOL AcceptsMenuDrag (DRAGMENUITEM *dmi);
virtual CPoint ConstrainDragCoords (CPoint pt);
virtual DROPEFFECT MenuDragDropped (CPoint pt, DRAGMENUITEM *dmi);
int m_nToolResourceID;
};
BEGIN_MESSAGE_MAP(CImcToolBar, CToolBar)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_NOTIFY_REFLECT( TBN_DRAGOUT, OnBeginDragging )
END_MESSAGE_MAP()
CImcToolBar::CImcToolBar (int nToolResourceID)
{
m_nToolResourceID = nToolResourceID;
m_deDrag = DROPEFFECT_NONE;
}
int CImcToolBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CToolBar::OnCreate(lpCreateStruct) == -1)
return -1;
RegisterMenuDragDrop (this, IDB_DRAGTOTOOLBAR, RGB(255,0,255));
return 0;
}
void CImcToolBar::OnDestroy ()
{
RevokeDragDrop (m_hWnd);
}
void CImcToolBar::OnBeginDragging ( NMHDR * pNotifyStruct, LRESULT* result )
{
NMTOOLBARA *nm = (NMTOOLBAR *) pNotifyStruct;
CFrameWnd *pFrame = GetDockingFrame ();
ASSERT(pFrame);
if (!pFrame)
return;
DRAGMENUITEM dmi;
dmi.nID = dmi.ItemInfo.wID = nm->iItem;
dmi.nToolbarID = GetDlgCtrlID ();
UINT nFormat = RegisterClipboardFormat (TEXT("ImcMenuDragData"));
ASSERT(nFormat);
if (!nFormat)
return;
TBBUTTONINFO btnInfo;
memset (&btnInfo, 0, sizeof (btnInfo));
btnInfo.cbSize = sizeof (btnInfo);
btnInfo.dwMask = 0;
int nItem = SendMessage (TB_GETBUTTONINFO, nm->iItem, (LPARAM)&btnInfo);
ASSERT(nItem >= 0);
if (nItem < 0)
return;
TBBUTTON btnOld;
if (!SendMessage (TB_GETBUTTON, nItem, (LPARAM)&btnOld))
return;
if (!SendMessage (TB_DELETEBUTTON, nItem))
return;
pFrame->RecalcLayout ();
pFrame->UpdateWindow ();
HANDLE hData = ::GlobalAlloc (GMEM_MOVEABLE | GMEM_SHARE, sizeof (DRAGMENUITEM));
char *buf = (char*) ::GlobalLock (hData);
memcpy (buf, &dmi, sizeof (DRAGMENUITEM));
::GlobalUnlock (hData);
COleDataSource ods;
CImcDropSource ids;
ods.CacheGlobalData (nFormat, hData);
DROPEFFECT de = ods.DoDragDrop (DROPEFFECT_COPY | DROPEFFECT_MOVE, NULL, &ids);
GlobalFree (hData);
if (de == DROPEFFECT_NONE)
SendMessage (TB_INSERTBUTTON, nItem, (LPARAM)&btnOld);
pFrame->RecalcLayout ();
}
BOOL CImcToolBar::AcceptsMenuDrag (DRAGMENUITEM *dmi)
{
return dmi && !dmi->ItemInfo.hSubMenu;
}
CPoint CImcToolBar::ConstrainDragCoords (CPoint pt)
{
CRect rcClient;
GetClientRect (&rcClient);
pt.y = m_rcDragImage.Height () / 2;
CRect rcItem (-1,-1,-1,-1);
for (int nItem = 0; ;nItem++ )
{
if (!SendMessage (TB_GETITEMRECT, nItem, (LPARAM)&rcItem))
break;
if (rcItem.PtInRect (pt))
break;
}
if (pt.x < rcItem.CenterPoint ().x)
pt.x = rcItem.left;
else
pt.x = rcItem.right;
pt.y = rcItem.CenterPoint ().y;
return pt;
}
DROPEFFECT CImcToolBar::MenuDragDropped (CPoint pt, DRAGMENUITEM *dmi)
{
TBBUTTONARRAY btnArray;
int nButtons = dmi->CreateDroppedButtonArray (btnArray, m_nToolResourceID);
if (!btnArray.GetSize ())
return DROPEFFECT_NONE;
int nItem, nItemMax = SendMessage (TB_BUTTONCOUNT);
CRect rcItem (-1,-1,-1,-1);
for (nItem = 0; ;nItem++ )
{
if (!SendMessage (TB_GETITEMRECT, nItem, (LPARAM)&rcItem))
break;
if (rcItem.PtInRect (pt))
break;
}
BOOL bBefore = pt.x < rcItem.CenterPoint ().x;
if (!bBefore && (nItem != nItemMax))
{
bBefore = TRUE;
nItem++;
}
while (btnArray.GetSize ())
{
if (bBefore)
SendMessage (TB_INSERTBUTTON, nItem++, (LPARAM) btnArray.GetData ());
else
SendMessage (TB_ADDBUTTONS, 1, (LPARAM) btnArray.GetData ());
btnArray.RemoveAt (0);
}
CFrameWnd *pFrame = GetDockingFrame ();
if (pFrame)
pFrame->RecalcLayout ();
return (dmi->nToolbarID == GetDlgCtrlID ()) ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
}
|
|
|
|
|
Thanks ,valuable code.
is it possible to Derived a class From CToolBar and then handling Mouse Event on toolbar after getting its ID or something like that, to add this functionality.
Thanks
|
|
|
|
|
Yes, its possible. Its probably not a good idea though. Users expect standard behaviour from things
that look standard. If you start making it behave in a non-standard way, users will think the soft-
ware is broken. Even if its better!
You can also use message reflection to get NM_RCLICK from the toolbar.
Let it do the work for you!
raed wrote:
Thanks ,valuable code.
Just remember you owe me a drink!
Iain.
|
|
|
|
|
English ability is short and I do not express properly.
We will express therefore in a task sequence which I want.
1, My program execution.
2, The mouse anywhere moves windows.
3, Is there the character in the place which the mouse moves?
4, The transmit to that character my program if has the character.
We try to make almost the program to have such skill.
Which does the utility become API function at?
|
|
|
|
|
2. You may need to hook the mouse
(Check SetWindowsHook and SetWindowsHookEx for that)
3. Having a position you can call GetWindowTextLength and or GetWindowText
4. Consider using Memory mapped files and SendMessage
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
The reply thanks.
This the thing which the answer which I want is not but.
I want to get any all character.
I want to get the character in all windows.
Ex: The content of the document.
The caption of the Component.
Actual character wants to get all except the character to become to the image.
|
|
|
|
|
Then i would suggest
EnumWindows
then on each window
EnumChildWindows
Then on each one GetWindowText
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
The reply thinks really thankfully.
We will try once in the method to inform.
Is the julsu makes probably an example file and there?
A num sense of honor is same being the request not to exist.
^^;
thinks
|
|
|
|
|
i understood till inform
but nothing after that
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
There's no API I'm aware of that does this job.
One difficult solution would be to use OCR.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
We have the facility already at a dictionary program which I use.
This program is same the mode of OCR not being.
Does API bet really that we do not exist?
|
|
|
|
|
If the window under the mouse is an edit or richedit window you can use EM_CHARFROMPOS.
For all other windows you will have to do a 'screen scrape' or use custom code to do the appropriate HITTEST testing.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
I have a Message-Window that goes with the System-Tray.
Upon a click on the tray-icon a menu is popped.
According to MSDN, I should call:
<br />
SetForegroundWindow();<br />
<br />
TrackPopupMenu();<br />
<br />
PostMessage(WM_NULL);<br />
so that the menu doesn't stay there until a selection is made on it.
In response to a certain menu-selection I show a dialog. This dialog is Modal and has no parent.
When I call SetForegroundWindow() the dialog will not show, if I don't call SetForegroundWindow() the dialog will show.
My window (the one receiving the message from the tray and performing the abovementioned logic) is a pure message-window (child of HWND_MESSAGE).
Can someone explain the situation ?
|
|
|
|
|
I've been using some memory leak detection software to solve my ever growing memory usage problem. The following has turned up, can someone help me understand why my first function call results in a leak, but the second doesn't. Or is this a bogus memory leak detection?
The function is
void Foo(BSTR sInput1, BSTR sInput2)
{
// do nothing with the inputs
}
This call results in a leak...
Foo((bstr_t)_T("Blah"), (bstr_t)_T("Blah"));
but this is OK...
Foo((BSTR)_T("Blah"), (BSTR)_T("Blah"));
If this will solve all my problems I am happy to use the second calling method, but I'm a bit sceptical... Any comments?
PS: I use Unicode and acsii builds
|
|
|
|
|
I think it's bogus.
What does it say if you explicitly contruct bstr_t's iso casting?
Foo( bstr_t(_T("Blah")), bstr_t(_T("Blah")));
if it still complains, what does it say about
{<br />
bstr_t a(_T("Blah")), b(_T("Blah"));<br />
Foo(a, b);<br />
}
This small snippet that mimics BSTR and bstr_t should convince you that there shouldnt be any leaks if bstr_t is implemented as the dox say.
#include < iostream >
using namespace std;
struct a
{
a(){
cout << "a()" << endl;
s_=0; }
a(const char*s){
cout << "a(const char*i)" << endl;
s_ =(char*) malloc(strlen(s)+1);
strcpy(s_, s); }
const a& operator= (const a& rhs){
cout << "operator =" << endl;
return *this; }
~a(){
cout << "~a()" << endl;
free(s_); }
operator char* () {return s_;}
private:
char* s_;
};
typedef char MYCHAR;
typedef MYCHAR* MYCHARPTR;
void func (MYCHARPTR n, MYCHARPTR m)
{
cout << n << " " << m << endl;
}
int main( void )
{
func( (MYCHARPTR)"Test cast", (MYCHARPTR)"from const char* to BSTR");
func( (a)"Test cast", (a)"from const char* to BSTR wrapper class");
func( a("Test constructing"), a("from const char* to BSTR wrapper class"));
return 0;
}
---
"Man will never be free until the last king is strangled with the entrails of the last priest". -- Denis Diderot
|
|
|
|
|
why RTC Sample can't sharing application, and sharing white board when login Live Communication Server.
somebody can help me?
Thanks
Nho'c Ti`
|
|
|
|
|
How can i send send or recv data to USB port
any sample
thanx
|
|
|
|
|
You don't send data to the port really, you send it to a device attached to the port via the device driver.
The tigress is here
|
|
|
|
|
'USB Complete' book by Jan Axelson, ISBN# 0-9650819-5-8.
http://computer.howstuffworks.com/usb.htm
http://www.lvr.com/usb.htm
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Hi,
Can anyone help me to get few website links for "Telnet architecture"
what all neeed to explain in this case..Pls help.
thnks in advance
Ram
|
|
|
|
|
A google search gave me a lot of links:
Try looking at the Telnet RFC Specification[^]
And other Telnet RFC's[^]
"It was when I found out I could make mistakes that I knew I was on to something."
-Ornette Coleman
"Philosophy is a study that lets us be unhappy more intelligently."
-Anon.
|
|
|
|
|
Hello All!
I Have video card with S-video output, when I try show my video player on TV in fullscreen (only) mode, I see only black square.
Please, anybody know how can I correct that problem?
Please send me letter to:
manowar@softdepia.com or
Alex_ManOwaR@newmail.ru
With best regards,
Alex ManOwaR
P.S.
Sorry for my english.
|
|
|
|
|
Hi.
I have added my program as service in Windows 2000. When i minimise the program, it is added in the tray-bar. This works great in Windows 2000. Even when i end the 'Explorer.exe' process i handle the "TaskbarCreated" message and add the icon again in the tray bar.
This does not work for Windows NT though. When explorer.exe is ended, the icon isn't added again in the tray bar. What could be the reason of this OS-depending problem?
<just edited="">
I have ran Spy.exe on the program.. when minimised and process 'Explorer.exe' killed and restarted, it does get a 'TaskbarCreated' message from a Windows 2000 computer. I have done the same on a Windows NT computer and it doesn't get the 'TaskbarCreated' message at all !!
<\Just edited>
Any questions about the problem, don't hesistate to ask them.
Thanks for the help.
Greetings,
Jens
|
|
|
|
|
To quote from MSDN:
With Microsoft® Internet Explorer 4.0 and later, the Shell notifies applications that the taskbar has been created...
I would bet that your NT machine has IE 3.x installed.
Iain.
|
|
|
|
|
Not correct. Internet Explorer 6.0 installed.
I have seen that a specific version of the system file 'shell32.dll' is needed (>= version '4.70') and i don't seem to be able to update that file to such version. I have version 4.0 of shell32.dll which in my opinion is a part of the shell and doesn't notify application when taskbar has been created.
Greetings,
Jens
|
|
|
|