0
votes

I am coding a test application for a windows CE device. This is the first time I am programming for a handheld device. I use MFC VC++ on Visual Studio 2008. I have found that there are many restrictions in the controls and what I could do with them when running the program on a handy versus when I run a similar program on a desktop computer.

Now, the device I am currently deploying my test program to, does not have a touchscreen and has few extra keys other that the numberpad 0-9 keys. So, I have to do with a simple GUI that uses keydowns to call specific functions like add, edit, delete etc... It also forces me to use separate dialogs for each of these functions so as to avoid unnecessary mouse cursor usage.

This leads me to my current problem: The 'ADD' dialog of my test app adds some user data to a CListCtrl that is on the 'MAIN' dialog. The 'EDIT/DELETE' dialog is to allow the user to select the desired data from its own CListCtrl and press the "ENTER" key, which thereby deletes the selected data from the 'MAIN' dialog's CListCtrl. Thus, both the main dialog and the 'EDIT/DELETE' dialog have CListCtrl with the exact same data. So, instead of having to use 2 separate list controls and using loops to copy the data to and fro among them, is there a way in which i could use the exact same CListCtrl (one and only one instance of the CListCtrl exists), but display it on 2 separate dialogs? This would remove all the copying code, as well as halve the amount of data in memory.

I tried passing a pointer to the MAIN dialog's CListCtrl to the 'EDIT/DELETE' dialog in hopes that I could redraw the control there, but in vain. I could call the RedrawWindow, RedrawItems commands, but they seem to have no effect in the 'EDIT/DELETE' dialog (I think it is because the control itself is not present on the edit/delete dialog). Any other suggestions?

1
I also tried to call the CListCtrl Create function using the passed pointer from inside the 'EDIT/DELETE' dialog. It seems like a List control is getting created, but the data is not reflected, maybe because the Create creates a new instance of the CListCtrl... - PRinCEKtd
I assume your EDIT/DELETE dialog is on top of the main dialog, so the main dialog will exists in the background of the other one. Then it should be possible to temporarily move the listctrl to the other dialog, by using the CWnd::SetParent function. What do you mean by "I tried passing a pointer"? - Karsten Koop
The MAIN dialog gets hidden and only one dialog is displayed at a time. **Passing it by pointer ** I tried something like this code in my Main dialog: EditDialog myEditDialog(&M_cDataList); //M_cDataList is variable to the CListCtrl and in the EditDialog: EditDialog(CListCtrl* pListCtrl); and then, used this pointer to try to display the list control. Ofcourse, I can access the data using this pointer, but I could not get it to display in the Edit dialog. - PRinCEKtd
Have you tried temporarily changing the parent to the new dialog (SetParent()) and setting the position to where you want to have it (SetWindowPos())? - Karsten Koop
I will try the SetParent. Haven't done it yet. Thanks for the suggestion Karsten. - PRinCEKtd

1 Answers

2
votes

You could temporarily change the parent of the ListCtrl using CWnd::SetParent to the EDIT/DELETE dialog, and set the position with CWnd::SetWindowPos to where you want to have it. When the dialog gets closed, set the parent back to the MAIN dialog.