You are on page 1of 8

Chng3: CCTHNHPHNCAMTNGDNG 1) Menu

Tothanhmenumi:VocasWorkspace>chnResourceView>chn menu resources > nhn nt phi chut v chn Insert > xut hin ca s InsertResourcevchnMenu,saunhnntNew. Thm cc phn t vo thanh Menu: Trong ca s ResourceView > DoubleClickvochsIDcathanhmenu>xuthincasdngthm ccphntvothanhmenu. Vd:Tothanhmenunhhnhsau

GnktmtthanhmenuvomtDialog:chnDialog>nhnntphichut vchnProperties>chnthGeneral,vvomcchnmenulachnch sIDcamenucnavoDialog. KhitalachnmtmcchntrnthanhmenuththngipCOMMANDs cgi. MtshmthuclpCWnddngchomenu: Hmtmtthanhmenuvocas.


BOOLSetMenu( CMenu*pMenu )

HmtrvcontrqunlthanhMenucamtcas.()
CMenu*GetMenu()const

MtshmthuclpCMenudngchomenu: Hm np v gn kt mt thanh menu vo mt i tng thuc lp CMenu


BOOLLoadMenu( LPCTSTRlpszResourceName ) BOOLLoadMenu( UINTnIDResource

) Hm t du Check hay loi b du Check cho mt mc chn trn thanh menu.


UINTCheckMenuItem( UINTnIDCheckItem, UINTnCheck

) HmEnables,disablesmtmcchntrnthanhmenu
UINTEnableMenuItem( UINTnIDEnableItem, UINTnEnable

) HmtrvmtcontritngCMenucamtpopupmenu.
CMenu*GetSubMenu( intnPos )const

Hmhinthmtpopupmenutimtvtrxcnh.
BOOLTrackPopupMenu( UINTnFlags, intx, inty, CWnd*pWnd, LPCRECTlpRect=0 )

ContextMenu: Mt Context Menu l mt popup menu c th hin th bt k u trn mnhnh. ToContextMenu: B1:TothanhmenubngMenuResource. B2:ThmthngipWM_CONTEXTMENUvongdng. B3: Trong hm OnContextMenu() dng cc hm LoadMenu(), GetSubMenu(),vTrackPopupMenu()hinthContextMenu.

2) Images,BitmapsvIcons
CchdngImageEditor CchdngPicture Gn kt Picture vi Icon, Bitmap: Chn Picture,nhn nt phi chut > chn Properties > Xut hin ca s Picture Properties > Chn th General,vomcchnTypelachnkiuPicturelIconhayBitmap >VomcchnImagelachnchsIDcaIconhayBitmapto ratrc. CchnpIconvBitmaptrongqutrnhthcthichngtrnh: HmAfxGetApp():Thepointerreturnedbythisfunctioncanbeusedtoaccess applicationinformationsuchasthemainmessagedispatchcodeorthetopmost window.
CWinApp*AFXAPIAfxGetApp()

HmLoadIcon()calpCWinApp:Loadstheiconresourcenamedby lpszResourceNameorspecifiedby nIDResourcefromtheexecutablefile.

HICONLoadIcon( LPCTSTRlpszResourceName )const HICONLoadIcon( UINTnIDResource )const

HmLoadBitmap()calpCBitmap:Loadsthebitmapresourcenamedby lpszResourceNameoridentifiedbytheIDnumberin nIDResourcefromthe application'sexecutablefile.


BOOLLoadBitmap( LPCTSTRlpszResourceName ) BOOLLoadBitmap( UINTnIDResource )

HmSetIcon()calpCStatic:Associatesanewiconimagewiththestaticcontrol.
HICONSetIcon( HICONhIcon )

HmSetBitmap()calpCStatic:Associatesanewbitmapwiththestaticcontrol.
HBITMAPSetBitmap( HBITMAPhBitmap )

CchdnglpCImageList: Thng c s dng hin th nhng Image trong ListControl v TreeControl. Cch tccImagevomtControl: B1:TomtBitmapchanhiuImage B2:DnghmLoadBitmap()npBitmap B3:DnghmCreate()mtImageList. B4:DnghmAdd()thmBitmapvoImageList. B5:DnghmSetImageList()tImageListvoControl B6:ChnccphntvoControl Nguynmumtshm: HmCreate()calpCImageList:Initializesanimagelistandattachesittoa CImageListobject.
BOOLCreate( UINTnBitmapID, intcx, intnGrow, COLORREFcrMask

HmAdd()calpCImageList:Callthisfunctiontoaddoneormoreimagesoran icontoanimagelist.
intAdd( CBitmap*pbmImage, COLORREFcrMask ) intAdd( HICONhIcon

) HmSetImageList():Assignsanimagelisttoalistviewcontrolandatreeview control.
CImageList*SetImageList( CImageList*pImageList, intnImageListType )

Vd:

3) DialogBoxes
ToDialog ModalDialogBoxes CchmthngdngthuclpCDialog. HmDoModal():Callthismemberfunctiontoinvokethemodal dialogboxandreturnthedialogboxresultwhendone.
virtualINT_PTRDoModal()

ModelessDialogBoxes CchmthngdngthuclpCDialog. HmCreate():Call Createtocreateamodelessdialogboxusinga dialogboxtemplatefromaresource.


virtualBOOLCreate( LPCTSTRlpszTemplateName,

CWnd*pParentWnd=NULL ) virtualBOOLCreate( UINTnIDTemplate, CWnd*pParentWnd=NULL )

CchmthuclpCWnd: HmGetParent():Callthisfunctiontogetapointertoachild window'sparentwindow(ifany).


CWnd*GetParent()const

HmShowWindow():Setsthevisibilitystateofthewindow.
BOOLShowWindow( intnCmdShow )

Vid:

MtsthnhphncalpCFileDialog: Hmto:CallthisfunctiontoconstructastandardWindowsfiledialog boxobject.


explicitCFileDialog( BOOLbOpenFileDialog,

LPCTSTRlpszDefExt=NULL, LPCTSTRlpszFileName=NULL, DWORDdwFlags=OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, LPCTSTRlpszFilter=NULL, CWnd*pParentWnd=NULL, DWORDdwSize=0 )

Parameters:bOpenFileDialog:SettoTRUEtoconstructaFileOpen dialogboxorFALSEtoconstructaFileSaveAsdialogbox. HmDoModal():CallthisfunctiontodisplaytheWindowscommonfile dialogboxandallowtheusertobrowsefilesanddirectoriesandentera filename.


virtualINT_PTRDoModal()

HmGetFileName():Callthisfunctiontoretrievethenameofthefilename enteredinthedialogbox.
CStringGetFileName()const

HmGetPathName():Callthisfunctiontoretrievethefullpathofthefile enteredinthedialogbox.
CStringGetPathName()const

MtsthnhphncalpCFile: HmtocalpCFile:Thedefaultconstructordoesnotopenafilebut rathersetsm_hFiletoCFile::hFileNull.


CFile() CFile( HANDLEhFile ) CFile( LPCTSTRlpszFileName, UINTnOpenFlags )

HmOpen():OpenisdesignedforusewiththedefaultCFileconstructor.
virtualBOOLOpen( LPCTSTRlpszFileName, UINTnOpenFlags, CFileException*pError=NULL )

HmClose():Closesthefileassociatedwiththisobjectandmakesthefile unavailableforreadingorwriting.
virtualvoidClose()

HmWrite():WritesdatafromabuffertothefileassociatedwiththeCFile object.
virtualvoidWrite( constvoid*lpBuf, UINTnCount )

HmRead():ReadsdataintoabufferfromthefileassociatedwiththeCFile object.

virtualUINTRead( void*lpBuf, UINTnCount )

Vd:Tongdngsau:

You might also like