How to deal with MFC listcontrol window flashing - c++

I wrote a MFC application program.I used some ListControl controls and some radio buttons in the dialog.I would like to realize real-time-update data with ListControl when clicked the single radiobutton triggering the corresponding events.
Firstly,when the dialog initialized,inserting data into the ListControl and showing the dialog.
Secondly,when I clicked the one radiobutton among these.The first step was to delete the all columns and all items in the ListControl.The second step was to insert my neccessary data into the ListControl.By the way,I used the same variable relative to the ListControl ID.
Notice:The data was changed by time!
Finally I found that the ListControl window appeared the fast flash and felt so bad.
So is there some good ways to solve this problem?And can you suggest some good or advanced advice to me?Thanks a lot!

Related

Display and use the same MFC CList control in multiple dialogs

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?
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.

How do I get messages to embedded dialogs in MFC?

I seem to have the original problem from Embedded Modeless Child Dialog not getting messages. I have managed to add rows to my property page using tips form What is the best way to manage data for rows of similar controls in MFC? but now when I click on the controls in the embedded dialog, nothing happens. I assume there's some message routing I need to do in the parent dialog but I don't know what it is.
The properties of the row dialog resource included Disabled = True. I have no idea how that happened.

How do i create a drag and drop start event in REPORT listview in winapi

I've stumbled into a problem with drag and drop.
I've got a REPORT style of my list view.
First thing to think of is catching the LVN_BEGINDRAG message, but I was unable to catch it in the parent window procedure. I went to MSDN and figured out that REPORT style doesn't support this notification because other styles had some mentioning of d'n'd in their description and report style didn't have one.
So I went the other path - handling NM_CLICK notification, but actually it's not perfect for the situation. The problem is that if i want to drag the already selected item, and click on it and hold the button, then no notification comes until I stop pressing the button.
I've also tried subclassing listview to catch LVM_LBUTTONDOWN to get 100% drag enter before any other calculations happen inside of a window proc, but it doesnt' do the job also; or maybe I've done some bad work subclassing the list view. Anyways. I need advice how to do it properly.
My target drag and drop zone is a treeview control actually.
Thanks

C++ - Create dialog box containing buttons and static text on click

so this project follows my last question. I implemented the buttons and found out how to render events when they are clicked, this question is a next-step for me that I am struggling with. Utilizing the winapi I want to create a dialog box when a button is clicked on the window class, but I want the dialog box to take the properties of another window class so I can pass specific properties to it. How would I approach this? Again, some demo code would be greatly appreciated! Thanks for taking the time.

Embedding dialogs in main dialog and switching them with button click in MFC

I have a design like below:
So basically, I want to embed three dialogs in the application main dialog and switch between them, for each button click i.e., button 1 will show dialog one , button 2 will hide dialog 1 and show dialog 2 .. and so on.
Each dialog will be having a different design and functions.
I tried using CPropertySheet class to Add pages but its GUI is different. It has either option for navigating the dialogs using next / back button , or from a tab control.
None of which is as per my requirement.
So I want to know is it possible to have a design like this in MFC ? If yes how? Which Class/ control should I use.
Any help will be appreciated.
What you can do is use a normal CDialog class, add your buttons to it and also create a frame/rect as a placeholder for where your embedded dialogs are to appear. The following piece of code will create and position your embedded dialog.
CRect rect;
CWnd *pHost = GetDlgItem(ID_OF_YOUR_FRAME_RECT);
pHost->GetWindowRect(&rect);
ScreenToClient(&rect);
pDialog->Create(ID_OF_YOUR_DIALOG, this);
pDialog->MoveWindow(&rect);
pDialog->ShowWindow(SW_SHOW);
On button clicks, you hide the previously shown dialog (SW_HIDE) and show your selected dialog(SW_SHOW) with ShowWindow(...).
If you create your embedded dialogs with IDD_FORMVIEW style in the add resource editor it'll have the proper styles for embedding.
Another option is probably to use an embedded PropertySheet and hide the tab row and programatically change the tabs on the button clicks. I just find it to be too much fuzz with borders, positioning, validation and such for my liking.
If you have the MFC Feature Pack, that first came with VS2008 SP1 and is in all later versions, you might like to consider CMFCPropertySheet. There are a number of examples on the linked page, that are very similar to your design.
For example, this:
What worked for me just using dialog based application is SetParent() method. Dont know why nobody mentioned it. It seems to work fine.
I am doing like below:
VERIFY(pDlg1.Create(PanelDlg::IDD, this));
VERIFY(pDlg2.Create(PanelDlg2::IDD, this));
VERIFY(pDlg3.Create(PanelDlg2::IDD, this));
::SetParent(pDlg1.GetSafeHwnd(), this->m_hWnd);
::SetParent(pDlg2.GetSafeHwnd(), this->m_hWnd);
::SetParent(pDlg3.GetSafeHwnd(), this->m_hWnd);
Now I can show or hide a child dialog at will (button clicks) as below:
pDlg1.ShowWindow(SW_SHOW);
pDlg2.ShowWindow(SW_HIDE);
pDlg3.ShowWindow(SW_HIDE);