[Q] Modeless CDialog and Today CommandBar - Windows Mobile Software Development

I write plug-in for «Today» for WM.
In initialization of my plug-in I create modeless windows – inherited from CDialog
class CMainForm : public CDialog
..........
m_Form = new CMainForm();
m_Form->Create(CMainForm::IDD, Parent);
m_Form->ShowWindow(SW_HIDE);
Depending on certain events I show this window: m_Form->ShowWindow(SW_SHOW);
Then user press OK/Cancel buttons I hide window: this->ShowWindow(SW_HIDE);
All work, but after start of my plug-in standard Windows CommandBar hide and it’s substituted with the CDialog panel.
How I can return standard Windows CommandBar?

Related

How To: Customize the Sliding Panels Homescreen

This was from the windows mobile team blog. More to follow but wanted to post it for those who don't read that.
Original link: http://blogs.msdn.com/windowsmobile/archive/2008/06/03/customizing-the-sliding-panel-homescreen.aspx
Customizing the Sliding Panel Homescreen
from Windows Mobile Team Blog by Jorge Peraza
Hi, my name is Jorge Peraza; I am a Developer on the Windows Mobile team that was responsible for the new “Sliding Panel” home screen in Windows Mobile 6.1.
When we were working on the visual style and functionality of the home screen we tried to make something that looked both professional and appealing while still showcasing all the information the user is going to need to know what’s important and requires attention. While I think the default design looks really cool, we added some customization features to enable users to make it their own.
Customizing the layout
The home screen layout can be modified using the same home.xml file from previous versions of WM, the schema of the file was extended to allow the customization of many of its elements, this includes the art assets that are used for most of the plug-ins.
When you open the SlidingPanel.home.xml file (inside \ApplicationData\Home) you will find the plug-in element that corresponds to the sliding panel home screen (its CLSID is {E9267CAB-02EE-4f37-8216-6BF6A8FF5A71}). All the child elements inside it are designed to tweak and customize the way the home screen will look.
The top level element is the plugins tag, this has one attribute called “Order” and it’s used to list the plug-ins that will be shown and the order they are going to be laid out on the screen.
The built in plug-in names are:
1)CClock – The big clock
2)CAppointments - The calendar plugin
3)CHome – The notifications plugin
4)CMyPhotos – The photos plugin
5)CMessage – The message center (this is off by default on all sliding panel built in layouts.
6)CMusic – The music plugin
7)Settings – The settings plug-in
8)Custom Plugin – Users can specify custom plug-ins with static content that can be displayed on the home screen.
For example, the XML snippet bellow moves the photos plug-in to the first position and enables the message center (which is turned off by default on both "Sliding Panel" and "Sliding Panel Media")
<plugin clsid="{E9267CAB-02EE-4f37-8216-6BF6A8FF5A71}" name="Bronze" height="266">
<Plugins Order="CMyPhotos;CClock;CMessage" />
</plugin>
There are many other ways of customizing the home screen using the plug-in settings like overriding the default images or even adding your own custom plug-ins that display static content, I'll post and updated entry latter on on how to do this in detail but for now, you can use the provided home.xml files to start experimenting with this.
The notifications plug-in and message center
In the sliding panel home screen, the notifications plug-in by default serves as a dual-purpose notifications/gateway to all you phone/message accounts where every page represents one account (so, if you have multiple notifications in one category they will be shown as one summary page).
There is however an alternative behavior where individual notifications are added as independent pages (Similar to what the T-Mobile shadow home screen does) and the plug-in only shows accounts that have new notifications in them. One cool feature of this alternate behavior is that each individual notification can be dismissed without having to leave the home screen.
You can enable this alternative behavior by setting the following registry key to a value other than 2 (The actual value indicates how many pages of each notification type will be added to the home screen before collapsing them into a summary page. We have tested 2 and 5 but feel free to experiment with other values)
[HKLM\Software\Microsoft\Chome\Chome]
PageCollapseThreshold: DWORD
Note that this prevents you from being able to access the email/phone account data if there are no notifications for it. If you still want to be able to do that you can always re-enable the message center as described in the previous section as a separate plug-in.
There is one more behavioral change you can make that allows you to “dock” the condensed view of the first plug-in to the top of the screen when it is not active, we added this for people like me that want to have the clock always visible. To enable just set the following registry key to “1”
[HKLM\Software\Microsoft\Chome]
DockOperatorBar: DWORD
Advanced layout modification
There are even more advanced things you can do to further tweak the look of the home screen but it is unsupported by Microsoft at this moment so you’ll have to experiment on your own J (Hint, look at the following files \windows\CHome_240x320.cpr and \windows\CHome_320x240.cpr).
----------------------------------------------------------------------------------------------------
Thanks to djNutz for posting this information & OrganicM for his efforts.
I wanted to create a post with info about what the different keys do in the CHome section of the registry. So, I'll start with a brand new one, that I bet nobody knows about....
[HKLM\Software\Microsoft\Chome\Chome]
PageCollapseThreshold: 2 or 5 (DWORD Value)
This will collapse your Notifications panel to only show active notifications. You can enable this alternative behavior by setting the following registry key to a value other than 2 (The actual value indicates how many pages of each notification type will be added to the home screen before collapsing them into a summary page. 2 and 5 were tested and work pretty well.
More to come of course....
should this change be made to the security section too, or does that matter? actually, do changes to the security section ever matter, cause they seem to apply even when you only edit the software section.
p.s.
i'm pretty sure people are gonna ask, so maybe i'll save some trouble instead of looking like an ass by answering preemptively. This DWORD value must be created with your registry editor, it's not already there, at least on ricky v24.
2 = default or normal (i assume cause it looks the same as before) and 5 = condensed.
But for the rest of us who don't have the time to be on every WM blog and forum at once here's my favorite:
To “dock” the condensed view of the first plug-in to the top of the screen when it is not active, set the following registry key to “1”
[HKLM\Software\Microsoft\Chome]
DockOperatorBar: DWORD
This is so you can have the clock always visible, no matter which panel you're on. You could also set it so that CHome Weather's compact view is always on top. Whatever plugin is first on the list.
More info from MS coming down the pipe:
We can get the day of the week on the clock plugin at the top of CHome by doing this:
Replace this portion...
<!-- Date --> <Text ID="Date" Left="180" Top="83" Width="110" Height="19" FontFamily="Segoe Condensed" FontSize="9" FontStyle="Bold" Wrap="False" HorizontalAlignment="Left" Trimming="EllipsisCharacter"></Text>
With this!
<!-- Date -->
<Text ID="Date" Left="180" Top="83" Width="110" Height="19" FontFamily="Segoe Condensed" FontSize="9" FontStyle="Bold" Wrap="False" HorizontalAlignment="Left" Trimming="EllipsisCharacter"></Text>
<Text ID="Day of Week" Left="65" Top="83" Width="110" Height="19" FontFamily="Segoe Condensed" FontSize="9" FontStyle="Bold" Wrap="False" HorizontalAlignment="Right" Trimming="EllipsisCharacter"></Text>
I will incorporate this in Chome Weather fore sure!
Here you go, the first is my Home
2nd is Scroll Down once
3rd is Scroll Down twice
4th is Scroll Down Thrice
heh
Edit: Tried Month in cpr, no luck.
will keep trying
I'm glad people are finally getting this information out. It makes customization that much easier. I'm adding the tips to the wiki as well, as they come out.
How to Reload the Homescreen
I have two questions:
1. After editing my CHome cpr file, how do I reload the homescreen without having to reboot the device?
2. How can I show any text on the clock panel? Regular text is defined by Text ID = "xxxxx", where xxxxx is something like Time, Network Name, etc. However, suppose I want to have the text "Knowledge Rules", how do I set it up in XML?
I have very little programming and Excalibur experience. So, I apologize if these questions are too naive or have been answered before.
Thanks a lot in advance.
you can use this if you dont use OrganicM Chome Weather
I don't think Microsoft has put out much documentation on the sliding panels plugin yet. Most of the CHome configurations use
Code:
TextID="text 1"
as the delimiter for static text. But that's not to say that the clock plugin will recognize that as a valid section. Could work. Could make your phone useless.
beartard said:
I don't think Microsoft has put out much documentation on the sliding panels plugin yet. Most of the CHome configurations use
Code:
TextID="text 1"
as the delimiter for static text. But that's not to say that the clock plugin will recognize that as a valid section. Could work. Could make your phone useless.
Click to expand...
Click to collapse
I do not understand. How do I make the phone know that:
text 1 = Knowledge Rules?
Typical syntax seems to be Text ID = "xxxx", where xxxx is a variable name, which is recognized by the device. If Text 1 is a valid variable for the device, how do I assign it a value? Am I rambling here?
No, you're not rambling. As far as the information coming from Microsoft and disseminated here on this site goes, it's a best guess right now.
someone at msdn blog asked the same question.
Someone at msdn blog asked the same question. Let's wait to see if we get an answer from there...
From http://blogs.msdn.com/windowsmobile...ustomizing-the-sliding-panel-homescreen.aspx:
"Jorgeba, thanks for taking the time to educate your user. I have some questions.
How do you change the text in the condense clock? The .cpr file has Text ID="Text 1". How is "Text 1" define? I would love to add the date to the condense layout.
The ActionURL and Softkey2 URL in the Appointments plug-in always open calendar in the today view. Is there a way to make one of the button opens calendar in the month view? Setting the default view for calendar does not help."
Easy as pie......
If you know what you are doing.
If you have any xml experience,then you'll know how to adjust x and y values to position things in different places. Yes, you can do that. Just change x=whatever and y=whatever to where you would like them to be. Just know this means that it will start on the left and move x pixels over and y pixels down. If you put in negative values, it will shift them in the opposite direction.
Eg. x=-whatever will move it to the left vs a + value which will move it to the right. Same for y=
Also, you can adjust the valignment and halignment to center, left, or right.
Have fun with these. They apply to everything in your cpr (That's the layout for your homescreen.It's in your \Windows directory on your phone).I mean everything, from where your network displays, right down to your pictures.
That's it. Have fun!
jaymit said:
Hi,
Sorry Im kind of a newbie :s, is it possible to edit home screen panels? I wanted to change the layout and look of the clock plugin.
Thanks!
Click to expand...
Click to collapse
Does anybody know how to change font color for certain panels or certain lines of text in the panel? Is it only possible for the whole homescreen?
As far as I know even as far as old xml coding works, you can only change a font color for a selected word or unselected word. Meaning, if you have the old 6.0 your plugins that are selected could have a different color, but unselected could be another color. This applied to the entire homescreen. I have not seen different colors for different plugins, since each panel style is basically its own plugin (each has its own unique GUID), then I doubt you can change font color for each plugin. You can more than likely only change the active selected panel and inactive panel fonts. I am not sure what their titles are in the cpr, but I know that in the old 6.0, the homecolor was one of the fonts colors and the other was called something else.
Eventhough this is 6.1, it doesn't look like much has changed as far as the fonts color goes. You could, however, always try adding a "fontcolor=" command in the cpr and a hex code and try it, to see if it works.
Hope this helps.
Edit your registry or get CHome Config
Both do the same thing. You want to change the plugin order for CHome. It's located in HKLM\Security\CHome\Default Settings and in HKLM\SOFTWARE\Microsoft\CHome. Edit the order you want your plugins to go. Reboot your phone and the new edits should be reflected in your homescreen layout. If you are having trouble cause this is new. Just search this thread for CHome Configurator. It's stickied at the top of this forum. Download it and it will let you select the order in a much easier way. Make sure you reboot, though, or else your changes won't show. Hope this fixes your problem. Later.
tae-xda said:
How to change the default location for where the CMyPhotos plugin
Click to expand...
Click to collapse
rollingondubs1 said:
I have that already, All my games are under a folder which i cant make it as a action url
Click to expand...
Click to collapse
try this
"ACTIONURL" = "\Windows\Start Menu\Games\xxxxx xxxx.lnk
or this
"ACTIONURL" = "\windows\fexplore.exe; \windows\start menu\games"
Yes you can
One last time, I think I've figured out how to help you.
1. Open Chome Config.
2. Scroll to MyApplication and select it with your center button.
3. Scroll to any page you want to edit. Then scroll down to where it says ActionURL. Press menu.
4. Once in the menu select the "1 Change URL" item.
5. Once you have selected that it will take you to a file explorer. Go to \Windows\Start Menu\Games. This is where your games should be. If not, then wherever you store, your games, navigate yourself to that folder and select the file you want.
I think this should cover it. Hope this solved your problem. HOLLA!!!!
rollingondubs1 said:
I have that already, All my games are under a folder which i cant make it as a action url
Click to expand...
Click to collapse
How to change the location of CMyPhoto to \Storage Card\My Documents\My Picturs

Quickmenu 2.7 on HD.....Not working?

Hey all,
I've just tried installing the latest version of Quickmenu. Has anyone else tried this piece of software? I was going to say excellent but unfortunately after a while my entire top bar (Start, Task Manager, Custom Notification icons, Signal level etc...) is no longer responding.
The only fix is power cycle. I can't even do a soft reset through SPB Mobile Shell. SPB Mobile shell is still responding and I can select the soft reset icon but I just get the spinning windows busy logo and then I'm back where I was.
Is there another Start Menu replacement that can give cascading menus like Quickmenu? I'm not fussed about all the extra bells and whistles just a cascading menu program would suffice.
Anyone else out there using anything on their Blackstone (Touch HD) ??
I've got it installed on mine... orange uk. Works a charm. I've also got sdk certs and topbar icons... but qm2.7 seems pretty stable. maybe you got something clashing? Can't really help 'cept to say it does work so keep trying.
It works a charm for me too: version 2.7.387.1527
What settings are you guys using as far as taking control of the system i.e. X-Button, Active Sync, OK Close etc..etc..
Thanks for the replies!
Also, When I choose Close Program - Task Manager I get Memory Settings???
General
----------------------
Auto start = yes
cache file icons = yes
replace start = yes
register win key = no
right arrow = no
"ok" key to close = no
x-button = no
long press = suspend
popup edit menu = yes
close activesync = yes (but doesn't work)
Exclude
---------------------
manile = both not
pocketcm = not close
View
---------------------
show Q = no
show battery = no
show X = no
the rest as you want
Menu items
--------------------
as you want (keep "Frequenters" checked otherwise you won't see the menu the right way)
Command
---------------------
ONLY if you don't see setting in menu, use this function to create a shortcut fon settings, then create a "settings" folder in start menu and put the shortcut in it
-------------
that's all.

Using WM6.5.x Control styles in own (.NET) programs?

Hello,
since WM6.5.3 the standard Controls like Buttons, Comboboxes, TabControls, Checkboxes etc. have a new Style with gradient Backgrounds and sometimes rounded edges.
If you develop programs with the .NET CF you will get the boring old style. Is there any way to enable the new style for .NET applications?
The only thing I found was this "hack" for the TabControl:
mobileworld.appamundi.com/blogs/peterfoot/archive/2009/09/17/windows-mobile-6-5-tab-control.aspx
(sorry, seems that I'm not allowed to post outside links)
I searched a lot for this but even the documentation from Microsoft gives no hint how to do this.
There is also a new control in many system control panels which replaces the TabControl (the navigation thing at top of the form for example in sounds and notification settings). Is there any chance to use this control in my own programs?
It is really annoying that Microsoft has developed a new themeable style for their controls and nobody can use it
Thanks a lot
Markus
You can but it requires overriding the controls paint events and imo is not worth the hassle. If you want fancy looking controls then you would be better off with 3rd party controls. There's several options out there and some are free. Read about some at http://forum.xda-developers.com/showthread.php?t=616838
If you want to work with the native controls and spruce them up a bit check out http://code.msdn.microsoft.com/uiframework for some guidance.
Ren13B said:
You can but it requires overriding the controls paint events and imo is not orth the hassle.
Click to expand...
Click to collapse
thanks for your answer but I don't want to create custom controls or use some 3rd party controls. I want to use the standard controls but with the WM6.5.x style.
Microsoft is really stupid. They were on a good way with 6.5.x. The user interface of the standard apps is mostly consistent and finger friendly. But they forget 3rd party developers now completely. I want to be able to create apps with the system look and feel but it seems that it is not possible. So my own applications have always an inconsistent look when I use standard controls. I always get the old style but when I open a messagebox then I get buttons in the new style.
Microsoft, this is really crap!
You'll have to wait for Windows Phone 7 if you want perfect consistency. Microsoft isn't going to update the controls for 6.5.
Hey there!
Today I did some research into controls, and I found out how to enable 6.5.3 style for buttons and checkboxes. You have to:
edit2: for dialogs - open .rc file in a text editor, and find your dialog, then after a line beggining with STYLE add a line with following contents:
Code:
EXSTYLE 0x1800000
Compile it and run. You should get 6.5.3 look and feel on existing controls without changing them!
Or if you want to create controls in runtime (works good for buttons, checkboxes/radio buttons look ugly):
1) call SHInitExtraControls()
2) when creating a button/checkbox use class TTBUTTON and make sure its style is combined with 0x8000
3) Use 'em like normal buttons.
Now it's time for listboxes & others...
edit2: To mimic 6.5.3 listbox behavior you have to set item height to 64 (or 32 for (W)QVGA), for example in this way:
Code:
SendDlgItemMessage(hwndDlg, IDC_COMBO1, CB_SETITEMHEIGHT, -1, 64);
SendDlgItemMessage(hwndDlg, IDC_COMBO1, CB_SETITEMHEIGHT, 0, 64);
To expand list views, use a empty image list with a proper image height (64 or 32), for example:
Code:
HIMAGELIST il;
il = ImageList_Create(1, 64, ILC_COLOR, 0, 1);
SendDlgItemMessage(hwnd, IDC_LIST1, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM) il);
edit: Oops, forgot you want it in .NET. Quick investigation lead me to a sad fact: .NET controls have the wrong window class. But if .NET dialogs are stored in resources there is hope. So I would be grateful if someone post here a compiled .NET application which would show a dialog with a button linked to some simple action. I might try to modify it for 6.5.3 style.

[Q] VB and the ApplicationBar

Using VB, im trying to add an application bar in the code (rather than xaml). I have the following code:
Code:
Public Sub New()
InitializeComponent()
Dim appBar As ApplicationBar
appBar = New ApplicationBar
appBar.IsMenuEnabled = True
appBar.IsVisible = True
appBar.Opacity = 1
Dim icon As New Uri("/Images/expand.png", UriKind.Relative)
Dim cmdStart As New ApplicationBarIconButton(icon)
cmdStart.Text = "Start"
'AddHandler (cmdStart.Click), test_click()
appBar.Buttons.Add(cmdStart)
' Set the data context of the listbox control to the sample data
DataContext = App.ViewModel
End Sub
However when i run it in the emulator there is no application bar! No error either. It is a pivot application also but this shouldnt make a difference surely? any ideas?
The application bar is accessible via the ApplicationBar property of the Page class you're deriving from. You don't need to create your own instance.
Thanks, I actually figured this out just after i posted the question. Thanks anyway.

How make HELLO WORLD on the WM6.1 ???

Who can write Step by Step instruction by C++/VisualStudio 2008 ? for writing Hello World apps And simple actions of work with forms???
You can start here...http://www.hitmill.com/programming/cpp/helloWorld.htm
Remember a search engine is your friend.
Hope that I have help you.
In C++ you have the choice of WIN 32, ATL and MFC programming models. They are all different.
If you are using standard windows forms items ie buttons, editboxes, dropdowns etc. C# is a LOT easier.
stephj said:
If you are using standard windows forms items ie buttons, editboxes, dropdowns etc. C# is a LOT easier.
Click to expand...
Click to collapse
It is indeed much easier for "Hello World" type applications. For more complicated things, poor performance and lack of direct access to the native API begins to add up.
The original poster probably has some specific problem, the solution to which he hopes to find in a step-by-step tutorial. If he still has not been able to solve it, it might help to describe it to us.
O.K........
Over the next few posts, (Rome wasn't built in a day!), this will build into a step by step tutorial in how to create a basic WIN32 application. As a start we will use the C# .Net solution I wrote in reply to this post:
http://forum.xda-developers.com/showthread.php?t=1435629
The original request was for an application that calculates the check digit for an intermodal container number. For the uninitiated, intermodal containers are the ubiquitous 20ft and 40ft metal boxes that dominate the shipping industry.
All containers have an eleven digit serial number of the form:
ABCD 123456 7
Where ABC is the code for the container's owner, and D is the Category Identifier, almost always a 'U'. 123456 is the serial number of the box and the final number '7' is the checksum digit which is calculated from the previous 10 characters. When keying in container numbers into computer systems etc, it can be used to quickly check whether the container number is valid before further processing is done. The same thing applies to the last digit of your credit card number, it is calculated from the previous 15 numbers.
Container numbers conform to ISO6346 and more can be read here http://en.wikipedia.org/wiki/ISO_6346
We will build a WIN32 C++ Mobile 6 application to calculate the check digit from those given in a text box on the screen.
Validation will be minimal, if the user enters anything but characters of the form AAAA999999 in the textbox, nothing appears in the check digit box. When valid, the checkdigit magically appears.
You will need:- Visual Studio Professional 2008, not the express version, and an installed Windows Mobile 6.0 SDK
The Express version of VS cannot target mobile devices. VS 2003/5 can also be used, as well as earlier or later versions of the SDK, but you will encounter slight differences in VS or the SDK, that you will have to fight your way through yourself.
The finished application will look something like the attached image.
Under Win32, there is no drag and drop toolbox, all controls have to be created from scratch. All good fun, so roll up your sleeves, break out the birch twigs and let the self-flagellation begin.......
Right!.....Let's go............
From VS2008 select
File -> New -> Project
Select C++, Smart Device and Win32 Smart Device Project. Select the destination for the project and name it IS06346. See image 01.
Click OK
On the Platforms submenu of the next screen add the Windows Mobile 6.0 SDK to the project and remove the others. See image 02
........and, on the 'Application Settings' submenu, make sure the Windows Application radio button is on, and all others are off. See image 03
Click Finish. The VS wizard will create all the basic files we need under the directory given above.
In fact, pressing F5 should build this project and run it in the emulator. The application does very little at this stage, nothing to be precise, but it should work........... See 04
The main program is ISO3486.cpp This shell program is some 250 lines of code, most of it is needed for a "do nothing" program, but it boils down into five main functions.
WinMain() The entry point of the program, where the operating system will call it on initial load. Leave it alone.
InitInstance() Called immediately by WinMain and where the program creates its initial window etc. We will add a few bits of extra initialization here.
MyRegisterClass() Called by InitInstance to register the window class, just before the initial window is created. Leave it alone unless you really know what you are doing.
WndProc() The message processing loop for the main/parent window. Any windows event will be fired at this function as a Windows Message, it is up to us to process the ones we need. A few variables will go in here. All the original WM2003 "Hello World" program did, in the EVC based SDK, was to intercept the WM_PAINT message, find the client area of the screen, and draw the text "Hello World" in the middle of it.
About() The message processing loop for the About dialog box. We will be quite happy with the default action so we'll leave it alone.
To Do:
1.) Add reference to <string.h>
2.) Create two text boxes and display them. Limit the entry to 10 characters on the main edit box and disable input on the second check digit box.
3) Draw an "Enter container number:" text label above the edit boxes in response to the WM_PAINT message. The edit boxes will draw themselves when required.
4.) Intercept the EN_CHANGE message from the main edit box. If the length of the text in the box is 10 characters long, uppercase it, and if it is valid, generate the checksum and display it in the checksum box, otherwise clear the checksum box. Replace the textbox text with its uppercase value, but do not respond the the EN_CHANGE message generated by this change, as this will trigger an infinite shower of EN_CHANGE messages.
When this is done, we will have a working application.
To be continued.....................
Next...........
Let’s work our way down the TODO: list above.
1.) Add reference to “string.h”:
Later on we are going to use a call to towupper() to convert the input into uppercase. It is defined in string.h, so we have to add this to the source file.
At the top of the ISO6346.CPP after the line
Code:
#include "ISO6346.h"
Add the line:
Code:
#include "string.h"
2.) Create two text boxes and display them......
We will create two windows as text boxes, but we will save their handles as global variables as they are referenced from more than one function. While we are at it we also need a global Boolean variable to prevent the uppercased replacement from causing the runaway reaction mentioned above.
After:
Code:
HINSTANCE g_hInst; // current instance
HWND g_hWndMenuBar; // menu bar handle
Add:
Code:
HWND g_hWndText,g_hWndCheck;
bool g_Updating;
Now let’s create the text edit boxes. You may already know this, or this may be an eye opener, but all edit controls are actually windows in their own right, albeit that they are child windows of the main form.
In InitInstance() after:
Code:
if (!hWnd)
{
return FALSE;
}
add:
Code:
g_hWndText= CreateWindow(TEXT("EDIT"),NULL,WS_CHILD | WS_BORDER,40,50,110,20,hWnd,NULL,hInstance,NULL);
g_hWndCheck=CreateWindow(TEXT("EDIT"),NULL,WS_CHILD | WS_BORDER, 160,50,20,20,hWnd,NULL,hInstance,NULL);
This creates the text edit boxes. As yet they won’t be displayed, but we have to tweak them first. We want to disable the checkdigit box, so that the user cannot type anything into it as we will set it with the correct value when a valid container number is entered in the text box. We will disable it by calling the EnableWindow() function.
We also need to set the size of the text edit window to 10 characters. Under MFC and .NET this is a hoot, as it already a property of the edit control object, which has been conveniently wrappered for us, and we can just set that property. Here in the world of Win32, it is not quite so simple. We have to fire an EM_SETLIMITTEXT message at the window, to tell it that that is what we want. While we are at it, let's set the global g_Updating variable to be false, ready for use later, and here is as good a place as any to do it.
After the CreateWindow() lines we have just added, add the next three lines to do the above.
Code:
SendMessage(g_hWndText,EM_SETLIMITTEXT,10,0);
EnableWindow(g_hWndCheck,false);
g_Updating=false;
Now the windows exist as we want them, all we have to do is display them. At the bottom of the InitInstance() function after
Code:
ShowWindow(hWnd, nCmdShow);
add
Code:
ShowWindow(g_hWndText, nCmdShow);
ShowWindow(g_hWndCheck, nCmdShow);
The main window will now look after them and control them as required. Marvellous!
3) Draw an "Enter container number:" text label............
Now we need a label above the two boxes to tell the user to type a valid container number number into the text box. From the resource view of the project, open the String Table folder in ISO6346ppc.rc then open the String Table object. Click in the blank entry at the bottom and change the ID to IDS_ENTER and the Caption to "Enter container number:" Don't worry about the what the value is, if it is not '3', as the IDE will take care of it.
To get it drawn on the form, we will have to add it to the WM_PAINT event of the main window. We'll need a RECT structure to describe where we want the text to go, a buffer to store the string and while we are here let's add the function variables we are going to need later. At the top of the WndProc() function:
After:
Code:
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
add
Code:
TCHAR c,szBuffer[MAX_LOADSTRING];
RECT rt;
int i,j,k;
bool valid;
i,j and k are general variables for calculating the check digit. szBuffer is used to hold the "Enter container number:" string in WM_PAINT, and also for the contents of the edit box when it changes. As these two events will not occur at the same time, we can get away with it having a dual personality. Variable 'c' is used to read the string one character at a time and 'valid' is set to false if the the container number is not in the correct format.
Replace the TODO: line in the WM_PAINT handler
Code:
// TODO: Add any drawing code here...
with:
Code:
rt.top=20;
rt.bottom=40;
rt.left=40;
rt.right=180;
LoadString(g_hInst,IDS_ENTER,szBuffer,MAX_LOADSTRING);
DrawText(hdc,szBuffer,wcslen(szBuffer),&rt,0);
Now when the form is drawn, the label will appear in the right place.
4.) Intercept the EN_CHANGE message from the main edit box..........
There is no easy way to do the next bit step-by-step, so we will just do it, I'll explain later.........
Replace the standard code for the response to the WM_COMMAND message:
Code:
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_HELP_ABOUT:
DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, About);
break;
case IDM_OK:
SendMessage (hWnd, WM_CLOSE, 0, 0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
with this:
Code:
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_HELP_ABOUT:
DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDOK:
SendMessage (hWnd, WM_CLOSE, 0, 0);
break;
}
switch (wmEvent)
{
case EN_CHANGE:
if(g_hWndText == (HWND) lParam && !g_Updating)
{
GetWindowText(g_hWndText, szBuffer,MAX_LOADSTRING);
if(wcslen(szBuffer)==10)
{
k=0;
valid=true;
for(i=0; i<10; i++)
{
c=szBuffer[i]=towupper(szBuffer[i]);
if((i<4 && (c<'A' || c>'Z')) || (i>3 && (c<'0' || c>'9')))
valid = false;
j=int(c);
if (j > 64 && j < 91)
k += ((j - 55) + (j - 56) / 10) << i;
else
k += (j - 48) << i;
}
if(valid)
{
// Calculate final check digit
k = ((k % 11) % 10);
// Do not process the following update
g_Updating = true;
SetWindowText(g_hWndText,szBuffer);
g_Updating = false;
// Set check window to correct value
szBuffer[0]='0'+k;
szBuffer[1]='\0';
SetWindowText(g_hWndCheck,szBuffer);
// Position cursor at end of edit field.
SendMessage(g_hWndText,EM_SETSEL,10,10);
}
else
SetWindowText(g_hWndCheck,TEXT(""));
}
else
SetWindowText(g_hWndCheck,TEXT(""));
}
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
When the text edit box contents are changed, a EN_CHANGE message arrives at the parent window. It appears as a WM_COMMAND message with the wmEvent parameter containing the EN_CHANGE identifier, together with the handle of the window that generated the message. That is why the second 'switch' code exists to trap the EN_CHANGE event message.
If the EN_CHANGE message came from the Text edit window, not the Checksum window, then get the text within it. If the length is 10 characters long, then process the string. The variable k is used as a running total for the checksum. If after processing all 10 characters, the string is still valid, it is converted modulo 11 and then modulo 10 into the final checksum number. The checksum edit box is then updated with this value. The contents of the Edit box are replaced with its uppercase value. In doing so, we will cause another EN_CHANGE message to be sent to the parent window, which would cause this function to be executed again, and so on and so forth, causing an infinite shower of messages. To prevent this, we set the global variable g_Updating to true before making the change, and then setting it to false immediately afterwards. The test in the first line of the EN_CHANGE processing code, does not execute at all if g_Updating is true, thereby preventing this problem.
Build the final program, and test it in the emulator. Switch the build to 'Release' and the target to Windows Mobile Device, and run the executable on your device.
The complete ISO6346.cpp file is included in the attached zip file.
Here endeth the lesson...........
As a continuation, we will build the whole thing again from scratch, but next time using the Microsoft Foundation Class, MFC.
Watch this space..................
Don Reba said:
It is indeed much easier for "Hello World" type applications. For more complicated things, poor performance and lack of direct access to the native API begins to add up.
Click to expand...
Click to collapse
I totally agree with this! And worst thing is you can neither use a resource hacker tool nor a dependency walker tool, if you want to inspect a .NET CF application.
Using MFC......
From VS2008 as before select File->New->Project then select Visual C++, Smart Device, and MFC Smart Device Application.
Name it ISO6346 as before, and click OK. See image 01
On the platforms submenu select the Windows Mobile 6.0 SDK as before. See image 02
On the Application Type submenu, select the "Dialog Based" and "Use MFC in a static Library" radio buttons. See Image 03
By default the application comes with two dialog boxes for portrait and landscape but in our case this is complete overkill. We will get rid of the Landscape (Wide) dialog box.
In the Dialog folder of the resource view of ISO6346ppc.rc, delete the IDD_ISO6346_DIALOG_WIDE entry. See image 04.
To get this past the compiler, we will have to tidy it up a bit. In ISO6346Dlg.cpp delete the following sections of code.
Code:
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
void CISO6346Dlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
if (AfxIsDRAEnabled())
{
DRA::RelayoutDialog(
AfxGetResourceHandle(),
this->m_hWnd,
DRA::GetDisplayMode() != DRA::Portrait ?
MAKEINTRESOURCE(IDD_ISO6346_DIALOG_WIDE) :
MAKEINTRESOURCE(IDD_ISO6346_DIALOG));
}
}
#endif
and also:
Code:
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
ON_WM_SIZE()
#endif
Double Click in the IDD_ISO6346_DIALOG entry to open it up in the main window. Click on the "TODO: Place dialog controls here" label and change its caption to "Enter container number:", and position it near the top of the dialog box. From the Toolbox view, drop two edit controls on to the dialog box, under the above label. See image 05. Right click on the first box and select Add Variable. Name the first box edtText and click Finish. See image 06. Do the same for the second box and name it edtCheck. Notice that the wizard has added entries for the DoDataExchange(CDataExchange* pDX) function.
In OnInitDialog() after the line
Code:
// TODO: Add extra initialization here
Add:
Code:
Updating=false;
edtText.LimitText(10);
edtCheck.SetReadOnly();
Note that an Edit Control has more useful methods to call than the Win32 method above, where setting the text limit of the control has to be done by sending windows messages to it.
Right click on the Text Edit Box control and select "Add event handler..." select the EN_CHANGE message, take the default event handler function name, and click the "Add and Edit" button. See image 07 In ISO6346Dlg.h notice that the wizard has added the two edit boxes at the bottom of the file, and also added the message map thus:
Code:
public:
CEdit edtText;
CEdit edtCheck;
afx_msg void OnEnChangeEdit1();
In the //Implementation section of the same file after
Code:
HICON m_hIcon;
add:
Code:
bool Updating;
This will be used as before to prevent an infinite cascade of messages.
In the OnChangeEdit1() function add the following code:
Code:
int i,j,k;
wchar_t c;
bool valid;
CString strText,strCheck;
if(!Updating)
{
if(edtText.LineLength(0)==10)
{
edtText.GetLine(0,strText.GetBuffer(10),10);
strText.ReleaseBuffer(-1);
strText.MakeUpper();
k=0;
valid = true;
// Check the contents are of the form ABCD123456
for(i=0; i<10; i++)
{
c=strText.GetAt(i);
j=int(c);
if((i<4 && (c<'A' || c>'Z')) || (i>3 && (c<'0' || c>'9')))
valid = false;
if (j > 64 && j < 91)
k += ((j - 55) + (j - 56) / 10) << i;
else
k += (j - 48) << i;
}
if(valid)
{
// Calculate final check digit
k = ((k % 11) % 10);
strCheck.GetBufferSetLength(1);
strCheck.SetAt(0,'0'+k);
strCheck.ReleaseBuffer(-1);
edtCheck.SetWindowTextW(strCheck);
Updating = true;
// Do not process the following update
edtText.SetWindowTextW(strText);
Updating = false;
// Position cursor at end of edit field.
edtText.SetSel(10,10,0);
}
else //Invalid Not ABCD123456 - clear the check digit field
edtCheck.SetWindowTextW(TEXT(""));
}
else // Invalid - Not 10 char long - clear the check digit field
edtCheck.SetWindowTextW(TEXT(""));
}
This time we use CString objects to get/set the contents of the edit controls.
Right! That's it. Compile it and run it, either in the emulator or on the device.
See image 08. Notice that as this a dialog application, there are no menu buttons. When the [X] button is pressed the program terminates.
As another interesting point, compare the sizes of the two release executables. The Win32 version is around 8.5kb, that of the MFC version is around 167kb, both launch pretty damned quickly. Compare that with the . NET C# executable from the original post. That is around 9kb in size, but it takes your device around three seconds to shove it through the JiT compiler in order to able to run it, and that is for only a tiny .NET program.

Categories

Resources