In Class 3 - Create and Use a DLL
Create a DLL
In our problem we want to create a DLL for the right-button Listbox we have discussed. We will assume we have a programthat can use the right-button listbox. Click here for such a project. Follow these steps to create the dll project as part of the previous project.
- Add the dll complier directives to the right-button listbox header and comment out the rh include.
- Add the compiler directive
#define RIGHT_BUTTON_LISTBOX_BUILDDLL
to your right-button listbox cpp file just above the line where you include the right-button listbox header. - Select the show project node option from the environment options dialog.
- Select the project node, then select new target from the project menu.
- When the add target dialog appears type the same name as you used for the original node and select standard node type.
- In the target expert choose the project type as DLL and from the advanced options delete just the rc file.
- Paste the boiler plate code which you get by clicking here in the empty cpp file your new target has produced.
- Copy the text in the existing def file and paste into the new def file. Make changes suggested in comments.
- Add the right-button listbox cpp file to the dll target node.
- Shut off all debugging in this node
- Build and you should have a dll and lib file.
Use The DLL
We will add a right-button menu to the program we built in our first in-class lab. Click here to a completed version of that file. Complete the following steps and your window will have a right-button select.
- Create a new directory and extract the test program to this directory.
- Copy the right-button header, lib and dll files into the directory containing your project.
- Open the project and add the lib file to the project.
- Include the right-button listbox header in the file containing OurMain.
- Change the line
_listbox = new TListBox(this, IDC_OUR_LISTBOX);
to_listbox = new RightButtonListBox(this, IDC_OUR_LISTBOX);
in the constructor for OurMain - Add a right-button down hander in OurWindow that uses the following code
TDialog::EvRButtonDown(modKeys, point); // INSERT>> Your code here. TMenu menu(HWindow); HMENU hMenu = menu.GetSubMenu(0); // 0 is the first menu of this window, // 1 would be the second etc. TPopupMenu popupMenu(hMenu); // Create the Menu GetCursorPos(point); // Put the menu at the click point popupMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,point,0,HWindow);
At this point your program should run with a right-button select and menu.