C# help needed - trap hard button presses when other apps have focus - Windows Mobile Development and Hacking General

Hi, I'm hoping some folks out there might be willing to help out a CF.NET newbie. I'm starting out with VS 2005 / C# and want to create an application, along the lines of SPB's virtual keyboard, that runs in "the background" and does the following:
1) Is automatically started upon a soft reset, but runs silently in the background.
2) Intercepts a hard button press when other apps have the focus (it will be using this button press as a trigger to display my app in the forefront).
3) Before it launches, it needs to check to see if the app that currently has the focus has focus on a text box (i.e., a blinking cursor). I only want to launch my app if that's the case.
4) Before I launch my app, I want to copy the contents of that other app's text box.
5) My app will have a multi-line text box and when the user exits out of my app, I want to paste the text from that text box back into the text box of the app that previously had the focus.
Any pointers anyone can provide regarding any/all of the above would be greatly appreciated. Thanks,
Scott

Related

Messaging; missing body, list of msgs

Hi All,
I've tried various search strings looking for an answer to my issue but found nothing related. Anyone else have an intermittent problem whereby pressing softkey for "Messaging" yields no body or list, only a title bar and softkey menu as normal? When it occurs, I just see the Today Screen where either the message contents or list of messages should be displayed. After some fumbling and clicking around I can usually get the content/list to appear. I only noticed this problem when I first loaded summiter's ROM but now I have the official Cingular ROM loaded and problem still exists.
Thanks in advance for any thoughts or solutions.
can you access the messaging if you go through the start menu or do you have the same problem there??
is your soft key mapped right to the messaging link?
softkey mapped
Thanks for response, yes, softkey is mapped; as I mentioned earlier, when you launch messaging, I get only the top and bottom elements of the program (Title, New, Menu) but the middle content (message, list of) is missing)--you see only the Today Screen in foreground.
It happened to me as well once I started to force 'exit' on all the apps instead of just minimizing them. Part of Pocket Plus close button.
I'm not sure if this is the same case as you are experiencing but it looks like after the Messaging program is completely terminating, the softkey cannot launch the complete program. I was still able to launch it from the start menu with no problems (sounds very strange, I know).
The way I recovered from that is to put the "Messaging" program in the exception list of the close program; this way it stays in memory and I get the messaging complete program every time I press the softkey now.
I *Hope* that helps...
maybe???
interesting thought... well, i don't use that program BUT i am using smartkey and that likely shares the same process SO i will try that from now on after soft-reset and report back...
Thanks for the tip! It's definitely one of those hard to track down the cause kind of issues, how did you come about that as a solution?

Putting PPC (Harrier & iMate) app on Treo 700wx Issues

Hi,
I have an application which has been running nicely on Harrier and iMate devices, well any PPC devices really because of their rectangular screen shape.
My client has gone and bought some Palm Treo 700wx devices, and they have a smaller square screen.
In the resource of my project the screens are designed to fit PPC. When it runs on the Treo the Treo automatically pops up a scroll bar to allow the whole view to be seen.
The issue is when I first go into the app I can't see the top of the screen, about 20 odd pixels heigh aren't displayed. The scroll bar still displays and I can scroll down to the bottom of the view, and when I scroll up again the top of the screen is still out of sight.
If I exit the app just by tapping on the x in the top right corner (so the app is still running, not exiting properly via my Exit button which shuts down the app), I exit the app and then when I go back into the app the screens are displayed correctly, there is no missing space at the top of the screen.
If I exit the app via my exit button and then start the app again, the top of the view is missing again.
Does anyone know why the screen isn't displayed correctly when I first enter the app, or why it should come right when reloading the view again? Has anyone else had problems with screen layout when putting PPC apps on the square Treo 700wx?
Thanks
It sounds like you have a 'refresh' problem. I haven't encountered this my self and it is really hard to diagnose when you don't even tell us what language your app is written in, but basically here is what I think happens:
When your app is launched, part of its window doesn't get properly painted (not sure why exactly).
When you click the X the app isn't closed, but minimized.
When you return to it the window is maximized and repainted. Second repaint goes correctly.
The quick solution to this would be to force a window refresh just after the app is fully started.
Sorry I forgot to add the language.. it's written in eVC++ 3.0
I'll give the refresh a go, thanks
Further Questions..
I thought that minimising and then maximising the screen fixed the problem, but only partially..
Because the screen in resource is designed for regular PPC it is bigger than the Treo 700 screen size, so the OS automatically shows a scroll bar.
The new issue I'm seeing is to do with the scroll bar. The steps I take to reproduce the issue are:
1. Go to View1, and I scroll down the view (I'm using CView not CDialog)
2. Go to View2
3. Go back to View1. When I go back to the first view the scrollbar is scrolled down in the position I left it.
4. Scroll up to top of view and some of the controls in the wrong place. Some controls I dynamically create in OnInitialUpdate, and as part of the Create() I pass in CRect to tell it where to create the control.
If I set CRect.top to say 10, it's created 10 down from the top of the visible screen. The problem is that because I've scrolled the view previously the view draws it 10 down on the visible portion of the view.
I had thought that the easiest solution would be to always reset the scroll bar to the top of the view before creating my controls, but I'm not sure how to force the OS scroll bar to the top of the view. I've tried SetScrollPos(0,0) or ScrollWindow(0, y). ScrollWindow moves the actual view up or down, but the OS scrollbar is still in the same position.
Any ideas on how to set my view window to the top and to reset the scrollbar?
Thanks again
How to refresh a view?
I have sorted the issue mentioned just above, by finding the scroll position and factoring in that when I set the value of CRect area of the controls I need to dynamically draw.
I'm now just left with the first issue, of when I first start up the app the top part of the window and scrollbar are covered by the Title/Taskbar at the top of the screen.
If I close the app via the x button and restart the app, the issue resolves itself. Or if I open up any dlg like the About screen or even display an AfxMessageBox, when I close the dialog the original screen is redrawn correctly, in the correct position and scroll bar fully shown.
I have tried calling RecalcLayout(), RefreshWindow(), UpdateWindow(), Sending WM_SIZE messages and a whole range of things, but I can't seem to get the screen refreshing correctly apart from when I open any dialog and close that dialog.
When you close a dialog what messages get sent to the previous view that force it to redraw? Does anyone have any suggestions how I can force a refresh myself?
Thanks again
Did you try InvalidateRect?
I am getting a bit rusty with MFC, since I now try to do things the hard way and use pure win 32, but this should work.
If you can't use it as a class member, call the API directly using you view GetSafeHwnd() function for window handle). Use NULL for lpRect to redraw the whole window and FALSE for bErase to prevent flickering.
Note that UpdateWindow() only triggers repaint if part of the window becomes invalid (the contents needs redrawing).
No I hadn't thought of using InvalidateRect(), so I should give it a go.
In the end I just wanted the issue fixed so opted for a quick 'n dirty solution of displaying a temp CDialog as soon as the app starts and calling EndDialog() immediately in the OnInitDialog() so the dialog disappears before you see it.
It worked and the original screen gets updated to correct size, layout and scroll bar.
Cheers.

Misc .NET CF questions

Hello, I'm thinking about switching over from my Palm OS Treo 700p to a Sprint Mogul and would like to develop some apps using .NET. I'm a long-time VB developer (VB3 thru VB6) but a more recent newbie with .NET (focusing on C#). I've also had experience with several Pocket PC / WM devices and dabbled with eVB long ago (hated it). Anyways, I've got some ideas for apps/applets/hacks that I'd like to create for WM devices (and the Mogul specifically), but I'm not sure what's possible with WM6 and .NET, so some questions:
1) Let's say I wanted to create an app that "runs in the background" all the time. I'm fairly certain that I can create an app that gets started after a soft reset but doesn't show any visual signs of being started. I want this app to essentially "listen" for other events. So, if for example, I'm using IE and the user presses a specific hard button, I want my app to trap that before IE notices it. My app might then fire up a window which displays on the screen.
a) Can I do this?
b) Can I trap *any* button (including the Start button, the OK button, and the two "soft menu" buttons?
c) Can I distinguish between a regular button press and a "press and hold"?
2) Can I effectively "replace" some/all of the built-in phone functionality? For example, when a call comes in, instead of the built in phone functionality taking over and showing on-screen an answer/ignore window, could I create an alternative app that had answer/ignore buttons?
3) What are my options for displaying windows on top of other apps?
a) Can I have a small window display on top of other running apps?
b) Can I do something fancy like have my app display a translucent full-screen window on top of a running app?
Thank you for any help you can offer.
Scott
all those things are possible but I think you had better use c++ especially for the phone stuff.
for the button pushes, the problem is that other programs can change it after you start up. Because the user will not see you app they will not know it happened.
There is not a good way to replace the phone answer dialog but you can just stop it and put up your own, you will need to be careful to prevent any uncontrolled ringing or vibrating that can be left when stopping the phone. If you are using c# to know when the phone is rinning you will not catch it fast enough to prevent the phone app rinning before your one.
You can put windows on top of other windows but you will then have to make sure the ok/x is correct. Its very easy to screw up the os smart minimize so that it no longer corresponds to the window the user sees. Maybe it would be better to just subclass the window you want to cover and make it look like you want.

All messages> Back switches apps instead

I noticed a bug that allows you to switch to running apps that were left behind with the home button.
Prerequisites: HTC Messages widget on one of the main screens.
Steps to reproduce:
1. Open an application (like 'people') and exit out with the home button, not the back button.
2. Repeat step one if you want to add other apps.
3. Go to the HTC messages widget and tap it to open a message.
4. Select menu option "All messages".
5. Press the 'back' button. This will switch to another app instead of close the messages.
6. Repeat step 5 to close the app and move to the next one.
Further notes:
Some apps will continue to show up even if you press 'back' on them to exit out.
For example, "People", "System settings" and browser never closes. Camera app does close, but you have to leave it by pressing 'home'.
Works on generic 1.5.
android dosent close apps untill needed lol just hold the home button to open any program you have run recently lol
mancsoulja said:
android dosent close apps untill needed lol just hold the home button to open any program you have run recently lol
Click to expand...
Click to collapse
I didn't know that - it is not mentioned in the manual. Thanks for that useful tip. Looks like a useful shortcut back to where you were before.
But how do you close a programme rather than let it waste memory and battery in the background?
peterc10 said:
I didn't know that - it is not mentioned in the manual. Thanks for that useful tip. Looks like a useful shortcut back to where you were before.
But how do you close a programme rather than let it waste memory and battery in the background?
Click to expand...
Click to collapse
If android needs ram it will close apps as needed but you can always download a task manager from the marketplace, there are some good free ones, i suggest advanced task manager its what i use
It would be good to be able to actually get them to exit properly.
Especially so when you have 4 or 5 "All messages" apps that won't go.
The only use this bug has is to take you to apps that are actually running as opposed to your history.
It also takes you to screens that a task switcher can't do for you, like the last screen you see from your last phone call and the call history.
frankv100 said:
The only use this bug has is to take you to apps that are actually running as opposed to your history.
Click to expand...
Click to collapse
I don't see this as being a bug. The ability to be able to short cut to the 6 (I notice it is limited to 6) previously used apps by a long press on the home button is obviously something the designers have deliberately included. And to me it is a useful additional feature (now I have found it!).
It seems to be history rather than running apps you are looking at - I closed several of my running apps using Astro and yet they still subsequently appeared in the list.

WP 8 and Multitasking

Hello there!
I would like to try it by myself, but unfortunately I cant. So, someone who tried the SDK, have you noticed changes in multitasking system?
Right now the only way to resume an app is using fast app switch. But I really dont like it. I rather just use the homescreen icon instead. Right now it relaunch the app.
Any changes on that? (oh please)
Thank you so much!
mikeeam said:
Hello there!
I would like to try it by myself, but unfortunately I cant. So, someone who tried the SDK, have you noticed changes in multitasking system?
Right now the only way to resume an app is using fast app switch. But I really dont like it. I rather just use the homescreen icon instead. Right now it relaunch the app.
Any changes on that? (oh please)
Thank you so much!
Click to expand...
Click to collapse
Windows Phone apps can never resume via the homescreen like iOS, due to the addition of the hardware OS back button.
To illustrate why; imagine you have an app that has start page and a settings menu. When a user goes to the settings menu, they can only go back to the start page by pressing the hardware back button (this is standard Metro design).
Now imagine a user opens the app, goes to the settings menu, then exists the app by pressing the Home button. They then do a few other tasks and then resume the app. They are now stuck in the settings menu and can't get back to the app start page; the back key will take them back to the WP8 Home screen (this is how the WP OS backstack works).
To get around this issue, Microsoft specify that starting the app from the front page always has to start a fresh instance, so the user can never get "stuck".
iOS has software back buttons on every page, so all apps can resume however you launch them. Android had the same problem with their back button (actually worse, as their backstack can be altered by the OS choosing to kill memory-intensive apps); to get around this, from ICS onwards Android apps are meant to have a software back button in the top-left, to go back within the application (hardware back key is still OS backstack).
Aphasaic2002 said:
Windows Phone apps can never resume via the homescreen like iOS, due to the addition of the hardware OS back button.
To illustrate why; imagine you have an app that has start page and a settings menu. When a user goes to the settings menu, they can only go back to the start page by pressing the hardware back button (this is standard Metro design).
Now imagine a user opens the app, goes to the settings menu, then exists the app by pressing the Home button. They then do a few other tasks and then resume the app. They are now stuck in the settings menu and can't get back to the app start page; the back key will take them back to the WP8 Home screen (this is how the WP OS backstack works).
To get around this issue, Microsoft specify that starting the app from the front page always has to start a fresh instance, so the user can never get "stuck".
iOS has software back buttons on every page, so all apps can resume however you launch them. Android had the same problem with their back button (actually worse, as their backstack can be altered by the OS choosing to kill memory-intensive apps); to get around this, from ICS onwards Android apps are meant to have a software back button in the top-left, to go back within the application (hardware back key is still OS backstack).
Click to expand...
Click to collapse
But it sucks so bad! They should review this. I hate to use the back button, and I hate to not resume the app. Using a common app, for example, WhatsApp. I was in a chat with someone. Then I hit Windows button and Im at start screen. Then I receive a message from the same person I just left the chat. What I do? I can open from the toast, can open from fast app switch (back button), or open from start screen icon.
If I open from toast, that will depend on what the app was meant to be. In WhatsApp it would take me to the chat, because of deep toast notification. But, right now, it needs to reload the whole app to open just the chat.
If I open from fast switch, it will resume the app right away. Nice. But in any other platform the message would be there waiting for you. Right now, in WP, it takes a lot to refresh the chat. You keep like 10 seconds staring at the screen waiting it. Its even faster to just reopen the whole app.
And if I open from start screen, its almost the same effect of toast, but it dont take me to the chat, but to the start screen of the app.
The point is, the fast switch is not helping that much. In fact, it would makes sense to change the fast switch to open when holding the Windows button instead of back button, and whenever an app is open, opening it from start screen icon just resume it. Actually, a lot of people doesnt even know, or even knowing, doesnt even use fast switch. Im not a common smartphone user, and even so I dont use fast switch.
For me, its the worse problem of platform. And I dont care about CE or NT if it works, but I care about it working at all. Doesnt make sense to put a whole computer in my pocket if it cant resume a single app.
i don't like the idea either to relaunch the app when you just have put it in background. then again, i also hope we will be able to close apps from the fast-appswitch-screen. and add an option to the gesture lovers out there: pinch out on homescreen to launch multitasking. or swipe from edge like w8. or anything like that. it would add to UI experience and would eliminate that 2-seconds-pause when pressing and holding down the backbutton.
Was the question not about Windows Phone 8?
Windows Phone 8 is supposed to behave differently, since true background processing is supposed to be enabled. I haven't played with the SDK yet, but I suspect that for non recompiled apps, things will behave as they do on Mango. But, I think that things changed to target WinRT and set to be able to run in the background will be able to resume right where you left off.
It wouldn't make sense for an app that is running and processing things in the background to restart when the tile is pressed.
It's been a while since I used Mango or wrote any apps for it. But, when an app is suspended, the dev has a specified amount of time to save the state.
That way when it is relaunched, the app can resume where it left off, by processing the saved state on launch. I thought with fast resume the app stayed in memory, but that was done through a registry hack and not directly made available by any carrier.
After doing some reading, the multi tasking enhancements might only add gps and voip to the currently supported background processing.
JVH3 said:
But it sucks so bad! They should review this. I hate to use the back button, and I hate to not resume the app. Using a common app, for example, WhatsApp. I was in a chat with someone. Then I hit Windows button and Im at start screen. Then I receive a message from the same person I just left the chat. What I do? I can open from the toast, can open from fast app switch (back button), or open from start screen icon.
If I open from toast, that will depend on what the app was meant to be. In WhatsApp it would take me to the chat, because of deep toast notification. But, right now, it needs to reload the whole app to open just the chat.
Click to expand...
Click to collapse
Tapping the toast to re-open the chat is the correct behavior here. I guess it's just bad coding that makes it take so long to resume; it should just be able to go straight to the conversation and skip all the "loading contacts...connecting" stuff.
JVH3 said:
Was the question not about Windows Phone 8?
Windows Phone 8 is supposed to behave differently, since true background processing is supposed to be enabled. I haven't played with the SDK yet, but I suspect that for non recompiled apps, things will behave as they do on Mango.
But, I think that things changed to target WinRT and set to be able to run in the background will be able to resume right where you left off.
Click to expand...
Click to collapse
Are you sure you're not thinking of Windows 8? For Windows Phone 8, no changes have been announced regarding multitasking or background tasks, *except* that a few select APIs (VOIP, location) will be able to run in the background, similar to iOS (not true backgrounding like Android)
Also we are talking about resuming, not background processing. In the WP8 SDK emulator, apps built into the OS don't resume; Therefore it's safe to assume 3rd party apps are not going to either.
JVH3 said:
It wouldn't make sense for an app that is running and processing things in the background to restart when the tile is pressed.
It's been a while since I used Mango or wrote any apps for it. But, when an app is suspended, the dev has a specified amount of time to save the state.
That way when it is relaunched, the app can resume where it left off, by processing the saved state on launch. I thought with fast resume the app stayed in memory, but that was done through a registry hack and not directly made available by any carrier.
Click to expand...
Click to collapse
When an app is closed the developer is meant to save the state, so that it can be reloaded if it is quick-resumed. However, once the app leaves the backstack (the 5 apps that appear in when you hold the back-button), this state is supposed to be discarded.
This is not a technical issue; it would be trivial for app developers to save the state and make their apps resume. The issue is that Microsoft's publishing guidelines (to get your app published on the WP app store) specifically says that an app launched from the home screen must launch showing it's introduction page, i.e. it can't resume. It could save some state, so a web-browser could still have all the recent tabs open, but it couldn't show the last one seen (ironically IE9 does resume it's state - guess Microsoft are allowed to break their own guidelines).
I agree it doesn't make sense to restart an app that is performing some background task; but then how to you avoid users getting stuck within a certain page, as in my example above? If WP8 includes a hardware back button, they can't change this policy.
Well, thats a shame. I hate reloading the app everytime I need it. Its so meaningless. I dont need VOIP, I dont need Skype running all the time. But I do need apps to be fast.
It really depends on how exactly the developers save their app state when the app is sent to background/tombstoned.
I, for one, use a text file to save data ( a lot of data) and proceed to loading the app as usual, and the moment the user presses a button, a pop up asks him weather he wants to restore or start anew.
I'm guessing that not every app will do this, as it is up to the developer to implement this.

Categories

Resources