c++ - MFC adding item to system menu -
i added item system menu in dialg based app, item shown in menu, when click it, nothing happend. here's code:
#define idm_clip 17 bool ccalculatorcontroldlg::oninitdialog() { cdialog::oninitdialog(); cmenu* psysmenu = getsystemmenu(false); if (psysmenu != null) { cstring straboutmenu; straboutmenu.loadstring(ids_aboutbox); cstring strclip; strclip.loadstring(ids_clipbox); if (!straboutmenu.isempty()) { psysmenu->appendmenu(mf_separator); psysmenu->appendmenu(mf_string, idm_aboutbox, straboutmenu); psysmenu->appendmenu(mf_string, idm_clip, strclip); } } seticon(m_hicon, true); seticon(m_hicon, false); m_calculator1.setnumformat("%0.2f"); logfont lf; m_calculator1.getresultwndfont(&lf); strcpy(lf.lffacename, "brittanic bold"); m_calculator1.setresultswndfont(&lf); m_calculator1.getbuttonfont(&lf); strcpy(lf.lffacename, "tahoma"); m_calculator1.setbuttonfont(&lf); m_calculator1.setresultswndbkclr(rgb(128,128,128)); m_calculator1.setresultswndtxtclr(rgb(255,255,255)); return false; } void ccalculatorcontroldlg::onsyscommand(uint nid, lparam lparam) { if ((nid & 0xfff0) == idm_aboutbox) { caboutdlg dlgabout; dlgabout.domodal(); } else if((nid & 0xfff0) == idm_clip) { m_calculator1.oneditcopy(); } else { cdialog::onsyscommand(nid, lparam); } }
about dialog added autommatically framework , added idm_clip. m_calculator1.oneditcopy() function ccalculatorctrl class coping text clipboard. included ccalculatorctrl.h file in calculatorcontroldlg.cpp file, i'm editing system menu. here oneditcopy method, btw works button control...
this method i'm calling in ccalculatorcontroldlg class.
void ccalculatorctrl::oneditcopy() { if ( !openclipboard() ) { afxmessagebox( _t("cannot open clipboard") ); return; } // remove current clipboard contents if( !emptyclipboard() ) { afxmessagebox( _t("cannot empty clipboard") ); return; } // selected data hglobal hglob = globalalloc(gmem_fixed, 64); strcpy_s((char*)hglob, 64, m_strcurrententry); // appropriate data formats... if ( ::setclipboarddata( cf_text, hglob ) == null ) { cstring msg; msg.format(_t("unable set clipboard data, error: %d"), getlasterror()); afxmessagebox( msg ); closeclipboard(); globalfree(hglob); return; } afxmessagebox( _t("copy clipboard successful!")); closeclipboard(); }
i hope i'm understandable... in advance.
in method
void ccalculatorcontroldlg::onsyscommand(uint nid, lparam lparam)
the line
else if((nid & 0xfff0) == idm_clip)
cannot right, masking 0x11 (hex 17) against 0xfff0. result 16.
(nid & 0xfff0) never value 17 idm_clip.
use id idm_clip.
Comments
Post a Comment