Open-source software M8 go score v0.8.8 first logged on to the meizu Software Center for free release, Technical Summary

Source: Internet
Author: User

Today (2010/7/22), I (liigo) developed the C/C ++ open-source software M8 go score v0.8.8 for the first time to log on to the meizu Software Center for free. This article provides some technical summary on how to meet the software requirements of the meizu Software Center.

As we all know, meizu has detailed requirements and strict review on the software released in the Software Center. Our staff can even help you test and find bugs, be considerate, enthusiastic, and considerate, and work very efficiently, working overtime on Saturday. Before the M8 go score (v0.8.8) was applied to enter the meizu Software Center, I reviewed and modified some content one by one based on the meizu mobile app software review standard 1.2, after several twists and turns, According to the feedback from the staff of the meizu Software Center, another part of the content was modified. To sum up, I logged on to the meizu Software Center and modified the following content:

The software must run on a single instance;

The title bar text must be set;

The text displayed in the system task manager must be the same as the software name;

When connecting to the computer through USB, the software must exit without any prompts;

The software must be animated when it is started, exited, or switched;

The software runs in an English system without Chinese garbled characters;

If the software has the sound playing function, you must allow the user to adjust the sound through the volume key (physical button), you must have the option to turn off the sound;

In general, its review is a little too trivial and strict, and some details are overly complicated in coding implementation (this is not user-friendly In SDK design ).

 

The software must run on a single instance. It is implemented by creating a global event object of the system, which is slightly different from the official sample code:

// According to mstore requirements, a single instance must be run <br/> m_eventhandle = createevent (null, false, false, l "Global // m8weiqipu_by_liigo "); <br/> If (m_eventhandle & getlasterror () = error_already_exists) <br/>{< br/> hwnd = findwindoww (null, m8_weiqipu ); <br/> If (hwnd) <br/>{< br/> setforegroundwindow (hwnd); <br/> setactivewindow (hwnd); <br/> :: showwindow (hwnd, sw_shownormal); <br/>:: updatewindow (hwnd); <br/>}< br/> postquitmessage (0); <br/> return false; <br/>}< br/> else <br/> setwindowtext (m8_weiqipu );

In the above Code, first create a global event object. If an object with the same name already exists, it indicates that an instance is running in this software. Use the wince API function findwindow () find the main window and activate it, and then exit the current process.

 

The display text of the software in the system task manager must be consistent with the software name. The document does not seem to mention where the text displayed in the System Task Manager is taken from. I have concluded that if the text in the title bar of the main window is set through the wince API function setwindowtext (), it is displayed, otherwise, the file name of the software EXE is displayed (no path ). To meet this requirement, you only need to set the title bar text to the Chinese name of the software.

 

When connecting to your computer via USB, the software must exit without any prompts. This implementation is a little complicated, but it is also simple. The SDK documentation provides relevant instructions. First, define a class member int m_usbpolicymsg. When the window is initialized (oninitdialog), assign the value to it: m_usbpolicymsg = registerusbpolicymsg (); that is, call the mz sdk function registerusbpolicymsg () obtain the message value related to USB connection. Then, process the USB connection message in the cmzwnd: mzdefwndproc () method. The main code is as follows:

Virtual lresult mzdefwndproc (uint message, wparam, lparam) <br/>{< br/> If (Message = m_usbpolicymsg) // comply with mstore requirements: exit program silently during USB connection <br/>{< br/> If (wparam = usb_massstorage_attach) <br/>{< br/> quit (); <br/>}< br/> ............

 

The software must be animated when it is started, exited, or switched. This class of code is called mainly by cmzwnd: animatewindow (mz_animtype_zoom_in, true). The SDK documentation contains sample code, which is simple.

 

The software runs in an English system without Chinese garbled characters. The M8 go Spectrum software needs to read the sgf chess file encoded in GB. The text parsed by the sgf parser developed by liigo is all in GB encoding (char *), the software itself is Unicode and requires encoding and conversion in the middle. I used to use the C library function mbstowcs () to convert the code. Later, I was tested by the meizu Software Center and found that when the software runs in the English system, this will cause Chinese characters to display garbled characters. After analysis, it is estimated that it is the cause of locale. It should be possible to call the C library function setlocale () to set it to Chinese locale? Then we found that the C Runtime Library Under wince does not seem to have the setlocale () function. So I gave up this idea and switched to the wince API function multibytetowidechar () for encoding conversion (gb2312-> ucs2le). The main code is as follows:

// Ensure that Chinese characters in the sgf file can be converted to Unicode in the English System <br/> static int cncharstowchar (const char * cnchars, wchar * wchars_buffer, int wchar_buffer_size) <br/>{< br/> If (wchars_buffer = NULL) <br/> return multibytetowidechar (936/* gb2312 */, 0, cnchars,-1, null, 0); <br/> else <br/> return multibytetowidechar (936/* gb2312 */, 0, cnchars,-1, wchars_buffer, wchar_buffer_size); <br/>}

 

If the software has the sound playback function, you must allow the user to adjust the sound by using the volume key (physical button). You must have the option to disable the sound. I used to call the wince API function playsound () to play the wave file, which makes it difficult to control the volume. Later, I chose to call the COM interface iplayercore_play provided by MZ SDK. The first step was to initialize the relevant COM Object (basically referring to the sample code in the SDK documentation, which is quite tedious ):

# Include <imzsysfile. h> <br/> # include <iplayercore. h> <br/> # include <iplayercore_iid.h> <br/> # include <playercore_guid.h> <br/> iplayercore_play * m_pplaycore; <br/> imzsysfile * m_psysfile; <br/> // initialize the sound playback component <br/> m_psysfile = NULL; <br/> m_pplaycore = NULL; <br/> If (succeeded (cocreateinstance (clsid_playercore, null, clsctx_inproc_server, iid_mz_sysfile, (void **) & m_psysfile) <br/>{< br/> m_psysfile-> Se Tparentwnd (m_hwnd); <br/> If (! Succeeded (m_psysfile-> QueryInterface (iid_playercore_play, (void **) & m_pplaycore) <br/>{< br/> m_psysfile-> release (); <br/> m_psysfile = NULL; <br/>}< br/> // m_pplaycore-> setpolicy (m_hwnd, wm_user + 15); <br/>}

To play a music file, call m_psysfile-> setname (m_luozisoundfile), then call m_pplaycore-> openfile (), and then call m_pplaycore-> play (). Of course, play () previously, you can call m_pplaycore-> setvolume (m_soundvolume) to set the volume:

M_psysfile-> setname (m_luozisoundfile); <br/> m_pplaycore-> openfile (); <br/> m_pplaycore-> setvolume (m_soundvolume ); <br/> m_pplaycore-> play ();

 

Next, you need to process the message that the user presses the music key (physical key) to increase or decrease the volume. The method is roughly the same as that for handling USB Connection events (the code is too cumbersome to handle ):

Int m_allkeyeventmsg; <br/> int m_soundvolume; <br/> registershellmessage (m_hwnd, wm_mzsh_all_key_event); <br/> m_allkeyeventmsg = getshellpolicymsg_allkeyevent (); <br/> virtual lresult mzdefwndproc (uint message, wparam, lparam) <br/>{< br/> If (Message = m_allkeyeventmsg) // comply with mstore requirements: volume key adjustment sound <br/>{< br/> int key = loword (wparam); // wparam_key_event _ *** <br/> If (Key = wparam_key_event_click _ Volup) <br/>{< br/> m_soundvolume + = 7; // The system volume variation is basically the same as that when you press the volume key <br/> If (m_soundvolume> 100) m_soundvolume = 100; <br/> m_skin.setsoundvolume (m_soundvolume ); <br/>}< br/> else if (Key = wparam_key_event_click_voldown) <br/>{< br/> m_soundvolume-= 7; <br/> If (m_soundvolume <0) m_soundvolume = 0; <br/> m_skin.setsoundvolume (m_soundvolume ); <br/>}< br/> ............

 

In the process of adjusting the volume by responding to the music key, I did not find a method to obtain the current volume. The user presses the "audio key" to increase the volume. The user presses the "audio key" to reduce the volume. But what is the initial volume value? I have not found a method to read the data, so I have to replace it with the volume of the current system incoming call. The current effect is not very good: When you press the music key, the system will automatically pop up a volume adjustment progress display box, and its displayed value is sometimes obviously not consistent with the volume in my software. In the final analysis, the initial volume value is not obtained. Depressed. If the system improves the interface, it will be nice to directly return the volume to me when the user presses the music key.

 

In general, the API design of mz sdk is not very friendly, and it is quite tedious to use in some places. Isn't it because I have written too much code in easy language and don't want to write smelly and long code? I'm looking forward to the android SDK. In my imagination, the API designed by Google should be pretty OK? In any case, the M8 go score enters the meizu Software Center, which is worth celebrating. By the way, I wish the meizu Software Center a better and better development.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.