c++ - List of available com ports in menu of MFC dialog -



c++ - List of available com ports in menu of MFC dialog -

i stuck. have little experience mfc , inherited mfc programme former coworker.

i want add together list of available com ports in menu bar, user can select whatever wants. during farther runtime of program, menu should locked.

i created menu , added dialog. but:

how can dynamically show list of available com ports during initialization?

how can figure out port selected? there something. homecoming value?

actually sec question bugs me most.

edit1: more clear: know how list of available com ports , displaying them in combo box. want menu instead.

edit2: got far. question 1 solved!

//create menu object main menu cmenu *menu = new cmenu(); menu->createmenu(); //another menu object submenu cmenu *submenu = new cmenu(); submenu->createmenu(); //create subsubmenus cmenu *comportselect = new cmenu(); cmenu *modeselect = new cmenu(); comportselect->createmenu(); modeselect->createmenu(); //append available ports (portlist created earlier) (int_ptr = 0; < portlist.getcount(); i++) { comportselect->appendmenu(mf_popup, id_show, portlist[i]); } modeselect->appendmenu(mf_popup, id_show, _t("user")); modeselect->appendmenu(mf_popup, id_show, _t("expert")); //append subsubmenu submenu submenu->appendmenu(mf_popup | mf_string, (uint)comportselect->m_hmenu, _t("comports")); submenu->appendmenu(mf_popup | mf_string, (uint)modeselect->m_hmenu, _t("mode")); //append submenu menu menu->appendmenu(mf_popup | mf_string, (uint)submenu->m_hmenu, _t("advanced")); setmenu(menu);

i played interfacing programme arduino time ago. different models of arduinos had used different com ports had need scan available ports.

i forget exact ins , outs of now, utilize 1 syntax when opening com ports upto 8 or 10 think, , different 1 higher numbered ports. fortunately, syntax works higher numbered ports works lower numbered ones - code uses higher-numbered port syntax , works fine both.

the code used non-mfc win32 project follows:

void initportcombo(hwnd combo) { int curport; char mportname[16]; handle hcom; (curport=1; curport<=20; curport++) { sprintf(mportname, "\\\\.\\com%d", curport); hcom = createfile(mportname, generic_read | generic_write, 0, 0, open_existing, 0, 0); if (hcom != invalid_handle_value) { sprintf(mportname, "com%d", curport); closehandle(hcom); sendmessage(combo, cb_addstring, 0, (lparam)mportname); } } }

as sec question, when dynamically add together menu option, need specify id menu item has. in mind, when wm_command handler fires, need reverse logic used @ time added menu items.

for instance, if assign menu items id of (4000 + com_port_number), can subtract 4000 id of command fired wm_command handler. if results in valid number (i guess 1 20 or whatever port number scan to) know menu item corresponds 1 of com-ports.

just have play adding dynamic menu items , determining 1 selected. dont mfc, cant help there.

c++ mfc

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -