Project PDA Program

Source: Internet
Author: User

Today, I finally finished the PDA version again. Recently, many things have to be annoying. I don't have time to do this things. Now I have finished it, so I can start reading it with peace of mind!
This PDA version used the cross-platform socket library that was previously used, so basically the underlying network does not need to be used, just use it directly, and then add the previous upper-layer code reuse, so the function will be implemented soon. It may be that some functions or controls that are not compatible with the Pocket PC need to be considered. record the following:

1) if you forget to define the destructor, the program may exit without a terminal on the Pocket PC.
2) code record:

Add menu code:
Void cpdactrldlg: initmenu ()
{
Hwndcb = commandbar_create (: AfxGetInstanceHandle (), this-> getsafehwnd (), 1 );
Commandbar_insertmenubar (hwndcb,: AfxGetInstanceHandle (), idr_main_menu, 0 );
Commandbar_addadornments (hwndcb, wm_help, 0 );
}
Full Screen setting code:
Void cpdactrldlg: initgui ()
{
Rect RC;
Getwindowrect (& rc );
RC. Top-= 26;
Movewindow (RC. Left, RC. Top, RC. Right, RC. Bottom, false); // move up 26 pixels
Shfullscreen (this-> m_hwnd, shfs_hidetaskbar); // hide the taskbar

Initmenu ();

}

Menu check item modification:
Hmenu =: commandbar_getmenu (hwndcb, 0 );

Uint state =: getmenustate (hmenu, id_pushplay, mf_bycommand );
Assert (State! = 0 xffffffff );

If (State & mf_checked)
{
Pbaseserver-> unloadservice (pcallplayresp-> getresptype ());
Checkmenuitem (hmenu, id_pushplay, mf_unchecked | mf_bycommand );
}
Else
{
Pbaseserver-> loadservice (pcallplayresp );
Checkmenuitem (hmenu, id_pushplay, mf_checked | mf_bycommand );
}

3) wince selects one or more files and tries to use cfiledialog. Therefore, it is easy to make a simple one by yourself, using ctreectrl
Together with clistctrl, the Code creates a resource manager like the resource manager in wince. By recursion all folders and directories
Displays files (non-folders) in the current directory. You can select multiple files from clistctrl to record the file path.
Code:

Dirdlg header file

# Pragma once </P> <p> // cdirdialog dialog box <br/> # include <string> <br/> # include <vector> <br/> # include "afx. H "</P> <p> using namespace STD; </P> <p> class cdirdialog: Public cdialog <br/>{< br/> declare_dynamic (cdirdialog) </P> <p> Public: <br/> cdirdialog (INT maxfilenum = 500, cwnd * pparent = NULL); // standard constructor <br/> virtual ~ Cdirdialog (); </P> <p> // data in the dialog box <br/> Enum {IDD = idd_listdlg}; <br/> PRIVATE: <br/> void initimagelist (); <br/> void clrimagelist (); <br/> void initdirtree (); <br/> void clrfilelist (clistctrl * plist ); <br/> void clrtreeitem (ctreectrl * ptree, htreeitem item); </P> <p> void initgui (); <br/> void clrgui (); </P> <p> vector <win32_find_data> findfile (string DIR); <br/> void getdirfile (clistctrl * plist, ctreectrl * ptree, htreeitem root ); <br/> string getpath (ctreectrl * ptree, htreeitem item); <br/> void recurdir (string Dir, ctreectrl * ptree, htreeitem root); <br/> public: <br/> vector <string> getselfile (); // return path </P> <p> PRIVATE: <br/> clistctrl * pfilelist; <br/> ctreectrl * pdirtree; <br/> cimagelist * pimagelist; <br/> vector <string> vecselpath; <br/> vector <string> vectmp; <br/> hwnd hwndcb; </P> <p> int imaxfilenum; // maximum number of stored display files </P> <p> protected: <br/> virtual void dodataexchange (cdataexchange * PDX); // DDX/DDV support <br/> declare_message_map () <br/> public: <br/> virtual bool oninitdialog (); <br/> Public: <br/> afx_msg void ontvnselchangeddir (nmhdr * pnmhdr, lresult * presult); <br/> public: <br/> afx_msg void onclose (); <br/> Public: <br/> afx_msg void onbnclickedok (); <br/> public: <br/> afx_msg void onbnclickedcancel (); <br/> Public: <br/> afx_msg void onactivate (uint nstate, cwnd * pwndother, bool bminimized ); <br/> Public: <br/> afx_msg void onsettingchange (uint uflags, lpctstr lpszsection); <br/>}; <br/>

 

Dirdlg implementation file

// Dirdialog. CPP: implementation file <br/> // </P> <p> # include ".. /stdafx. H "<br/> # include ".. /dlgsrc/pdactrl. H "<br/> # include" dirdialog. H "</P> <p> // cdirdialog dialog box </P> <p> implement_dynamic (cdirdialog, cdialog) </P> <p> cdirdialog :: cdirdialog (INT maxfilenum, cwnd * pparent/* = NULL */) <br/>: cdialog (cdirdialog: IDD, pparent) <br/>{< br/> This-> imaxfilenum = maxfilenum; <br/>}</P> <p> cdirdialog ::~ Cdirdialog () <br/>{< br/>}</P> <p> void cdirdialog: dodataexchange (cdataexchange * PDX) <br/>{< br/> cdialog: dodataexchange (PDX); <br/>}</P> <p> begin_message_map (cdirdialog, cdialog) <br/> on_wm_create () <br/> on_policy (tvn_selchanged, idc_dir, & cdirdialog: blank) <br/> on_wm_close () <br/> on_bn_clicked (idc_ OK, & cdirdialog: onbnclickedok) <br/> on_bn_clicked (idc_cancel, & cdirdialog: onbnclicked Cancel) <br/> on_wm_activate () <br/> on_wm_settingchange () <br/> end_message_map () </P> <p> // cdirdialog Message Processing Program <br/> void cdirdialog: initgui () <br/>{< br/> rect RC; <br/> getwindowrect (& rc); <br/> RC. top-= 26; <br/> movewindow (RC. left, RC. top, RC. right, RC. bottom, false); // move up to 26 pixels <br/> shfullscreen (this-> m_hwnd, shfs_hidetaskbar ); // hide the taskbar </P> <p> hwndcb = commandbar_create (: AfxGetInstanceHandle (), this-> getsafehw Nd (), 1); <br/> commandbar_addadornments (hwndcb, wm_help, 0); <br/>}</P> <p> void cdirdialog: clrgui () <br/>{< br/>: commandbar_destroy (hwndcb); <br/>}</P> <p> void cdirdialog: initdirtree () <br/>{< br/> pfilelist = (clistctrl *) This-> getdlgitem (idc_filelist); <br/> pdirtree = (ctreectrl *) this-> getdlgitem (idc_dir); <br/> pfilelist-> setimagelist (pimagelist, lvsil_small); <br/> pdirtree-> setimagelist (pimagelis T, tvsil_normal); </P> <p> int iindex = 0; <br/> htreeitem root = pdirtree-> insertitem (L ". ", 1, 1); <br/> recurdir (". ", pdirtree, root); <br/>}< br/> void cdirdialog: initimagelist () <br/>{< br/> pimagelist = new cimagelist (); <br/> pimagelist-> Create (16, 16, ilc_color, 2, 6); <br/> cbitmap * pbmp = new cbitmap (); <br/> pbmp-> loadbitmapw (idb_filebmp); <br/> pimagelist-> Add (pbmp, (cbitmap *) null); <br/> Delete pbmp; <br/> Pbmp = new cbitmap (); <br/> pbmp-> loadbitmapw (idb_folderbmp); <br/> pimagelist-> Add (pbmp, (cbitmap *) null ); <br/> Delete pbmp; <br/>}</P> <p> void cdirdialog: clrimagelist () <br/>{< br/> Delete pimagelist; <br/>}< br/> bool cdirdialog: oninitdialog () <br/>{< br/> cdialog: oninitdialog (); </P> <p> // todo: add additional initialization here <br/> initimagelist (); <br/> initdirtree (); </P> <p> return true; // return true unless you set Focus to a control <br/> // exception: the OCX attribute page should return false <br/>}< br/> vector <win32_find_data> cdirdialog: findfile (string DIR) <br/>{ <br/> vector <win32_find_data> vecret; </P> <p> win32_find_data FFD; <br/> handle hfind; <br/> uses_conversion; </P> <p> hfind = findfirstfile (a2w (dir. c_str (), & FfD); <br/> If (hfind = invalid_handle_value) <br/>{< br/> // No file found <br/>}< br/> else <br/>{< br/> do {<br/> vecret. push_ B Ack (FfD); </P> <p >}while (findnextfile (hfind, & FfD); <br/>}< br/> findclose (hfind ); <br/> return vecret; <br/>}< br/> void cdirdialog: recurdir (string Dir, ctreectrl * ptree, htreeitem root) <br/>{< br/> uses_conversion; <br/> vector <win32_find_data> vecfile; <br/> dir + = "//*"; <br/> vecfile = findfile (DIR); </P> <p> If (vecfile. size () = 0) <br/> return; <br/> else <br/>{< br/> int iindex = 0; <br/> string strpath = Getpath (ptree, root); </P> <p> for (INT I = 0; I <vecfile. size (); I ++) <br/>{< br/> If (vecfile [I]. dwfileattributes & file_attribute_directory) <br/>{< br/> htreeitem citem = pdirtree-> insertitem (vecfile [I]. cfilename, 1, 1, root); <br/> string strcurdir = strpath + (string) w2a (vecfile [I]. cfilename); <br/> recurdir (strcurdir, ptree, citem ); <br/>}</P> <p> string cdirdialog: getpath (ctreectrl * PT Ree, htreeitem item) <br/>{< br/> uses_conversion; <br/> string strpath (""); <br/> string curdir = (string) w2a (pdirtree-> getitemtext (item); </P> <p> while (item = pdirtree-> getparentitem (item ))! = NULL) <br/>{< br/> cstring cs = pdirtree-> getitemtext (item); <br/> strpath = (string) w2a (CS) + "//" + strpath; </P> <p >}< br/> strpath = strpath + curdir + "//"; <br/> return strpath; // return path +/EG. /root/test <br/>}</P> <p> void cdirdialog: clrfilelist (clistctrl * plist) <br/>{< br/> plist-> deleteallitems (); <br/>}</P> <p> void cdirdialog: clrtreeitem (ctreectrl * ptree, htreeitem hdelitem) <br/>{< br/> htreeit Em hchilditem = ptree-> getchilditem (hdelitem); <br/> while (hchilditem! = NULL) <br/>{< br/> ptree-> deleteitem (hchilditem); <br/> hchilditem = ptree-> getchilditem (hdelitem ); <br/>}</P> <p> void cdirdialog: getdirfile (clistctrl * plist, ctreectrl * ptree, htreeitem root) <br/>{< br/> clrfilelist (plist); <br/> vectmp. clear (); <br/> vectmp. reserve (imaxfilenum); <br/> uses_conversion; </P> <p> string strpath = getpath (ptree, root ); <br/> string dir = strpath + "// *"; </P> <p> vector <wi N32_find_data> vecfile; <br/> vecfile = findfile (DIR); </P> <p> int iindex = 0; <br/> int JL (0 ); </P> <p> for (INT I = 0; I <vecfile. size (); I ++) <br/>{< br/> If (! (Vecfile [I]. dwfileattributes & file_attribute_directory) <br/>{< br/> string strfile = strpath + (string) w2a (vecfile [I]. cfilename); <br/> vectmp. push_back (strfile); <br/> pfilelist-> insertitem (JL, vecfile [I]. cfilename, 0); <br/> pfilelist-> setitemdata (JL, (DWORD) & vectmp [JL]); <br/> JL ++; <br/>}</P> <p> void cdirdialog: ontvnselchangeddir (nmhdr * pnmhdr, lresult * presult) <br/>{< br/> lpnmtreeview pnmtreeview = reinterpret_cast <lpnmtreeview> (pnmhdr); <br/> // todo: add the control notification handler Code <br/> htreeitem selitem = pdirtree-> getselecteditem (); <br/> If (selitem = NULL) <br/> return; </P> <p> getdirfile (pfilelist, pdirtree, selitem); </P> <p> * presult = 0; <br/>}</P> <p> void cdirdialog: onclose () <br/>{< br/> // todo: add the message processing program code and/or call the default value <br/> clrimagelist (); </P> <p> cdialog: onclose (); <br/>}</P> <p> vector <string> cdirdialog: getselfile () <br/>{< br/> return vecselpath; <br/>}</P> <p> void cdirdialog: onbnclickedok () <br/>{< br/> // todo: add the control notification handler code here <br/> position Pos = pfilelist-> getfirstselecteditemposition (); </P> <p> int index (0 ); <br/> while (POS) <br/> {<br/> Index = pfilelist-> getnextselecteditem (POS); <br/> string strpath = (* (string *) pfilelist-> getitemdata (INDEX); <br/> vecselpath. push_back (strpath); <br/>}</P> <p> enddialog (idok); <br/>}</P> <p> void cdirdialog :: onbnclickedcancel () <br/>{< br/> // todo: add the control notification handler code here <br/> enddicel (idcancel ); <br/>}</P> <p> void cdirdialog: onactivate (uint nstate, cwnd * pwndother, bool bminimized) <br/>{< br/> cwnd :: onactivate (nstate, pwndother, bminimized); <br/> shfullscreen (this-> m_hwnd, shfs_hidetaskbar); <br/> // todo: add the Message Processing code <br/>}</P> <p> void cdirdialog: onsettingchange (uint uflags, lpctstr lpszsection) <br/>{< br/> // cdialog: onsettingchange (uflags, lpszsection); </P> <p> // todo: add the message processing program code here <br/>}< br/>

 

Effect

4) program running:

 

 

 

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.