PC Review


Reply
Thread Tools Rate Thread

Covering Startbar with a floating window, Topmost of all Topmost, andoverriding WndProc - C#

 
 
jhow
Guest
Posts: n/a
 
      17th Jun 2009
I'm writing a dictionary application in C#, similar to Trancreative's
Word Book.

Most of these dictionary apps have a concept of a "Word Picker", which
is a small floating window that stays Topmost even when other
applications are in the foreground. The idea is that, if you are using
a web browser for example, you simply highlight a word in the browser,
click on the Word Picker window, and it will automatically search for
this word for you in your dictionary application.

I have three problems with this:

1) I would like my Word Picker window to be able to cover the Start
Bar. This works ok with the correct Form properties set, but when the
user changes the foreground app, the Start Bar appears to refresh, and
sets itself to Topmost, thus covering my Word Picker. How can I avoid
this happening?

2) This problem is related to the first problem. How do I make my Word
Picker the Topmost of all Topmost windows even if it is deactivated.
Is it possible to always claim this No. 1 spot in the Z-order,
regardless of other applications that might want to bump me off the
top?

3) In order to "pick" the word off for example, the web browser, I
want to:
a) intercept the activate message my Picker Window receives when
it is clicked
b) examine the message to determine the last activated window
c) send this last activated window a WM_COPY message to determine
which word the user has just highlighted.

The problem here is that WndProc can't be overridden in the CF. I've
read up on the MessageWindow but figured out I can't use this to
capture my Word Picker Messages. The alternative is a several hundred
lines of code from the MS CF team blog, but I don't have the time and
energy to implement this. It also seems like an awfully long work
around for a very simple problem.

Can someone suggest a simpler way of doing this?

Thanks in advance.
 
Reply With Quote
 
 
 
 
Mark Erikson
Guest
Posts: n/a
 
      17th Jun 2009
On Jun 17, 5:58*am, jhow <jhowar...@hotmail.com> wrote:
> I'm writing a dictionary application in C#, similar to Trancreative's
> Word Book.
>
> Most of these dictionary apps have a concept of a "Word Picker", which
> is a small floating window that stays Topmost even when other
> applications are in the foreground. The idea is that, if you are using
> a web browser for example, you simply highlight a word in the browser,
> click on the Word Picker window, and it will automatically search for
> this word for you in your dictionary application.
>
> I have three problems with this:
>
> 1) I would like my Word Picker window to be able to cover the Start
> Bar. This works ok with the correct Form properties set, but when the
> user changes the foreground app, the Start Bar appears to refresh, and
> sets itself to Topmost, thus covering my Word Picker. How can I avoid
> this happening?
>
> 2) This problem is related to the first problem. How do I make my Word
> Picker the Topmost of all Topmost windows even if it is deactivated.
> Is it possible to always claim this No. 1 spot in the Z-order,
> regardless of other applications that might want to bump me off the
> top?
>
> 3) In order to "pick" the word off for example, the web browser, I
> want to:
> * * a) intercept the activate message my Picker Window receives when
> it is clicked
> * * b) examine the message to determine the last activated window
> * * c) send this last activated window a WM_COPY message to determine
> which word the user has just highlighted.
>
> The problem here is that WndProc can't be overridden in the CF. I've
> read up on the MessageWindow but figured out I can't use this to
> capture my Word Picker Messages. The alternative is a several hundred
> lines of code from the MS CF team blog, but I don't have the time and
> energy to implement this. It also seems like an awfully long work
> around for a very simple problem.
>
> Can someone suggest a simpler way of doing this?
>
> Thanks in advance.


Don't know enough to help with the first two questions, but I can
address #3. I assume you're referring to the "Subclassing controls in
CF 2.0" post at http://blogs.msdn.com/netcfteam/arch...20/420551.aspx
.. Yes, the code in that post is somewhat longwinded, but it does
provide a complete solution to hooking a WndProc in the CF. The key
is the line "oldWndProc = Win32.SetWindowLong(hwnd, Win32.GWL_WNDPROC,
Marshal.GetFunctionPointerForDelegate(newWndProc));" Marshal.GFPFD()
gives you an IntPtr that serves as a handle to a .NET function, which
can then be passed to native code.

Unfortunately, anything dealing with Win32 programming (and WndProcs
in particular) is going to be somewhat long and tedious. However, the
code provided by the CF team shouldn't need any modifications. All
you should have to do is paste the code into your project, create a
function that matches the WndProcCallback delegate, and call
HookWndProc().

Hope that helps!

Mark Erikson
http://www.isquaredsoftware.com
 
Reply With Quote
 
jhow
Guest
Posts: n/a
 
      18th Jun 2009
Thanks for your suggestion Mark, I'll give it a go.

I would still appreciate feedback on my first two problems too, if
anyone out there knows the solution.

Thanks
 
Reply With Quote
 
Lcubed
Guest
Posts: n/a
 
      18th Jun 2009
To hide the start bar, make sure your form is maximized and the form's
clientsize is set to the full size of the screen.

Setting your form to TopMost = true; will bring it to the top, but you
have to get creative to keep it there.

To hide the start bar and SIP, here's the C++ code to do it, but you
will need to p/invoke these commands to make them work in C#. www.pinvoke.net
can help you our with that.

AFX_MANAGE_STATE(AfxGetStaticModuleState());
HWND hWnd = ::FindWindow( _T( "HHTaskBar" ), NULL );
::ShowWindow( hWnd, SW_HIDE ); // hide taskbar - use SW_RESTORE to
put it back
::EnableWindow(hWnd,false); // disable taskbar

On Jun 17, 10:35*pm, jhow <jhowar...@hotmail.com> wrote:
> Thanks for your suggestion Mark, I'll give it a go.
>
> I would still appreciate feedback on my first two problems too, if
> anyone out there knows the solution.
>
> Thanks


 
Reply With Quote
 
jhow
Guest
Posts: n/a
 
      19th Jun 2009
Thanks Lcubed, but I'm not looking to hide the Start bar completely.
What I want to do is have a small floating window, roughly 10x10
pixels in size, which I can move anywhere on the entire screen area,
including over the Start bar, and never have it covered.

I'm thinking now of implementing a timer, to reset its topmost
behaviour every certain interval, but I know this will chew CPU and
also cause the window to flash. But at the moment I can't think of
another way of doing this.

On Jun 19, 3:13*am, Lcubed <Loris.Email...@gmail.com> wrote:
> To hide the start bar, make sure your form is maximized and the form's
> clientsize is set to the full size of the screen.
>
> Setting your form to TopMost = true; will bring it to the top, but you
> have to get creative to keep it there.
>
> To hide the start bar and SIP, here's the C++ code to do it, but you
> will need to p/invoke these commands to make them work in C#.www.pinvoke.net
> can help you our with that.
>
> * * AFX_MANAGE_STATE(AfxGetStaticModuleState());
> * * HWND hWnd = ::FindWindow( _T( "HHTaskBar" ), NULL *);
> * * ::ShowWindow( hWnd, SW_HIDE ); // hide taskbar - use SW_RESTORE to
> put it back
> * * ::EnableWindow(hWnd,false); // disable taskbar


 
Reply With Quote
 
jhow
Guest
Posts: n/a
 
      8th Aug 2009
I've thought of another way of being able to always be on top of the
startbar.

That is, to make my picker window a child of the start bar. In that
way, because the child will never be shown behind the parent, my
problem will be solved.

However, how do I get the startbar as a parent/owner form in my
application?

I can get the window handle of the startbar by following Lcubed's code
above. But how can I covert this handle to a form and set it to be the
owner of my picker form?

For a desktop application I believe Control.FromHandle would be the
solution, but unfortunately this is not implemented in the .NetCF.

Any workarounds or other suggestions?
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Topmost form loses the topmost status when VS2005 is run Andrea Microsoft Dot NET Framework Forms 0 26th Feb 2007 07:40 AM
Cursor automatically selects topmost window =?Utf-8?B?Z20=?= Windows XP General 2 29th Jan 2006 08:31 PM
Topmost Tool Window =?Utf-8?B?S2V2aW4gQ29jaHJhbg==?= Microsoft Dot NET Framework Forms 2 17th Jul 2005 06:20 AM
Topmost window get stuck there Nick Payne Windows XP Performance 0 28th Feb 2004 12:19 AM
OnKillFocus, not working with topmost window Sims Microsoft Dot NET 2 29th Jan 2004 01:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:45 AM.