Hi there,
I'm writing an OpenGL ES 1.0 application using C#, .Net 2.0 and this .Net OpenGL ES wrapper: www .koushikdutta.com/2008/08/net-compact-framework-wrapper-for.html. My phone is a Touch Pro2 (duh), with WM 6.5.5 (build 23549, EnergyRom).
My app is working fine, with the exception of the slideout keyboard. After I slide it out, it renders a couple of frames (20 or so) and then it freezes on the first OpenGL call in the next frame (which is glViewport in my case).
Is there anything I'm doing wrong, or is this a driver issue with my phone?
Here's my setup code:
Code:
display = egl.GetDisplay(EGLNativeDisplayType.Default);
int major, minor;
egl.Initialize(display, out major, out minor);
EGLConfig[] configs = new EGLConfig[10];
int[] attribList = new int[]
{
egl.EGL_RED_SIZE, egl.EGL_DONT_CARE,
egl.EGL_GREEN_SIZE, egl.EGL_DONT_CARE,
egl.EGL_BLUE_SIZE, egl.EGL_DONT_CARE,
egl.EGL_DEPTH_SIZE, 16,
egl.EGL_SURFACE_TYPE, egl.EGL_WINDOW_BIT,
egl.EGL_STENCIL_SIZE, egl.EGL_DONT_CARE,
egl.EGL_NONE, egl.EGL_NONE
};
int numConfig;
if (!egl.ChooseConfig(display, attribList, configs, configs.Length, out numConfig) || numConfig < 1)
throw new InvalidOperationException("Unable to choose config.");
config = configs[0];
context = egl.CreateContext(display, config, EGLContext.None, null);
surface = egl.CreateWindowSurface(display, config, windowHandle, null);
if (surface.Pointer == EGLSurface.None.Pointer)
throw new InvalidOperationException("Can't create window surface.");
int width, height;
egl.QuerySurface(display, surface, egl.EGL_WIDTH, out width);
egl.QuerySurface(display, surface, egl.EGL_HEIGHT, out height);
System.Diagnostics.Debug.WriteLine("Surface size: " + width + " x " + height);
egl.MakeCurrent(display, surface, surface, context);
And this is what I do when the control is resized:
Code:
egl.MakeCurrent(display, EGLSurface.None, EGLSurface.None, context);
egl.DestroySurface(display, surface);
surface = egl.CreateWindowSurface(display, config, hWnd, null);
if (surface.Pointer == EGLSurface.None.Pointer)
throw new InvalidOperationException("Can't create window surface.");
int width, height;
egl.QuerySurface(display, surface, egl.EGL_WIDTH, out width);
egl.QuerySurface(display, surface, egl.EGL_HEIGHT, out height);
System.Diagnostics.Debug.WriteLine("Surface size: " + width + " x " + height);
egl.MakeCurrent(display, surface, surface, context);
What I'm seeing is as follows. I run the app and it renders normally. Then I slide out the keyboard, and the window is resized. The surface is recreated with the appropriate settings, and I see a 20 or so frames being rendered. Then, all of a sudden, I see what looks like an old framebuffer from before the resize taking up the left half the screen (since it was merely 480 pixels wide), right half black, and the application freezes. Breaking in the debugger reveals it hangs on the first OpenGL call in that frame (glViewport). Shift-f5 doesn't close the app, I can still pop up the start menu and the call window using the physical buttons, but the home screen does not render anything (any contents that happened to be on the screen, the start menu for example, just stay there), nor do applications like arkswitch and advanced task manager. I have to softreset my phone before I can use it again.
What, if any, am I doing wrong?
The problem seems to be with manila.exe. If I kill that app, it works fine.
Related
Hello,
i have an application, programmed in C#. I wanna that the size of the gui will automatically adapt to the size of the phone on which the application get used.
How can I do this?
In the Paint() event of the form examine its ClientSize property. This is the size of the client (White) area of the screen. It is itself a Size object with Height and Width integer properties, this.ClientSize.Width and this.ClientSize.Height
Use these values to position/resize your objects on the screen, by changing their Size and Location (Left and Top) properties, so that they fit in this area.
This event occurs before the Paint() event of the child objects, so they will be repositioned/resized before they themselves are drawn.
To be clever, reposition and resize screen objects, scaled to the screen size at run time, not values hardcoded at development time.
This technique can also detect a change of orientation, the values of Height and Width change over! If you want to be smart, handle this as well, and your app should be starting look pretty damned professional. A bit of work and it should look good on all screen sizes. Test them out against the SDK's emulator images for a range of device screen sizes.
The following code example positions the label in the correct place. Hey Diddle Diddle, slap bang in the middle!
Code:
private void Form1_Paint(object sender, PaintEventArgs e)
{
label1.Left = (this.ClientSize.Width - label1.Size.Width) / 2;
label1.Top = (this.ClientSize.Height - label1.Size.Height) / 2;
label1.Text = this.ClientSize.Width.ToString() + " x " + this.ClientSize.Height.ToString();
}
do you have to do this with every object you put on it? Seems like a lot of code. (also im doing this in VB so far..)
I'm afraid so. But it's worth the effort. Also it will run on all screen sizes, see image, and also the oddball ones they haven't thought of yet!
Change 'this.' to 'me.' and omit the C# end of line character ';' and it's now in VB.
Does your form property AutoScaleMode is set to AutoScaleMode.Dpi?
For controls set the anchor property (default is top|left) also to right (and/or bottom if needed). That will automatically 'stretch' the controls.
Advanced:
Now, if you really want to support different resolutions it will take much more work:
As already mentioned you have to rearrange the controls on orientation changes. Take a look at Developing Orientation and dpi Aware Applications for the .NET Compact Framework!
And finally you have to provide images in different resolutions.
Adapt to New Screen Orientations and Resolutions
Of course you have to decide if this is really needed for your app as this will take much more time.
Is there a way to easily remove the facebook tags on contacts in outlook? it's the stuff that says :
<HTCData><!-- Please do not modify -->
<Facebook>id:xxxxxx/friendof:xxxxxxxxxxx</Facebook>
</HTCData>
Thanks!
Yes PLEASE? I don't use a Sense ROM anymore and this is annoying!
I don't even have this phone anymore. Maybe I will write something to do this for us.
HTC tag removal in contact notes!
I just sat down on my break and created this code to strip out the HTC tags from the contact notes:
Code:
Sub HTCbGone()
Dim objContactsFolder As Outlook.MAPIFolder
Dim objContacts As Outlook.Items
Dim objContact As Object
Dim StartPos As Integer
Dim EndPos As Integer
Dim iCount As Integer
' Specify with which contact folder to work
Set objContactsFolder = _
Session.GetDefaultFolder(olFolderContacts)
Set objContacts = objContactsFolder.Items
iCount = 0
' Process the changes
For Each objContact In objContacts
If TypeName(objContact) = "ContactItem" Then
StartPos = InStr(objContact.Body, "<HTCData>")
EndPos = InStr(objContact.Body, "</HTCData>") + 10
If StartPos > 0 Then
If StartPos = 1 Then
If Len(EndPos) > EndPos + 1 Then
objContact.Body = Mid(objContact.Body, EndPos + 1)
Else
objContact.Body = ""
End If
Else
If Len(EndPos) > EndPos + 1 Then
objContact.Body = Left(objContact.Body, StartPos = 1)
Else
objContact.Body = Left(objContact.Body, StartPos - 1) & Mid(objContact.Body, EndPos + 1)
End If
End If
iCount = iCount + 1
objContact.Save
End If
End If
Next
' Display the results
MsgBox "Number of contacts updated:" & Str$(iCount), , _
"HTCbGone Finished"
' Clean up
Set objContact = Nothing
Set objContacts = Nothing
Set objContactsFolder = Nothing
End Sub
To run this, I opened Outlook. Selected Macro(s) from the Tools pull-down menu (or press [ALT+F8]). Created a new Macro called HTCbGone and pasted this code over everything. Then I just ran it.
Use at your own risk.
Happy scripting,
GinoRP
THANK YOU!!!! (I only type in all caps 2 or 3 times a year) If HTC was a person I would kick him in the teeth because of what they have done to my 500+ contacts in my Microsoft Exchange account.
How could the people at HTC justify code that puts notes on contacts only invisible to a HTC device and visible everywhere else?? How could they think that would annoy no one? Blows my effing mind.
Kinda thanks but for me it did not work.
I made and run the macro.
Then I noticed some things got lost though!
Before I began I made a copy of the contacts folder in Outlook (recommended!).
I used the "modified" tab to see what contacts where changed when.
There was an extra URL in the note position for a contact which I put there earlier today.
After running the macro the Facebook data was gone but so was the URL.
Because it changed many contacts I did not bother to look further if other things gotten lost but rather just emptied the folder and restored from backup folder.
I am do work with DB and such but did not find anything special in the script which could explain my output.
Sorry to bring up a dead thread, but is there a way to do this without outlook?
i am still interested as well- can anyone come up with a better way not using outlook?
Remove HTC Notes Using CSV
DeMiNe0 said:
Sorry to bring up a dead thread, but is there a way to do this without outlook?
Click to expand...
Click to collapse
I was trying to figure out this very same thing and came across this thread in my searching. I also don't look Outlook, but I found a really simple, quick, and effective way to manually get rid of all those pesky HTC notes in under five minutes, for those that don't use Outlook:
1) Go into the contacts view in Gmail
2) Click the "More" dropdown box and select "Export"
3) Ensure that the "All Contacts" option is selected, choose the "Outlook CSV format," and export
4) After the file downloads, open it up in Excel (or your choice spreadsheet program)
5) Find the column labeled "Notes," and then just scroll down and clear all the cells with HTC data in them
6) Save the file, ensuring it is still in CSV format
7) Back in your Google Contact Manager, delete all your contacts
NOTE: Before deleting your contacts you will want to export a Google CSV file of all your contacts for backup. You can also the "More > Restore" feature to go back to a previous point in time if something goes wrong.8) Import the CSV file you saved in step 6
That's it! Your contact book should be restored to the exact way it was, minus the obnoxious HTC data. With 1,000+ contacts, I was able to do this in about two minutes. Again, be sure you have backups of your contacts or know how to use Google's Restore contacts feature in case something goes wrong, but this should work simply enough. Also, I just selected all the cells in the Notes column and cleared all their data, but if you have any notes saved for any of your contacts, you'll want to scroll through the spreadsheet file and be sure you only delete cells with HTC data.
I hope this helps!
---------- Post added at 01:09 AM ---------- Previous post was at 12:52 AM ----------
You should also be aware that this method may cause you to lose your contacts photos, as well as any joined contacts you have in your Android address book. However, if you want to attach your contacts Facebook photos permanently to their Google contact entry (something HTC's method did not do), you should check out this tool; in just a couple clicks, you can have all those photos matched up again and restored:
[I can't post links yet, but just Google "Facebook Google Contact Sync" and click on the first return. It is a great little tool made by a dev called "Heart of Angel."]
mredmond2012 said:
I was trying to figure out this very same thing and came across this thread in my searching. I also don't look Outlook, but I found a really simple, quick, and effective way to manually get rid of all those pesky HTC notes in under five minutes, for those that don't use Outlook:
1) Go into the contacts view in Gmail
2) Click the "More" dropdown box and select "Export"
3) Ensure that the "All Contacts" option is selected, choose the "Outlook CSV format," and export
4) After the file downloads, open it up in Excel (or your choice spreadsheet program)
5) Find the column labeled "Notes," and then just scroll down and clear all the cells with HTC data in them
6) Save the file, ensuring it is still in CSV format
7) Back in your Google Contact Manager, delete all your contacts
NOTE: Before deleting your contacts you will want to export a Google CSV file of all your contacts for backup. You can also the "More > Restore" feature to go back to a previous point in time if something goes wrong.8) Import the CSV file you saved in step 6
That's it! Your contact book should be restored to the exact way it was, minus the obnoxious HTC data. With 1,000+ contacts, I was able to do this in about two minutes. Again, be sure you have backups of your contacts or know how to use Google's Restore contacts feature in case something goes wrong, but this should work simply enough. Also, I just selected all the cells in the Notes column and cleared all their data, but if you have any notes saved for any of your contacts, you'll want to scroll through the spreadsheet file and be sure you only delete cells with HTC data.
I hope this helps!
---------- Post added at 01:09 AM ---------- Previous post was at 12:52 AM ----------
You should also be aware that this method may cause you to lose your contacts photos, as well as any joined contacts you have in your Android address book. However, if you want to attach your contacts Facebook photos permanently to their Google contact entry (something HTC's method did not do), you should check out this tool; in just a couple clicks, you can have all those photos matched up again and restored:
[I can't post links yet, but just Google "Facebook Google Contact Sync" and click on the first return. It is a great little tool made by a dev called "Heart of Angel."]
Click to expand...
Click to collapse
In addition to the thanks button, I think you deserve a "thanks" post. This was so useful and in addition to removing that HTC garbage, I removed all the other data I found unnecessary.
Remove With a Simple Java Program, If you know Java
Ozark_8125 said:
Is there a way to easily remove the facebook tags on contacts in outlook? it's the stuff that says :
<HTCData><!-- Please do not modify -->
<Facebook>id:xxxxxx/friendof:xxxxxxxxxxx</Facebook>
</HTCData>
Thanks!
Click to expand...
Click to collapse
I know I am too late to reply this post but I actually searched a solution today and found this post where some one also had same issue.
Using gdata java api I wrote a small program to remove notes from all of your contacts. Maximum 800 (Congifurable) Here is the Java Program :
Code:
import java.net.URL;
import com.google.gdata.client.Query;
import com.google.gdata.client.contacts.ContactsService;
import com.google.gdata.data.PlainTextConstruct;
import com.google.gdata.data.TextContent;
import com.google.gdata.data.contacts.ContactEntry;
import com.google.gdata.data.contacts.ContactFeed;
/**
* This is a test template
*/
public class ContactNotesCleaner {
public static String feedUrlString = "https COLON SLASH SLASH www DOT google DOT com SLASH m8 SLASH feeds SLASH contacts SLASH default SLASH full";
public static void main(String[] args) throws Exception {
// Create a new Contacts service
ContactsService myService = new ContactsService(<Any App Name>);
myService.setUserCredentials(<Your Gmail Id>, <Your Password>);
updateAllContacts(myService);
}
public static void updateAllContacts(ContactsService myService) throws Exception {
URL feedUrl = new URL(feedUrlString);
Query myQuery = new Query(feedUrl);
myQuery.setMaxResults(800);
ContactFeed resultFeed = myService.query(myQuery, ContactFeed.class);
// Print the results
System.out.println(resultFeed.getTitle().getPlainText());
for (ContactEntry entry : resultFeed.getEntries()) {
if (entry.getContent() != null) {
updateNotesContent(myService, entry);
}
}
}
private static void updateNotesContent(ContactsService myService, ContactEntry entry) throws Exception {
TextContent textContent = (TextContent) entry.getContent();
if (textContent.getContent() != null) {
String plainText = textContent.getContent().getPlainText();
if (plainText != null && plainText.startsWith("<HTCData>")) {
String newPlainText = "";
textContent.setContent(new PlainTextConstruct(newPlainText.trim()));
entry.setContent(textContent);
URL editUrl = new URL(entry.getEditLink().getHref());
ContactEntry contactEntry = myService.update(editUrl, entry);
System.out.println(entry.getName().getFullName().getValue() + " " + "Updated: " + contactEntry.getUpdated().toString());
}
}
}
}
I have executed the above program and tested it. You need gdata lib files:
gdata-media-1.0.jar
gdata-client-meta-1.0.jar
gdata-contacts-3.0.jar
gdata-client-1.0.jar
gdata-contacts-meta-3.0.jar
gdata-core-1.0.jar
guava-14.0.1.jar
gdataplugin.jar -- I am not sure what this jar does, even if it is required or not.
This is a bit complex for some users to run a java program, this way you will not loose the chat invites and other important information of your contact.
Note: Even if I have tested above program 10 times, I would not give any guaranty it will work for you.
- CAM
cmehta82 said:
I know I am too late to reply this post but I actually searched a solution today and found this post where some one also had same issue.
Using gdata java api I wrote a small program to remove notes from all of your contacts. Maximum 800 (Congifurable) Here is the Java Program
Click to expand...
Click to collapse
Your Java program worked!
I attached all the required libraries in a .zip-file. Include them in your Java project and copy the code from cmehta82 post above.
Replace <Your Gmail Id> with your emailadress:
Replace <Your Password> with your application specific password, generated at https://accounts.google.com/b/0/IssuedAuthSubTokens#accesscodes
Replace the feed URL string with https://www.google.com/m8/feeds/contacts/default/full
Can't JOIN contacts if HTCData exists in notes field
I wrote up my solution to this problem a little bit here thanks to the this forum thread above.
http://androidforums.com/samsung-ga...tcdata-exists-in-notes-field.html#post5968115
Python script to remove HTCData
Used to be a HTC phone user and it really messed up my contacts with the XML data. I am using a Mac and have written a Python script to get rid of the HTCData tag.
I posted the script here: http://kongjinjie.wordpress.com/2013/10/29/remove-htcdata-from-apple-contacts/
I don't know if this works on other OS, only tested on my Mac. I hope it helps!
EDIT:
Do not use this for those who setup Sync to Google. After running this script, it doesn't seeem to initiate a sync to Google. Anyone knows how to force a sync to Google? Is there a timestamp I can change to identify the latest version?
cmehta82 said:
I know I am too late to reply this post but I actually searched a solution today and found this post where some one also had same issue.
Using gdata java api I wrote a small program to remove notes from all of your contacts. Maximum 800 (Congifurable) Here is the Java Program :
Code:
import java.net.URL;
import com.google.gdata.client.Query;
import com.google.gdata.client.contacts.ContactsService;
import com.google.gdata.data.PlainTextConstruct;
import com.google.gdata.data.TextContent;
import com.google.gdata.data.contacts.ContactEntry;
import com.google.gdata.data.contacts.ContactFeed;
/**
* This is a test template
*/
public class ContactNotesCleaner {
public static String feedUrlString = "https COLON SLASH SLASH www DOT google DOT com SLASH m8 SLASH feeds SLASH contacts SLASH default SLASH full";
public static void main(String[] args) throws Exception {
// Create a new Contacts service
ContactsService myService = new ContactsService(<Any App Name>);
myService.setUserCredentials(<Your Gmail Id>, <Your Password>);
updateAllContacts(myService);
}
public static void updateAllContacts(ContactsService myService) throws Exception {
URL feedUrl = new URL(feedUrlString);
Query myQuery = new Query(feedUrl);
myQuery.setMaxResults(800);
ContactFeed resultFeed = myService.query(myQuery, ContactFeed.class);
// Print the results
System.out.println(resultFeed.getTitle().getPlainText());
for (ContactEntry entry : resultFeed.getEntries()) {
if (entry.getContent() != null) {
updateNotesContent(myService, entry);
}
}
}
private static void updateNotesContent(ContactsService myService, ContactEntry entry) throws Exception {
TextContent textContent = (TextContent) entry.getContent();
if (textContent.getContent() != null) {
String plainText = textContent.getContent().getPlainText();
if (plainText != null && plainText.startsWith("<HTCData>")) {
String newPlainText = "";
textContent.setContent(new PlainTextConstruct(newPlainText.trim()));
entry.setContent(textContent);
URL editUrl = new URL(entry.getEditLink().getHref());
ContactEntry contactEntry = myService.update(editUrl, entry);
System.out.println(entry.getName().getFullName().getValue() + " " + "Updated: " + contactEntry.getUpdated().toString());
}
}
}
}
I have executed the above program and tested it. You need gdata lib files:
gdata-media-1.0.jar
gdata-client-meta-1.0.jar
gdata-contacts-3.0.jar
gdata-client-1.0.jar
gdata-contacts-meta-3.0.jar
gdata-core-1.0.jar
guava-14.0.1.jar
gdataplugin.jar -- I am not sure what this jar does, even if it is required or not.
This is a bit complex for some users to run a java program, this way you will not loose the chat invites and other important information of your contact.
Note: Even if I have tested above program 10 times, I would not give any guaranty it will work for you.
- CAM
Click to expand...
Click to collapse
P1nGu1n_ said:
Your Java program worked!
I attached all the required libraries in a .zip-file. Include them in your Java project and copy the code from cmehta82 post above.
Replace <Your Gmail Id> with your emailadress:
Replace <Your Password> with your application specific password, generated at https://accounts.google.com/b/0/IssuedAuthSubTokens#accesscodes
Replace the feed URL string with https://www.google.com/m8/feeds/contacts/default/full
Click to expand...
Click to collapse
Where do you configure the app name and password?>
ginorp said:
I just sat down on my break and created this code to strip out the HTC tags from the contact notes:
Code:
Sub HTCbGone()
Dim objContactsFolder As Outlook.MAPIFolder
Dim objContacts As Outlook.Items
Dim objContact As Object
Dim StartPos As Integer
Dim EndPos As Integer
Dim iCount As Integer
' Specify with which contact folder to work
Set objContactsFolder = _
Session.GetDefaultFolder(olFolderContacts)
Set objContacts = objContactsFolder.Items
iCount = 0
' Process the changes
For Each objContact In objContacts
If TypeName(objContact) = "ContactItem" Then
StartPos = InStr(objContact.Body, "<HTCData>")
EndPos = InStr(objContact.Body, "</HTCData>") + 10
If StartPos > 0 Then
If StartPos = 1 Then
If Len(EndPos) > EndPos + 1 Then
objContact.Body = Mid(objContact.Body, EndPos + 1)
Else
objContact.Body = ""
End If
Else
If Len(EndPos) > EndPos + 1 Then
objContact.Body = Left(objContact.Body, StartPos = 1)
Else
objContact.Body = Left(objContact.Body, StartPos - 1) & Mid(objContact.Body, EndPos + 1)
End If
End If
iCount = iCount + 1
objContact.Save
End If
End If
Next
' Display the results
MsgBox "Number of contacts updated:" & Str$(iCount), , _
"HTCbGone Finished"
' Clean up
Set objContact = Nothing
Set objContacts = Nothing
Set objContactsFolder = Nothing
End Sub
To run this, I opened Outlook. Selected Macro(s) from the Tools pull-down menu (or press [ALT+F8]). Created a new Macro called HTCbGone and pasted this code over everything. Then I just ran it.
Use at your own risk.
Happy scripting,
GinoRP
Click to expand...
Click to collapse
Sorry for this reply in this old thread, but you might lose data running the VBA code from GinoRP. I found a lot of small mistakes.
Here is the corrected code. You can run it multiple times if there is more than one <HTCData> tag in a specific contact.
Code:
Sub HTCbGone()
Dim objContactsFolder As Outlook.MAPIFolder
Dim objContacts As Outlook.Items
Dim objContact As Object
Dim StartPos As Integer
Dim EndPos As Integer
Dim iCount As Integer
' Specify with which contact folder to work
Set objContactsFolder = _
Session.GetDefaultFolder(olFolderContacts)
Set objContacts = objContactsFolder.Items
iCount = 0
' Process the changes
For Each objContact In objContacts
If TypeName(objContact) = "ContactItem" Then
StartPos = InStr(objContact.Body, "<HTCData>")
EndPos = InStr(objContact.Body, "</HTCData>") + 10
If StartPos > 0 Then
If StartPos = 1 Then
If Len(objContact.Body) > EndPos + 1 Then
objContact.Body = Mid(objContact.Body, EndPos)
Else
objContact.Body = ""
End If
Else
If Len(objContact.Body) = EndPos - 1 Then
objContact.Body = Left(objContact.Body, StartPos - 1)
Else
objContact.Body = Left(objContact.Body, StartPos - 1) & Mid(objContact.Body, EndPos)
End If
End If
iCount = iCount + 1
objContact.Save
End If
End If
Next
' Display the results
MsgBox "Number of contacts updated:" & Str$(iCount), , _
"HTCbGone Finished"
' Clean up
Set objContact = Nothing
Set objContacts = Nothing
Set objContactsFolder = Nothing
End Sub
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.
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.
Hi
I built a simple clock app yesterday. It was surprisingly easy. One question I have though is how to make my images smooth (without jaggies). I drew my clock face and hands in photoshop. At first I did them at 300x300 pixels and the jaggies were so obnoxious I threw those images away. Then I did everything at 1000 x 1000 pixels and resized down to 300 when I was finished. This was much better, but still not as smooth as the clock in Jelly Bean. I notice that most of the graphics and fonts I see in Android are all very smooth. I've been testing the app on a Galaxy Nexus.
What is the secret to creating/displaying nice smooth images?
Thanks, Derek
vector graphic is the keyword with fix sized effects (photoshop, ie. inner shadow is always 1px, above 256px use 2px)... yeah, the simple bitmap resizing won't give pro result for you
Heh Yeah, I've had this problem and it was a ***** to solve. Mainly because the answer is distributed over a dozen different posts on half a dozen different forums.
Anyway, the answer depends mainly on if you're using imageviews/buttons or something or if you're drawing directly to a/your own canvas. But the way to solve it can be applied to both. It basically involves using BitmapFactory.Options and configuring it correctly:
Code:
private BitmapFactory.Options ops;
ops = new BitmapFactory.Options();
ops.inPurgeable = true; //means the system can recycle and reclaim the memory used by the bmp when the system has low memory
ops.inDensity = 0; //load the bitmap without scaling it to the screen density
ops.inDither = false; //don't dither (you only want dithering when you're working/converting between bitmaps/canvasses with different color depths (16bit to 8 bit etc)
ops.inScaled = false; //no scaling, related to some other settings in ops
ops.inPreferredConfig = Bitmap.Config.ARGB_8888; //load the bmp into a 32bit argb bitmap
ops.inJustDecodeBounds = false; //if true, you're just looking at the underlying bmp data, eg to see the height/width without loading the bmp into memory
//then load your bitmap like so:
Bitmap yourbitmap = BitmapFactory.decodeResource(getResources(), R.drawable.yourprettybmp, ops);
Now you can use the bitmap to draw onto all kinds of surfaces or load it into widgets.
Be warned, this is a non-mutable bitmap. If you want to change it's data (like you want to draw on it by making it the backing bmp of a canvas) you'll have to get a copy of the BMPFactory.decodeResouce bit by adding
Code:
.copy(Config.ARGB_8888, true);
to it.
For resizing the bmp, you can also do the following (which returns a mutable bmp, so you won't need the copy bit above):
Code:
yourresizedbmp = Bitmap.createScaledBitmap(yourbmp, width, height, true);
Of course, you can combine all this in one step (where "res" is a reference to getResources()):
Code:
yourresizedbmp = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(res, bgIDInt, ops), width, height, true);
One more thing to ensure quick drawing, lower memory usage etc is to define the window type of your activity to match the colour depth of your bitmaps. You can do that by adding the following to the onCreate of your activity:
Code:
getWindow().setFormat(PixelFormat.RGBA_8888);
And if you're also drawing to a surface canvas in a thread, you also set that:
Code:
mSurfaceHolder.setFormat(PixelFormat.RGBA_8888);
Anyway, the most important thing is the "ops" section. Hope you get it sorted!
PS: clean, minimal graphics can often be more easily gotten by just drawing things yourself on a canvas (extend the View object and override it's onDraw()). Just use a correctly setup and antialiased Paint to draw circles, lines and text on it and use the result.
Bitmaps are not generally used for graphics. Try to use PNG images, Google does so too.
I might be wrong, but from the OP it seems like you're using the same image size for all resolutions, use the Android Dpi Calculator to easily get the right dimensions for each screen resolution (and put the resized images respectively in /res/drawable-xhdi, hdpi, mdpi, ldpi...)
If you didn't do so, then it's definitely the problem as mdpi is the default behaviour of /res/drawable, so it will be awfully resized on your xhdpi Galaxy Nexus.
dealy663 said:
Hi
I built a simple clock app yesterday. It was surprisingly easy. One question I have though is how to make my images smooth (without jaggies). I drew my clock face and hands in photoshop. At first I did them at 300x300 pixels and the jaggies were so obnoxious I threw those images away. Then I did everything at 1000 x 1000 pixels and resized down to 300 when I was finished. This was much better, but still not as smooth as the clock in Jelly Bean. I notice that most of the graphics and fonts I see in Android are all very smooth. I've been testing the app on a Galaxy Nexus.
What is the secret to creating/displaying nice smooth images?
Thanks, Derek
Click to expand...
Click to collapse
Not sure if you've fixed this already but it's really easy. No code is required to remove jaggies, regardless of resolution. Assuming you're using Photoshop, choose save for web and devices, then select PNG-24 (not jpg or PNG-8) with transparency enabled. Initial resolutions of 200x200, 300x300 etc. are all fine; there's no need to create it at 1000x1000 and scale down if you need something smaller. Your graphics will look great.
One more tip - clock widgets fill a certain number of "squares" on the home screen grid, so just make sure that you determine the right number of dp pixels to cover the size you want (e.g., 2x2 or 2x4, or 3x3) and then specify it in xml. See the Android site for widget sizing.