a better DestroyWindow? - General Questions and Answers

I need a tiny, tiny app that just closes the current foreground window.
I ended up writing a small app that just sends the OK virtual key which works fine except that it seems HTC X Button doesn't capture the VK so the default action is executed (SmartMinimize) instead of the action I have HTC X Button set up to perform (real close).
My second solution was to write a small app to send the WM_Close message which worked fine. I later changed it to the destroy message for two reasons ... 1) terminate without any prompting and 2) because there is already a DestroyWindow function so I don't need to sendmessage:
Code:
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
HWND hwnd = GetForegroundWindow();
DestroyWindow(hwnd);
return 0;
}
What I'd like to do is make it a bit more intelligent and, rather than Destroy blindly, prevent it from closing shell32 or cprog, yet properly close what I can only presume are it's children (such as the Programs or Settings Window).
I'm new to windows mobile native coding so I'm having some trouble debugging and developing.

bump ... no developers?
If not, is anyone aware of a small application that merely closes the topmost window (actual close, not smart minimize)?

Would you like me to move your thread to the Dev&Hack section?

I guess but I'm a bit confused ... Last time I asked a dev question in Development and Hacking I got chastised for not posting in Q&A.
If it's cool with you then sure!

Related

[Q] Open a Programm twice parallel?

Hi everybody,
is it possible to open a programm twice parallel? I want to open the coreplayer twice, one time for music and another time for audiobook. Is that possible?
thx, mic
It's probably not too hard to write a script for it.
trying talking to either vijay or oldsap.
Depends on the code in the program itself. In the shell code created by Embedded C++ in the InitInstance function there is the following code:
Code:
hWnd = FindWindow(szWindowClass, NULL);
if (hWnd)
{
// set focus to foremost child window
// The "| 0x01" is used to bring any owned windows to the foreground and
// activate them.
SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
return 0;
}
In other words when the application starts, it looks for another active process with the same name as itself. If it finds one, it activates it, then kills itself.
thx for try to help me - that means it is not possible?
The original PPC programming guidelines by Microsoft stipulated that only one copy of a program should be running at any one time. In later versions of Windows CE/PPC a lot more processes are allowed to run simultaneously. They may have changed their tune over this since. Try and launch it twice, then go to Settings->System->Memory and see if there is more than one copy in Running Programs. If there is only one, then I'm afraid the answer is no.
P.S. If you create a Windows Mobile Win32 program in C++ under Visual Studio 2008, it still has the process checking code in it by default.

Combobox with Smartphones vs. WinMo

With the help of the peeps here, i got my little program working on the WinMo (touch screen) platform. Now im working on converting it into the Smartphone (non-touchscreen) platform. Seems with each medium im go, its more and more restrictive :|
anyway. I have a combobox on the screen. I has a few numbered values used to generate a random number. On the windows and winmo verson, i can just select the number from the drop down combobox, and it will generate a random number based on the selected item..
However in the Smartphone version, despite having the combobox and dispite selecting a number from it, when i hit the generate button (ie the enter button) it brings up a window with all the values in the combo box, asking me to select one from it. One when i pick one and hit "Done" does it process.
How can i get it to pull from the combobox list and Not bring up the extra screen?
Also, When the program first starts, despite me defining a default index, there is no number displayed in the combobox when it first starts up. And ideas on how to fix this?
Thanks in advance.
Good fun isn't it?
When you move from PPC to Smartphone some of the .NET objects dissappear and others behave completely differently.
OK lets do these one at a time. The Enter/Action key causes the ComboBox to display its list of contents, as a new window. It is coded into the object itself. To bypass it, you have to trick it into thinking it has already been dealt with. On the KeyDown event of the ComboBox add
Code:
private void comboBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == System.Windows.Forms.Keys.Enter)
{
e.Handled = true;
}
}
Voila!
The enter key is ignored and nothing happens. Add any processing code here to deal with the selected item if required, as the control itself will never see that the 'Enter' key has been pressed.
To get the box to display its value when your application starts, use :
Code:
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.SelectedIndex = 0;
}
It doesn't actually change anything as it zero to start with, but it will trigger the ComboBox to redraw itself as it thinks it has changed.
Good luck.
The "comboBox1.SelectedIndex = 0;" ive tried already, didn't seem to help. Ill try the other when i get a moment..
I should also mention ( thought i did before, sorry) that im working with VB (for school) tho converting that code to vb shouldn't be too hard
OK I'll code it up in VB and post it. But it will have to wait until I can get to a suitable machine on which to do it. Monday onwards....... Watch this space.
Here it is. VS 2005. (2008 will update it). Both problems mentioned in the original post are corrected. All the extra lines of code added by VS for the KeyDown event have been removed.

[Q] GPS-tracking acting weird.

Hello!
Firstly, I don’t speak english very well. But I beg your indulgence.
I have some troubles with every GPS tracking apps I’ve installed on my Omnia W (I8350). While I start the tracking and locking my phone, it’s tracking quite well.
BUT, if I want to write a SMS or something. I have to press on the Windows-button to come out to the main menu, and the GPS-tracking will stop. But the time counter continues unaffected.
I think it’s a bit weird behavior. I have testet, Endomondo, Sports Tracker, SmartRunner, Runtastic. And all of these apps acts at same way.
Is this normally? Is it the OS, which stops the GPS-device, while the app is minimized?
It's the OS, yes. In theory, an app could continue GPS tracking in the background, but since that's not officially allowed (you'd need to mess with the APIs in ways Microsoft doesn't approve of) it wouldn't be allowed into the Marketplace.
@GoodDayToDie
Do you know any working hack that will allow app continue tracking in the background? Maybe some registry changing?
If app cannot get to Marketplace, it is not problem for me. I want to create GPS tracking in background only for myself.
At the max it will work with screen lock though Endomodo doesnt support but others do. And Yes its a problem with Windows Phone API not allowing intensive tasks to run in background.
May be a custom app can do which somebody can sideload but then its for one few people.
Well, the dehydration tweak that Jaxbot found (and yes, it's a registry change) allows an app to keep running in the background. That doesn't guarantee it will actually keep tracking - the app still gets notified that it's leaving the foreground, and a "well behaved" app might stop using resources like the GPS when it gets that notification - but it makes it possible. Normally I'd direct you to my MultiTaskToggle app, which is a very simple and user-friendly way to change this value, but it doesn't work on second-gen Samsung phones at this time.
GoodDayToDie said:
Well, the dehydration tweak that Jaxbot found (and yes, it's a registry change) allows an app to keep running in the background. That doesn't guarantee it will actually keep tracking - the app still gets notified that it's leaving the foreground, and a "well behaved" app might stop using resources like the GPS when it gets that notification - but it makes it possible. Normally I'd direct you to my MultiTaskToggle app, which is a very simple and user-friendly way to change this value, but it doesn't work on second-gen Samsung phones at this time.
Click to expand...
Click to collapse
I am pretty sure that just keeps it in memory, but not actually running. I downloaded the source code to see what it does and manually applied the registry change. It allows fast resume from any app, even if it was not recompiled for Mango. This is good for apps, such as Angry Birds, which would otherwise dehydrate, and need to restart. But, when using it, you can see that if you launch a bird, and then switch out. Wait a while. Then switch back to it. You can see that the launched bird has not moved since switching to a different app. It is possible that the app is suspending by responding to the fact that it is being pushed into the background.
Most apps that display time, or a timer that counts are not actually counting. What they do to display it get an initial time value when the timer starts. Then they get the time and subtract the initial time from it. So, an app that seems to count seconds, even when in the background is really just successfully get the current time and subtracting the original time before suspension. They may use a timer control to schedule the frequency that this calculation is made.
To verify, it would be good to test with a simple program that does something like:
Code:
[FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]namespace[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] TestCountApp
{
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] public[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]partial[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]class[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Form1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] : [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Form
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] {
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] public[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] Form1()
{
InitializeComponent();
}
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] i = 0;
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] private[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] btnStart_Click([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] sender, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]EventArgs[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] e)
{
timer1.Start();
}
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] private[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] timer1_Tick([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] sender, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]EventArgs[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] e)
{
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] val = 0;
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] try
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] {
val = [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].Parse(tbText.Text.ToString());
}
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] catch[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] ([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Exception[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] ex)
{
}
i++;
tbText.Text = i.ToString();
}
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] private[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] btnStop_Click([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] sender, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]EventArgs[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] e)
{
timer1.Stop();
}
}
}
of course the timer class might automatically suspend for Windows Phone.
So, a simple for loop might be better.
Code:
[FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]namespace[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] TestCountApp
{
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] public[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]partial[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]class[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Form1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] : [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Form
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] {
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] public[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] Form1()
{
InitializeComponent();
}
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2][/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] private[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] btnStart_Click([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] sender, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]EventArgs[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] e)
{
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] for[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] ([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] i = 0; i < 60; i++)
{
tbText.Text = i.ToString();
System.Threading.[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Thread[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].Sleep(1000);
}
}
[/SIZE][/FONT][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] }
}
If it is background processing, you should see 59, after returning to the app. It will remain blank until the end.
[/SIZE][/SIZE][/FONT][/FONT][/SIZE][/FONT][/SIZE][/FONT]
GoodDayToDie said:
Well, the dehydration tweak that Jaxbot found (and yes, it's a registry change) allows an app to keep running in the background. That doesn't guarantee it will actually keep tracking - the app still gets notified that it's leaving the foreground, and a "well behaved" app might stop using resources like the GPS when it gets that notification - but it makes it possible. Normally I'd direct you to my MultiTaskToggle app, which is a very simple and user-friendly way to change this value, but it doesn't work on second-gen Samsung phones at this time.
Click to expand...
Click to collapse
Unfortunatelly it doesn't help, because OS is suspending app executing. OS is just keeping app in memory.
Anyway I can use background task in debug build with LaunchForTest method that will allow me execute background code as often I want. However background task cannot access fresh GPS data. It can only used cached data which is refreshed every 15 minutes. Is any way to force GPS to refresh it's data when using GPS from background agent?
OK, in reverse order:
@Mendoza32: You are quite incorrect; the change to the registry I was talking about actually causes the OS to *not* suspend apps. It can cause problems for some of them. In Mango, an app is *always* kept in memory when it's backgrounded. Apps that weren't recompiled for Mango can't take advantage of this and will do a full rehydrate anyhow, but they don't hve to (using a process listing, you can see that the suspended processes are still in memory). However, even with the tweak, a few things are cut off, like audio (and possibly GPS). See my response to JVH3 for more info...
As for a background agent, there's no official way. I think if you abuse one of the background audio decoder agent classes, you might be able to make an agent that runs in the background and can access the GPS. I haven't tried, though, and there's no chance of it getting into the Marketplace.
@JVH3: If you read the really old threads on the subject, you'll see that the app really does keep running in the background. For example, you can create an app that will pop a MessageBox (which always goes to the foreground) after 10 seconds, start it and immediately hit the Windows key. A few seconds later, you'll get the message box. More practically, you can use this hack to do things like run the WebServer app (any version) in the background, and browse it in the foreground on the phone's IE (pointing to 127.0.0.1). This would be impossible if the app were suspened, obviously...
As for Angry Birds, the game is in fact pausing the XNA update/render loop when notified that it's going into the background. In theory, this allows it to save the entire current game state, including the flying bird, such that when you resume the app (from dehydration, or so it thinks), that bird is exactly where it was and you've lost no progress. I suspect it is actually doing this. On the other hand, a game like Puzzle Quest 2 (which is rather poorly behaved regarding dehydration) quite obviously does *not* suspend the update/render loop. It's a turn-based game, so there is no gameplay problem, but there are certain real-time graphical effects that, when you "resume" the game, will all render simultaneously. Additionally, the phone will get quite warm and use a lot of battery (and other games will run slowly) because Puzzle Quest 2 still eating CPU and GPU time in the background.
GoodDayToDie said:
As for a background agent, there's no official way. I think if you abuse one of the background audio decoder agent classes, you might be able to make an agent that runs in the background and can access the GPS. I haven't tried, though, and there's no chance of it getting into the Marketplace.
Click to expand...
Click to collapse
I do not want put app in Marketplace. It's only for me
GoodDayToDie said:
@JVH3: If you read the really old threads on the subject, you'll see that the app really does keep running in the background. For example, you can create an app that will pop a MessageBox (which always goes to the foreground) after 10 seconds, start it and immediately hit the Windows key. A few seconds later, you'll get the message box.
Click to expand...
Click to collapse
Could you provide some sample code how to display this message box when app is in background? I tried this but without any luck. Maybe I'm missing something.
Did you have the no-suspend/dehydrate tweak enabled? It should be simple (event handler for a button or something:
Thread.Sleep(10000); MessageBox.Show("Alert from background app");
Thank you very much GoodDayToDie. I see how it works now. As long as GUI thread is blocked, then background threads keep working (also the GPS). One drawback is that I cannot go back to my app. It just keep displaying "Resuming...", but this is because GUI thread is blocked.
@GoodDayToDie
I was all wrong. Blocking GUI thread doesn't help in anything, because OS is killing app.
Please take a look at this sample code:
Code:
using System;
using System.Diagnostics;
using System.IO.IsolatedStorage;
using System.Threading;
using System.Windows;
using Microsoft.Phone.Controls;
namespace PhoneAppBackgroundTest
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
this.Loaded -= this.MainPage_Loaded;
this.DisplayLastUpdateTime();
}
private void buttonBackgroundThread_Click(object sender, RoutedEventArgs e)
{
ThreadPool.QueueUserWorkItem((s) =>
{
while (true)
{
this.UpdateLastUpdateTime();
Debug.WriteLine(DateTime.Now.ToString());
Thread.Sleep(1000);
}
});
}
private void buttonBlockGUIThread_Click(object sender, RoutedEventArgs e)
{
while (true)
{
Thread.Sleep(1000);
}
}
private string lastUpdateKey = "lastUpdate";
private void DisplayLastUpdateTime()
{
string value;
if (IsolatedStorageSettings.ApplicationSettings.TryGetValue<string>(this.lastUpdateKey, out value))
{
MessageBox.Show("last update time: " + value);
}
}
private void UpdateLastUpdateTime()
{
if (IsolatedStorageSettings.ApplicationSettings.Contains(this.lastUpdateKey))
IsolatedStorageSettings.ApplicationSettings.Remove(this.lastUpdateKey);
IsolatedStorageSettings.ApplicationSettings.Add(this.lastUpdateKey, DateTime.Now.ToString());
IsolatedStorageSettings.ApplicationSettings.Save();
}
}
}
Button "buttonBackgroundThread" is starting new background thread which updates settings value and display current time to Output window. When you press this button you will see in Ouput, that current time is displaying each second. When you use window key, then current time is no longer displaying in Output. So the thread gets suspended. When you go back to app it start to work again.
When you press on button "buttonBackgroundThread" and "buttonBlockGUIThread" and use window key, you will see that current time is keep displaying in Output. This works when you have debugger attached. If you follow this scenario on device without attached degubber you will see that app is getting killed by OS. To prove that app is displaing last update time at start.
So my question is: how to get managed threads keep running while app is in background? I'm attaching sample project, so you can test on your device and see that managed thread get suspended when you use window key.
Is maybe some way to use native threads that won't get suspended? I see your WebServer can run while app is in background. However you used native listeners.

[Q] How to retrieve image from sql server into window phone?

I had error ArgumentNullException was unhandled when run my coding.
Code:
public class ImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
byte[] buffer = value as byte[];
[B]Stream memStream = new MemoryStream(buffer);[/B]
WriteableBitmap wbimg = PictureDecoder.DecodeJpeg(memStream);
return wbimg;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
The bold line is where the error occur..
Any solution to this error or any other suggestion for me to retrieve image into window phone? Thank you.
Well...
Well, I guess you enter your method with value as null. Your code snippet does of course not show just why value might be null.
Pardon me this innocent question: Why don't you just take the whole thing into the debugger and watch what happens?
Either value is null, or value is not a byte[].
It would be better to just cast it to byte[] instead. That way you would get a different error if it's not a byte[], than if it's null. This would be of some diagnostic value but as another poster mentioned your best bet is to run this in a debugger to see what's going on.
save the image name in database,
Sorry, may i know how to test it in debugger mode?Thank you.
Too early?
hueikar said:
Sorry, may i know how to test it in debugger mode?Thank you.
Click to expand...
Click to collapse
I don't want to offend you, and of course you are free to do whatever you like, but I think it's too early for you to build a full and maybe complicated WP7 app. Do you know the saying "First you have to learn to crawl before you can try to walk"? I think you should learn the fundamentals of using Visual Studio and programming for WP7 from some nice book or online tutorial first.
Even working with complete code samples, as you seem to try, does not help, if you ask me. At least it always was like that when I tried it myself: If in the past I tried to get some code samples to work that I did not understand myself, the first trivial problem already stopped me dead in my tracks. I only had success after my knowledge had progressed to a point where I could read and understand the samples.
Sorry. Yes. I admit that i am too rush to do a win7 app. This is my first time doing window phone app and so with the language c#. But i kinda run out of time to do learning..My first mistake is choose wrong title to do window phone app as my final year project..Luckily so far i manage to do the CRUD for the app.but this is the most difficult problem i am facing now..
Well, in answer to your question, Visual Studio has a Debug button. Select whether you want to debug on the emulator or on your phone (the latter requires that the phone be connected to the PC and Zune be running) and give it a try. If you want to use the media library while debugging, you'll need to use the WPConnect program (it's part of the dev tools, I believe) which allows you to close Zune after you establish the connection, thus unlocking the media library on the phone.

Link contact adress to Nokia Drive

I use my7rom on my Omnia 7.
Is there anyway to link a contacts adress to Nokia Drive instead of Maps (stock wp7 app). It would be much more practical if Nokia Drive opened a navigation session instead.
Anyone up for the challenge? A reg-tweak perhaps?
// Manneman
Skickat från Windows Phone 7.8
There's two parts here. The first is identifying the correct "filetype" or URI scheme that is used for navigation. That shouldn't be too hard; a little digging in HKCU should reveal it. We already know about ones like callto: and http: and I'm actually (slowly) working on an app to allow people to easily change them. The second part is finding the correct command to load that address or route in the Nokia Maps app. If the app supports pinning routes or destinations to Start, this is probably possible. If not, it may not be possible in the app. Most apps aren't designed to accept command-line parameters, so even if you make them the default handler for a given filetype or URI scheme, they ignore the value you send them and just start as though launched from Start.
GoodDayToDie said:
If the app supports pinning routes or destinations to Start, this is probably possible.
Click to expand...
Click to collapse
Nokia Drive supports pinning to start so it should be possible. Unfortunately I can't tell you exact command line parameters 'cause my Lumia 900 still "in jail"
Let me see if I have a copy of the Nokia Drive XAP handy. I'll need to decompile it to figure out the correct parameters for launching it with the intent of navigating to a specific location. Note also that this might not be possible directly - for example, the app might store a list of locations internally, and the tiles only provide an index into that list rather than providing the location directly - but that just requires another layer of indirection.
In that case, you create an app that gets registered as the navigation handler, and in response to a navigation request, it writes the requested location into the Nokia Drive app and then chain-launches Nokia Drive with the index of the newly written location. That's just an example of one way that this might go wrong, but overall, the odds are actually pretty good. Obviously, all of this will require, at a minimum, write access to the HKCR hive in the registry.
Ah, guys! You are so kind helping me out. I´m really certain alot of members in the WP7 section would love for this to work!
// Manneman
GoodDayToDie said:
I'll need to decompile it to figure out the correct parameters for launching it with the intent of navigating to a specific location
Click to expand...
Click to collapse
GoodDayToDie, you may try much simpler solution. Just create assembly (dll) to show startup parameters in message box, and replace main Nokia Drive dll (but pin some location first).
That's actually harder than it sounds; even if the app is sideloaded (which would mean I already have the DLL) my fake would have to mimic the internal structure of the real app to a degree (namespaces, class names, default actions, etc.). That's not hard, but decompiling .NET is pretty trivial too.
AFAIR, Nokia Drive is obfuscated (but I'm not 100% sure). Also, you don't need to duplicate all names and structures; just a stuff mentioned in WMAppManifest (I hope so). BTW, I forgot: I still have unlocked handset; if I'll found time, will try today later.
Update: tried but without of luck What I did:
- installed Nokia Drive first;
- downloaded map and pinned current location;
- created fake app with same app guid and namespace name ("Drive"), and performed app update (that operation completely override whole solution but NokiaDrive tile still pinned to the start screen);
- tried a few different page names (_default.xaml, QuickStartPage.xaml, DestinationPickerPage.xaml, FavoritesPage.xaml) with code
Code:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
MessageBox.Show("Hello from fake dll");
if (e.NavigationMode == System.Windows.Navigation.NavigationMode.New)
{
string[] keys = NavigationContext.QueryString.Keys.ToArray();
string[] values = NavigationContext.QueryString.Values.ToArray();
string param = "";
for (int i = 0; i < keys.Length; i++)
{
param += keys[i] + " -> " + values[i] + "\n";
}
MessageBox.Show("parameters: " + param);
}
}
But result always the same: app doesn't start from the pinned tile
Update 2: Finally, I did it
The trick is:
- do the same as I've described above (you should have pinned tile from ND);
- add following code to the start page:
Code:
public MainPage()
{
InitializeComponent();
var appTile = ShellTile.ActiveTiles.Last();
if (appTile != null)
{
//MessageBox.Show(appTile.NavigationUri.OriginalString);
EmailComposeTask emailTask = new EmailComposeTask();
emailTask.Subject = "NokiaDrive pinned parameters";
emailTask.Body = appTile.NavigationUri.OriginalString;
try
{
emailTask.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK);
}
}
}
- run app as usual (not from tile);
We allset - all params are sent to our email (I'm too lazy to manually copy all stuff )
Here we are (start parameters; bold values are changed for privacy reason ):
/_default?destination.name=200 SomeName Street&destination.latitude=49.5255378801376&destination.longitude=-72.4296837244183&destination.address.street=SomeName Street&destination.address.houseno=200&destination.address.district=&destination.address.county=&destination.address.city=SomeCity&destination.address.state=&destination.address.country=USA&destination.address.postcode=05720&destination.hashCode=371767793destination.address.statecode=MA&pinnedFrom=Favorites
P.S. Just found: Navigon also has ability to pin address to the start tile So, if you find the way to modify map protocol (or how it calls), it will be a really nice hack! BTW, could you remind me: do we have ability to launch assembly by GUID (on the full-/policy-unlocked phones)? If "yes", it's possible to write a real nice "proxy" app to handle map requests
I don't know about launching assemblies directly, but it's certainly possible to launch apps by GUID. It doesn't even require anything more than dev-unlock in fact (although of course you can only launch apps that you could launch anyhow). So yes, a proxy app is totally possible. That's actually what I'm working on (started as a project to make a Kindle ebook file loader, that would pur .mobi/.prc file in the Kindle app's folder and then launch the app).
GoodDayToDie, could you please, take a look to the registry, for default map protocol handler and figure out how to change that stuff? I'm pretty busy these days (and probably will be extremely busy couple of next months) but we can cooperate and create this app...
I'll investigate, but you're not the only one busy. If you've noticed a lack of software from me recently, it's due to the nex job I got some months back; I love it, but it leaves me with a lot less time for phone hacking if I want to still have a life outside of that.
With that said, this actually ties into the work I'm already doing with things like filetype handling and default browser switching. I can send you my HKCRlib, at a minimum; it's a library that simplifies interacting with HKCR, including creating backups of important values when they change, and reverting the backups.
GoodDayToDie, truly, I'm not much interested (personally) in that hack 'cause I can't use it for my Lumia 900. So it's only for the community needs but because of lack of time, I believe, we may put it on hold.

Categories

Resources