how to process events in a loop - Windows Mobile Software Development

Hi,
in my C-Program there is a loop, where data are send and received.
I want to give the user a chance to break this loop.
There is a push-button on the dialog-form. In the event-handler there is a flag, which is set, when the button is pressed. But when the program is running in the lopp, this code is never reached.
In the loop, I want to break, if the flag is set.
How can I achieve that the button-pressed-event is processed,
when the program ist running in the transmission-loop.
Perhaps someone knows a solution.
Have a nice day!
Franz

Have you tried running the 'loop' in a different thread then the User Interface? It might be the problem that the main thread is so busy looping that it ignored/doesn't receive the button press...

Your best solution would be to kick off your loop as a seperate thread.
the other option is to process messages every so often, by peeking and pumping the message handler.
The thread method is the cleanest by far.
..Chuck..

the other option is to process messages every so often, by peeking and pumping the message handler.
Click to expand...
Click to collapse
Is this like the old VB command DoEvents?
I am looking for a way to process the WM_PAINT event of a form, whilst again in a loop, which the DoEvents would have perfectly completed.
Have you a code example for 'peeking and pumping'?
Thanks!
Ben.

benclewett said:
Have you a code example for 'peeking and pumping'?
Click to expand...
Click to collapse
void CProgressDlg:eekAndPump()
{
MSG msg;
while eekMessage(&msg, NULL,0,0,PM_NOREMOVE)) {
if (!AfxGetApp()->PumpMessage()) {
:ostQuitMessage(0);
return;
}
}
}

Related

how to get the notification when a call end

How to get the call process notification when a call end or shut down by remote network?
i don't want to use ril.lib.
If you make the call using ExTAPI (not RIL) then you will get a Callback then the call is over.
Search for 'lineCallbackFunc'.
Ben
It is relatevelly easy with lineCallbackFunc. You have to wait for the LINECALLSTATE_DISCONNECTED messages in dwParam1 of this function and than you have to check the second param to see what cause this event.
The code migth look like this:
case LINECALLSTATE_DISCONNECTED:
{
//Place your code here
switch(dwParam2)
{
case LINEDISCONNECTMODE_NORMAL:
//Place Your code here
}
}
Search MSDN for the list of LINEDISCONNECTMODE constants !!! (I wrote only one, there are more, of course
Regards
Yes, sorry I didn't ellaborate much I use much the same.
This function has six parameters, a random selection of which might contain information, which may or may not be documented. There are various incomplete examples from various people arround, or just dive in and see what you get...
This callback is (I belive) called from the RIL callback. The mapping is not 1-2-1, MS claim there is 'significant logic' between the two layers. So using RIL would ultimatelly get you closer to the truth. Certainly, I belive TAPI only gives access to your applications use of the phone, I belive RIL gives access to any applications use of any phone use.
Some help from TAPI.h where the messages are defined, may be found.
Anyway, this is what I use: First the 'dwMsg' = LINE_CALLSTATE, then examine the dwParam1, dwParam2. When dwParam1 = LINECALLSTATE_DISCONNECTED and dwParam2 != LINEDISCONNECTMODE_REJECT you have a fair chance that the phone has been disconnected.
The hard part is not the understaning of the callback, it's getting bl**dy call back correctly registered in the first place...
Ben

[REQ] Help for app development: SetPowerRequirement and invoke Appointment

Hello,
I am very new with CF development.
I try to create my first app in C#.
At the moment I am struggling with two problems:
1.
I wrote an appliactian what is running like a "Service". I used the managedservices class of CodePlex. (Sorry, I am not allowed to post links here)
The app is running fine until my device turned off the screen (timeout as configured in the settings). The applications stopps until I press the power button to awaik it.
I already red a lot of SetPowerRequirement and PowerPolicyNotify but I was unable to implement it. Could somebody provide me a code snippet for that?!
2.
At a specific event I want to invoke an appointment. Means, I want to play the device configured appointment sound, display the appointment form and let the LED flashing.
Is there a class or an API that I can use?
Or do I have to invoke all these things manually? If so, how can I invoke the sound and the LED flashing?
Would be very cool if somebody could give me some support!
Thank you in advance.
Matthias
Agamemnon81 said:
Hello,
I am very new with CF development.
I try to create my first app in C#.
At the moment I am struggling with two problems:
1.
I wrote an appliactian what is running like a "Service". I used the managedservices class of CodePlex. (Sorry, I am not allowed to post links here)
The app is running fine until my device turned off the screen (timeout as configured in the settings). The applications stopps until I press the power button to awaik it.
I already red a lot of SetPowerRequirement and PowerPolicyNotify but I was unable to implement it. Could somebody provide me a code snippet for that?!
2.
At a specific event I want to invoke an appointment. Means, I want to play the device configured appointment sound, display the appointment form and let the LED flashing.
Is there a class or an API that I can use?
Or do I have to invoke all these things manually? If so, how can I invoke the sound and the LED flashing?
Would be very cool if somebody could give me some support!
Thank you in advance.
Matthias
Click to expand...
Click to collapse
exactly what event will be used to trigger the creation of an appointment? you might be able to use the notification queue of Windows Mobile. which means the OS will trigger the event even if ithe OS is suspended.
mb286 said:
exactly what event will be used to trigger the creation of an appointment? you might be able to use the notification queue of Windows Mobile. which means the OS will trigger the event even if ithe OS is suspended.
Click to expand...
Click to collapse
Thank you very much.
That was the first very important hint for me. I always searched for "appointment" but did not find the notification class.
I got it running. Only problem is the LED is not flashing. Maybe this is a special thing?!
Is there a HTML code available which lets the notification just look like that one of a calendar appointment? I am not very firm with HTML.
BR
Matthias

Transparent/Translucent Forms & Controls

So I have been searching these forums a bit each day for the past week, and I have yet to see a working solution for SmartPhones AND PPC's alike. I have tried P/Invoking AlphaBlend, SetBkMode, etc. but to no avail. I am not a great coder, so I may be using them wrong.
If anyone knows how to get this to work on SmartPhone's and PPC's, could they please share their knowledge
Thank you!
Cyclonezephyrxz7 said:
So I have been searching these forums a bit each day for the past week, and I have yet to see a working solution for SmartPhones AND PPC's alike. I have tried P/Invoking AlphaBlend, SetBkMode, etc. but to no avail. I am not a great coder, so I may be using them wrong.
If anyone knows how to get this to work on SmartPhone's and PPC's, could they please share their knowledge
Thank you!
Click to expand...
Click to collapse
What exactly do you want to do?
I want to be able to make forms / controls that have Opacity less than 255 ... (I want to do this in C#) ... take, for instance, SMSBubbles, it displays a small bubble at the bottom of the screen about a new text message...how would i be able to achieve that and still maintain the background to be transparent. Also look at SmartToolKit, when you pop open the Start Menu, the back (what is not covered by the menu) remains updating (etc.) but you still get the menu..
I want to do something along those lines...
any help is greatly appreciated
Have you checked out this blog entry?
blogs.commentor.dk/post/Transparent-Controls-in-NETCF.aspx
Or a library: http://beemobile4.net/?sitecateg=products&productID=5
Thanks for the replies, the first I tried implementing, but it didn't work as I would have hoped (The second, well I don't want to pay 45+$ for it...heh)
So I re-tried P/Invoking SetBkMode in the onPaintBackground method:
Code:
protected override void onPaintBackground(PaintEventArgs e)
{
setBkModeCE(e.Graphics.getHDC(), BkMode.TRANSPARENT);
}
I also made sure to P/Invoke
Code:
SetCursor(IntPtr cursor)
...main loop starts here...
SetCursor(IntPtr.Zero)
to get rid of the wait cursor.
While this works perfectly in terms of eliminating the background, it doesn't actually make it transparent. What it does, i can do by taking a screenshot and applying it as the bg (It doesn't update). I suppose I can use a timer and have it update the background on Events of all sorts, on user-activity, and every minute, but that seems like it is a hassle.
That may be the only way to actually do it, I don't know, but it just seems that there is a better way to do it (and be able to conserve RAM).
I used this library in one of my apps: http://code.msdn.microsoft.com/uiframework
Sourcecode is available, written in C# so its easily adaptable to your needs too.

Help me debug ArkSwitch :)

Hi all,
It seems that certain people (most notably multiple HD2 users) are having crashes and other issues with ArkSwitch. I have a Fuze (Touch Pro), and I'm not experiencing these issues. Therefore, it's virtually impossible for me to fix them.
I ask for your help finding and fixing these bugs, if you have any device that is not a Touch Pro. The source code is available at http://arkswitch.codeplex.com and I would really appreciate some help from any devs that have an HD2 or pretty much any device other than my own.
Let's use this thread to discuss code issues, and the "main" thread for everything else.
Thanks a lot!
Hi ark,
I'll take a look into it (I have an HD2, and sometimes it freezes for me also)
I've coding skills so no worries
See you later
PS. Nice app!
Cool, thanks!
Works fine on my HD
Only crashes when i try to include a image as a selector
hi Arktronic,
I have included ArkSwitch in my ROM v1.8, but have to remove it in next release.
Here are some problems found:
- I have to exclude it from CleanRAM otherwise CleanRAM will take the phone down.
- top taskbar (I'm using WM6.5.5) will be no longer accessible if ArkSwitch has been terminated by other apps (such as Task Manager 3.1, CleanRAM), or sometimes closed by itself.
However, I like the way ArkSwtich "take down" other apps, such as cprog.exe (Phone). It really removes cprog from the memory and free up some RAM without crashing the phone.
Is it possible to make ArkSwitch NOT to stay in RAM?
P/S: Sorry, I'm off topic. You want to discuss coding? Where can I get the code?
If you don't want ArkSwitch to stay in RAM, enable WM65 compatibility mode. Depending on what the user does then, it will either quit or minimize (but be friendly to the system if killed by CleanRAM or others).
Like I said in the first post, the source code is available here: http://arkswitch.codeplex.com/
Okay I did a debug session,
It seems to freeze here:
// Get the window text or else continue enumerating.
if (!GetWindowText(hwnd, WindowTextSb, 1024)) return 1;
in
static int EnumWindowsCallback(IntPtr hwnd, uint lParam)
In some cases the function GetWindowText doesn't return...
If I remove this call, it will load without any freeze
Interesting. Does that happen when there is another app that has frozen, or is it just random?
Maybe I forgot to lock that callback procedure in memory to prevent the GC from moving it around...
Arktronic said:
Interesting. Does that happen when there is another app that has frozen, or is it just random?
Maybe I forgot to lock that callback procedure in memory to prevent the GC from moving it around...
Click to expand...
Click to collapse
Seems that just some apps makes it freeze. I just noticed that an app written by me in c++ makes it freezing every time
If it is closed instead, arkswitch loads up normally.
I forgot:
It is not frozen. But it hosts a IE control in it if that could help.
btw I don't think is a GC problem...
I don't think an IE control would have such an effect. Is it a normal window, and does it have title text?
Arktronic said:
I don't think an IE control would have such an effect. Is it a normal window, and does it have title text?
Click to expand...
Click to collapse
I was searching a way to implement IE Control correctly due to netcf's scrolling bug with it. My exe is a modification of this one http://cid-e91b74403814953e.skydrive.live.com/self.aspx/BrowserWithGestures/BrowserWithGestures.zip which I'm using as support to my main app...
I'll look at that when I get a chance. Thanks again!
Arktronic said:
I'll look at that when I get a chance. Thanks again!
Click to expand...
Click to collapse
I'm going to look again on that piece of your code instead, maybe I will figure it out because it freezes.
I think i found the answer:
Internally, GetWindowText calls SendMessage(hWnd, WM_GETTEXT) to the window.
Since the thread calling GetWindowText (your thread) and the thread that
owns the window are different threads, the SendMessage
internally becomes a PostMessage, which sticks the message in the owning
thread's message queue and blocks until the message is processed by the
owner thread. You are now at the mercy of the owner thread to process that
message. If that thread isn't running a message pump, you're stuck.
Click to expand...
Click to collapse
you should use
SendMessageTimeout(hWnd, WM_GETTEXT, ..., 1000L,...). You'll be blocked for
1 second tops. You can of course send in a longer delay, but 1 second
should be sufficient.
Click to expand...
Click to collapse
Let's fix it
I'll post fixed source as soon as I end.
Wow, great find! I'll change it as soon as I can. This explains why other apps freezing causes ArkSwitch itself to freeze.
EDIT: Oh, if you're going to change it yourself, that works too
Fixed. It doesn't freeze anymore.
I'm doing some other checks, then I'll post corrected source code
w00t! You are awesome
Arktronic said:
w00t! You are awesome
Click to expand...
Click to collapse
I read on codeplex "Removed global memory status information retrieval as a test..."
Why you did so?
Where I need to touch to re enable it?
PS. Thanks, i just like to help
I did it as I was testing various things with Long Zheng to determine why ArkSwitch crashed on his HD2. We seemed to get somewhere with the removal of that, but then it started crashing again. I suggest you just go with change set 44738, as that has the latest stuff in it, except for the unnecessary removal of global memory info.
Arktronic said:
I did it as I was testing various things with Long Zheng to determine why ArkSwitch crashed on his HD2. We seemed to get somewhere with the removal of that, but then it started crashing again. I suggest you just go with change set 44738, as that has the latest stuff in it, except for the unnecessary removal of global memory info.
Click to expand...
Click to collapse
Ok.
Do you know how to detect sliding the finger on listview? I would add a process view which opens on sliding finger from right to left but there is not any mousedown/up event...

CheckBox state presrving/restoring

Hi there,
Does anyone out there how to preserve/restore the transient state of a CheckBox and/or Radio button?
So far, I'm using the following code, working for textbox
Code:
Public Sub PreserveState_TextBox(ByVal TB As TextBox)
Dim buffer As String = String.Empty
If True = PhoneApplicationService.Current.State.ContainsKey(TB.Name) Then
buffer = TryCast(PhoneApplicationService.Current.State(TB.Name), String)
If Not String.IsNullOrEmpty(buffer) Then
TB.Text = buffer
End If
End If
End Sub
Public Sub RestoreState_TextBox(ByVal TB As TextBox)
If True = PhoneApplicationService.Current.State.ContainsKey(TB.Name) Then
PhoneApplicationService.Current.State.Remove(TB.Name)
End If
PhoneApplicationService.Current.State.Add(TB.Name, TB.Text)
End Sub
it possible to modify the above code to work for Checkbox and/or Radiobutton?
If not, any ideas?
So far, I've been trying the sample "Tombstoning" sample code from Microsoft without any luck...
Thanks in advance!
Hi,
I'm not a VB developer, but storing the state of a checkbox is not much different from storing any other primitive type. What you could do is have a bool variable "isCbChecked" and store that bool state in your PhoneApplicationService.State.
Code:
PhoneApplicationService.Current.State.Add("isCbChecked", myCheckbox.IsChecked)
Then, when you're restoring your app, simply do
Code:
myCheckbox.IsChecked = (bool)PhoneApplicationService.Current.State.ContainsKey("isCbChecked");
keyboardP said:
Hi,
I'm not a VB developer, but storing the state of a checkbox is not much different from storing any other primitive type. What you could do is have a bool variable "isCbChecked" and store that bool state in your PhoneApplicationService.State.
Code:
PhoneApplicationService.Current.State.Add("isCbChecked", myCheckbox.IsChecked)
Then, when you're restoring your app, simply do
Code:
myCheckbox.IsChecked = (bool)PhoneApplicationService.Current.State.ContainsKey("isCbChecked");
Click to expand...
Click to collapse
Thanks a lot for your fast reply.
Can I ask for additional help on how to make your statements into generic procedures, at least to take them to something similar to what I posted?
Don't care if it's in C#
Thanks in advance!
GFR_2009 said:
Thanks a lot for your fast reply.
Can I ask for additional help on how to make your statements into generic procedures, at least to take them to something similar to what I posted?
Don't care if it's in C#
Thanks in advance!
Click to expand...
Click to collapse
Off the top of my head, something like this should work (C# code).
Code:
public static T RestoreState<T>(string key)
{
if (PhoneApplicationService.Current.State.ContainsKey(key))
{
return (T)PhoneApplicationService.Current.State[key];
}
return null;
}
'T' is the type that will be used. In C# 'T' is a special character denoting the generic type, not something I just used
So in the code above, the return type is 'T' and when using RestoreState, it will be 'RestoreState<Textbox>("TB.Name");'. The value of 'TB.Name' will be searched within the dictionary and, if it's found, it will cast that object as 'T' (Textbox) and return it, otherwise it will return null.
Hi,
So far, I did the following and while no error is raised, nothing happens...
Code:
Public Function Backup(ByVal token As String, ByVal value As Object) As Boolean
If Nothing Is value Then
Return False
End If
Dim store = PhoneApplicationService.Current.State
If store.ContainsKey(token) Then
store(token) = value
Else
store.Add(token, value)
End If
Return True
End Function
Public Function Restore(Of T)(ByVal token As String) As T
Dim store = PhoneApplicationService.Current.State
If Not store.ContainsKey(token) Then
Return Nothing
End If
Return CType(store(token), T)
End Function
I call them as follows
Code:
Backup(Me.CheckBox_1.Name, Me.CheckBox_1)
Restore(Of CheckBox)(Me.CheckBox_1.Name)
Don't where is the error, maybe you could take a look and help me out.
Any help is much appreciated!
Where are you calling the Backup and Restore functions? Since your doing page specific things, you could do it in the OnNavigatedFrom and OnNavigatedTo methods, respectively.
keyboardP said:
Where are you calling the Backup and Restore functions? Since your doing page specific things, you could do it in the OnNavigatedFrom and OnNavigatedTo methods, respectively.
Click to expand...
Click to collapse
Hi,
I'm calling them in the OnNavigatedTo and OnNavigatedFrom methods, as you pointed out
Unfortunately, nothing happens at all!
Thanks!
Hi,
As far as I can tell, there's nothing wrong with your saving/loading code. When you call
"Restore(Of CheckBox)(Me.CheckBox_1.Name)", is that returning a bool? You need to assign that bool to the checkbox:
Code:
myCheckbox.IsChecked = Restore(Of CheckBox)(Me.CheckBox_1.Name);
Also, all variables are reset when the page loads, so make sure you have set "myCheckbox.IsChecked" anywhere else on the page that could be called when the page loads.
Please, check the converted code of the above functions, to C#
Code:
public bool Backup(string token, object value)
{
if (null == value)
{
return false;
}
var store = PhoneApplicationService.Current.State;
if (store.ContainsKey(token))
{
store(token) = value;
}
else
{
store.Add(token, value);
}
return true;
}
public T Restore<T>(string token)
{
var store = PhoneApplicationService.Current.State;
if (! (store.ContainsKey(token)))
{
return default(T);
}
return (T)(store(token));
}
Do you think they are OK?
How should I call them ?
Clearly, the restore does not returns a boolean...
Honestly, I'm lost now!
Hope this helps to find the culprit.
It seems okay to me. You'll have to do some debugging. Set a breakpoint inside the Backup and Restore methods. Step through each line and make sure it's going to the line you expect it to and that the value being set is the correct one.
I haven't seen the tombstoning sample from MSDN, but can you get that to work? If so, is the generic method causing the problem? Or can you not get it to work at all?
Hi,
Sorry for the delay in getting back, but I was trying different codes and at least I found the cause.
Code:
Me.NavigationService.Navigate(New Uri("/PivotPage1.xaml?Name=" & "John", UriKind.Relative))
[B]Me.NavigationService.GoBack[/B]()
Me.NavigationService.Navigate(New Uri("/PivotPage1.xaml", UriKind.Relative))
Everything works fine, and the Checkbox state is saved/restored (in the Pivot Page) if I GO BACK using the GoBack hardware button or Me.NavigationService.GoBack
But, the state's dictionary entry is lost or ignored if I go back with the Navigate service (lines 1 and 3)...
Problem is that I need to get back with the query string...
The query string contains a value taken in the SelectedItem event of PAGE2's ListBox, and automatically once retrieved must go back.
I didn't know until know, that NavigationService.Navigate creates a new page instance or something like that in the backstack...
Any sugestions are welcomed!
Hi,
There are various methods you can use depending on the app's architecture. For example, you could have a 'shared' class that contains a shared field that holds the SelectedItem value. When the user selects the item, set the shared field's value and then when you go back, you can get the value from the shared field.
keyboardP said:
Hi,
There are various methods you can use depending on the app's architecture. For example, you could have a 'shared' class that contains a shared field that holds the SelectedItem value. When the user selects the item, set the shared field's value and then when you go back, you can get the value from the shared field.
Click to expand...
Click to collapse
So, no other way to cope with the navigation service?
It's a strange behaviour for sure...
Will try your ideas.
Thanks a lot for your reply!
GFR_2009 said:
So, no other way to cope with the navigation service?
It's a strange behaviour for sure...
Will try your ideas.
Thanks a lot for your reply!
Click to expand...
Click to collapse
There are other ways. For example, instead of using the PhoneApplicationService to store the tombstoning information, you could put it in a querystring for page 2. Then, in page 2, you could add the information from the previous page to a querystring AND the information of the selected item to the querystring. Navigate to page 1, with the querystring that contains information on what was there before and what the user selected. Tombstoning is there for when the user presses the hardware search button, home button, a phone call arrives etc.. It's not there for the navigation of the app. That's where querystrings, shared variables, binary serialization etc... come into play.
The concept of the navigation service is similar to a website. For example, when you submit something and then go back, it might still be there in the page state. However, if you submit something and then reload the previous page by typing it in the address bar, it becomes a completely new page as no state is stored.
keyboardP said:
There are other ways. For example, instead of using the PhoneApplicationService to store the tombstoning information, you could put it in a querystring for page 2. Then, in page 2, you could add the information from the previous page to a querystring AND the information of the selected item to the querystring. Navigate to page 1, with the querystring that contains information on what was there before and what the user selected. Tombstoning is there for when the user presses the hardware search button, home button, a phone call arrives etc.. It's not there for the navigation of the app. That's where querystrings, shared variables, binary serialization etc... come into play.
The concept of the navigation service is similar to a website. For example, when you submit something and then go back, it might still be there in the page state. However, if you submit something and then reload the previous page by typing it in the address bar, it becomes a completely new page as no state is stored.
Click to expand...
Click to collapse
Hi,
Will try your suggested approach, and thanks a lot for the last explanation on how the darn thing works.
Thanks again!
GFR_2009 said:
Hi,
Will try your suggested approach, and thanks a lot for the last explanation on how the darn thing works.
Thanks again!
Click to expand...
Click to collapse
You're welcome . It's one of those things that take a bit of time to understand, but starts to make sense. You might be interested in a free WP7 development ebook by Charles Petzold.
keyboardP said:
You're welcome . It's one of those things that take a bit of time to understand, but starts to make sense. You might be interested in a free WP7 development ebook by Charles Petzold.
Click to expand...
Click to collapse
I already have the book, but will need a deeper reading
So far, I've been testing your idea of using global classes and works ok.
Thanks a lot for being so cooperative, it's much appreciated!
GFR_2009 said:
I already have the book, but will need a deeper reading
So far, I've been testing your idea of using global classes and works ok.
Thanks a lot for being so cooperative, it's much appreciated!
Click to expand...
Click to collapse
No worries! If programming was super easy everyone would be doing it
keyboardP said:
No worries! If programming was super easy everyone would be doing it
Click to expand...
Click to collapse
Never said better!

Categories

Resources