How to change the cursor to hand when enter to a window?

908 views
Skip to first unread message

He HongFu

unread,
Jun 6, 2005, 12:40:33 AM6/6/05
to wx-users
Hi,

I would like the cursor to change to a hand when the mouse is over a
window. But the window always be arrow cursor.

Here is the code segment:

EVT_MOTION (ListMenu::onMouseMotion)

ListMenu::onMouseMotion (wxEvent& event) {
if (HitTest (event.GetPosition(), _expandBtnRect) == false) {
::wxSetCursor (wxCursor (wxCURSOR_ARROW));
return;
}

::wxSetCursor (wxCursor (wxCURSOR_HAND));
}

Thanks in advance.

        He HongFu
        h...@eisoo.com
          2005-06-06

He HongFu

unread,
Jun 6, 2005, 4:53:00 AM6/6/05
to wx-u...@lists.wxwidgets.org
Hi, Ryan,

I have tried wxWindow::SetCursor. But still not get the correct result.

Best Regards!
        He HongFu
        h...@eisoo.com
          2005-06-06

======= Original Message on 2005-06-06 13:11:54 =======

>Use wxWindow::SetCursor
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: wx-users-u...@lists.wxwidgets.org
>For additional commands, e-mail: wx-use...@lists.wxwidgets.org
>
>

= = = = = = = = = = = = = = = = = = = =


VEGH, Janos

unread,
Jun 6, 2005, 7:37:30 AM6/6/05
to wx-u...@lists.wxwidgets.org

On Mon, 06 Jun 2005 07:24:05 -0300, "João Paulo Just"
<j...@justsoft.com.br> said:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1

>
> He HongFu wrote:
> | Hi, Ryan,
> |
> | I have tried wxWindow::SetCursor. But still not get the correct result.
> |
> | Best Regards!
>
> You don't need all that code you wrote. Just do:
>
> ::wxSetCursor (wxCursor (wxCURSOR_HAND));
>
> in the window's constructor. And, by the way, you used wxCURSOR_ARROW :P
>
Or, maybe you want a more dynamic behavior, like this

/** Called when the mouse enters the view
*/
void MyView::OnMouseEnter(wxMouseEvent& WXUNUSED(event))
{ if(TheCanvas)
TheCanvas->SetCursor(*wxCROSS_CURSOR);
}

/** Called when the mouse exits the view
*/
void MyView::OnMouseExit(wxMouseEvent& WXUNUSED(event))
{
if(TheCanvas)
TheCanvas->SetCursor(*wxSTANDARD_CURSOR);
}

Janos

He HongFu

unread,
Jun 7, 2005, 7:34:48 AM6/7/05
to wx-u...@lists.wxwidgets.org
Hi, Paulo,

Thanks very much. We have solved this problem. Because we forget add wx.rc into our resource script.

Best Regards!
        He HongFu
        h...@eisoo.com
          2005-06-07

======= Original Message on 2005-06-07 01:11:03 =======

>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>yy_cn wrote:
>| Hi, Jo?o,
>|
>| I write some code by your instruction, and the debug window output the
>following log:
>|
>| 20:01:52:
>\Work\Source\library\wxWidgets-2.6.0\src\msw\cursor.cpp(356):
>'LoadCursor' failed with error 0x00000714 (the specified image file did
>not contain a resource section.).
>|
>| When I step into the wxCursor constructor, I found the log was
>generated by the following code:
>| const StdCursor& stdCursor = stdCursors[idCursor];
>| HCURSOR hcursor = ::LoadCursor(stdCursor.isStd ? NULL : wxGetInstance(),
>| stdCursor.name);
>|
>| Why the stdCursor.isStd equal to false? I think wxCURSOR_HAND should
>be a system standard cursor. How should I do?
>|
>| The version of wxWidgets we used is 2.6.
>
>I really don't know why this error occured (maybe there is something
>missing in your code). But, I wrote a small code below which creates a
>frame and sets its cursor, so you can see how I use the SetCursor method:
>
>#include <wx/wx.h>
>
>class MyApp: public wxApp
>{
> virtual bool OnInit();
>};
>
>class MyFrame: public wxFrame
>{
>public:
> MyFrame(void);
>};
>
>IMPLEMENT_APP(MyApp)
>
>bool MyApp::OnInit(void)
>{
> MyFrame *frame = new MyFrame();
> frame->Show(true);
> SetTopWindow(frame);
> return true;
>}
>
>MyFrame::MyFrame(void)
> :wxFrame((wxFrame *)NULL, -1, "Hand Test")
>{
> SetCursor(wxCursor(wxCURSOR_HAND));
>}
>
>
>
>- --
>João Paulo Just Peixoto
>Justsoft Informática e Publicidade Ltda.
>http://www.justsoft.com.br/
>- --
>Linux User #329704
>http://counter.li.org/
>- --
>Graduando em Ciência da Computação
>Universidade Estadual de Santa Cruz, BA
>- --
>Ilhéus, BA, Brasil
>+55 75 8104 8473
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.2.7 (GNU/Linux)
>Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
>
>iD8DBQFCpIOnXL+vuN2d7ZwRArsWAKCr5Y6hjyuQr0i/FcP4/spHUF+apwCgqSZC
>M3zg8ycymbhIf3RO/EIX5Zg=
>=ST7b
>-----END PGP SIGNATURE-----
Reply all
Reply to author
Forward
0 new messages