Jump to content
Tuts 4 You

How to use one control more than one time?


LCF-AT

Recommended Posts

Posted

Hi guys,

I have again a small question you could maybe answer.

So I made a new app and main app GUI is a little large and now I thought it would be good idea to create something like a compact GUI too.So I created another smaller Dialog and now I would like to put some controls into this new Dialog from my main GUI dialog.Lets say I have  some buttons / box views etc and  I wanna show them too in my smaller new dialog too without to create another new  buttons you know?So is this possible to do this?

Or other example: In  my main GUI I have a listbox what does log some datas from a extern source and in my new dialog I wanna show this too without to create a another listview control (if possible) or if I need to create also a new listbox control for this new dialog then I would like to get the same log infos in this listbox like I get in  my main GUI but without to write another code to send datas also into the new listbox.So can I anyhow dublicate this etc?

Example: Lets say you open 2x a notepad window and in one you do enter some text and now the text should be to see in both windows if you enter something etc.Anyhow like this I mean.

Maybe you have  any idea how I could handle that if possible.Just wanna prevent writing much extra codes for new controls if I can save the work anyhow.

Thank you

Posted

I think you will need to separate the data from the view of it.

Ideally you would create your data log and populate a structured buffer with all the required information. So instead of directly updating the listview, you first create all the data in one place, which can then be shared later on. For example you can create a structure like so:

LOGENTRY STRUCT
    LogTime db 32 dup (?)
    LogDate db 32 dup (?)
    LogEntry db 256 dup (?)
    LogParam dd ?
LOGENTRY ENDS

.const
MAX_LOG_ENTRIES EQU 1024

.data
MyLog    LOGENTRY   MAX_LOG_ENTRIES dup (<>) ; creates a buffer called 'MyLog' of 1024 x LOGENTRY data structures

Have a routine that populates the data in the buffer MyLog

Then when your GUI part is ready to show the data you update your list - with that data from a function that loops through the MyLog data structure and places the information in the list for the user to see/edit

The same function can then be called in other dialogs to update their list, so i would imagine a function like:

UpdateLogEntryList PROC lpLog:DWORD, hList:DWORD
    ; loop through all log entries and fetch each 'field': LogTime, LogDate, LogEntry, LogParam.
    ; Add entry to the hList control
    ret
UpdateLogEntryList ENDP

To synchronize the edits of one list to another, you will need to respond to something like an update or changed or lv_item_changed event and ideally have a mechanism where you can update the data log buffer directly at the right log entry.

Then you could have a refresh function to update each list control, or perhaps an array of hList handles to set an item index to a new text value directly via a PostMessage call

So say you have three list controls (listbox, listview or whatever) stored in an array, you could go through each one in turn fetch the hList. Make sure it is not the same as the current hList that is responding to the edit, otherwise we can skip that one. Send a PostMessage call with LVM_SETITEMTEXT for whatever entry index is to be updated and set the new text field directly (for listviews) or some similar thing for other controls.

 

Hope that helps

 

 

 

  • Like 1
Posted

Hi fearless,

thanks for your answer so far but I dont understand it yet what you exactly mean so maybe I try it again.

First question was whether its possible to show one and the same control like a LV etc more than one time.So I have a Dialog + LV and now I call another Dialog and there I wanna show the same LV too inside without to create a another new LV control.So maybe I think its not possible right?

Ok,so if I also need to create also a new LV for that new dialog then I would like to get the same content piped into that new LV from the original LV without to write another new code to fill same content too in this new LV.So above my example was a listbox control to log datas inside from a extern source part where it does fill datas into the original listbox handle....something like LB_ADDSTRING etc and  normaly I also now have to write all this code twice again to fill the same data in my new listbox control handle too.

Handle Original LB_ADDSTRING & Handle New LB_ADDSTRING.Now just imagine I have lots codes in my source where it does fill some diffrent datas into original Handle and now I need to write same code again for the new Handle.Just lets say I didnt created any own API to log datas and in this case I just tried to find any way to get same datas filled into new handle.

Maybe I do it explain not good enough to understand what I mean etc.

greetz

Posted (edited)

I think the best approach would be what fearless already said.

The easiest approach for that would be as said to create an array with the log data and a global update function for the listviews which takes as first parameter the log data and as second parameter the desired listview. Now in your Update function of the dialog you call for the main dialog the UpdateLogEntryList function with your main listview as parameter and in the sub dialog update routine you call the same function but with your sub list view as parameter.

Edited by Castor
  • Like 2
Posted

Hi again,

hmmm,a global update function....so what is if I have 2 dialogs and in each I have a LV which I wanna use / control same?Then both have to use any update function.Ok lets say I try to build such "update from each other" routine so where should I call it without to call it tons of times?At notify message?

greetz

Posted

Well updating it all the time isn't a good solution I think. You should just update it when it's necessary like when you're opening the main or sub dialog, updating the data of the log, after editing the log data but this you have to figure out by yourself and look for situations when it would be useful to update that control. You could also create another small sub-routine with the name "UpdateBothListViews" or such which like the name already says updates both controls, therefore you don't have to mess around when to update which control since you're always updating both. Like I've said you just have to figure it out by yourself, making tests and come to a final solution which suits your program the best.

  • Like 1
Posted

Hi,

all is all it seems not to be easy to use more than one control and link them with each other.Ok,for updating I do use a timer now just reading the data from main control to write same into another sub control.For a update 2 update of both controls I need to write most code twice again what I wanted to prevent but I can see no other solution for this.

greetz

Posted

I would suggest trying to refactor your code to help you in having to rewrite it again. If you a series of functions that you can call then this will help you by allowing you to reuse the functions and will also help if you wanted to reuse the code in other projects.

Just have to design the logic for the functions appropriately and pass handles for a list as a parameter, that way the code functions can be called from any dialog.

I would separate the logic into:

  • Initialization: handle basic steps to get the control up and running (if required) with any additional options like inserting columns, headers etc. Alloc additional mem for stuff (if required)
  • Loading Data: handle loading of data in the list or listview control from a data source (file, array in memory, database, or even manually adding hard coded string data etc)
  • Update: ideally handle updating back to data source any changes for a particular row or list entry AND handling update of the GUI of the control to reflect the new data based on the row or index that has changed.
  • Refresh: reload the entire list/listview. Optional, depending on your projects requirements, can be as simple as clearning list/listview and calling the loading function
  • Destroy: handle any logic to save any pending changes (if required) to external files, global memory buffers or whatever before control is destroyed. Also release any memory allocated at init, if not needed anymore

So depending on how many dialogs you will likely have open with lists/listviews that share the same data source you might be able to just call DialogBoxParam with the current hList as the parameter to pass to the dialog, and in the WM_INITDIALOG message save that param for later use.  Then handle the new list/listview by calling your list init routine, then the list loading routine

Use the same update function to update back to the core data source for the new dialogs list/listview, then either call the update function again using the hList param passed in via WM_INITDIALOG to update your 'master' list, or even check for return values on exit of DailogBoxParam to determine if you need to call the update function for the main 'master' list, depending on if any data has changed or not.

  • Like 2
Posted

Hhmm,

so my goal was it to update without to touch the main GUI controls code routines.So the problem is I wrote everything only for the main GUI controls and there I normaly want to change anything anymore.Now I made a second GUI too what only shows basic controls of main GUI to have a compact GUI.Now I have 2 choices,A) I only do show compact GUI with some controls and update these from main GUI (what happens / changed there) via a timer like to read entire content of LVs for example.Thats the only way I can see to update without to change my main GUI code.Problem in that case is I cant use any functions to do something in the compact GUI what means I can only see what happens.If I now also wanna use compact GUI too almost same as main GUI then I need to update main GUI and need to send new infos from compact GUI to main GUI.Anyhow its tricky to find any simple method for this without to write another much codes you know.No idea,so maybe I do think again in a wrong direction or so.

greetz

Posted (edited)
On 7/9/2017 at 10:01 PM, LCF-AT said:

Hi guys,

I have again a small question you could maybe answer.

So I made a new app and main app GUI is a little large and now I thought it would be good idea to create something like a compact GUI too.So I created another smaller Dialog and now I would like to put some controls into this new Dialog from my main GUI dialog.Lets say I have  some buttons / box views etc and  I wanna show them too in my smaller new dialog too without to create another new  buttons you know?So is this possible to do this?

Or other example: In  my main GUI I have a listbox what does log some datas from a extern source and in my new dialog I wanna show this too without to create a another listview control (if possible) or if I need to create also a new listbox control for this new dialog then I would like to get the same log infos in this listbox like I get in  my main GUI but without to write another code to send datas also into the new listbox.So can I anyhow dublicate this etc?

Example: Lets say you open 2x a notepad window and in one you do enter some text and now the text should be to see in both windows if you enter something etc.Anyhow like this I mean.

Maybe you have  any idea how I could handle that if possible.Just wanna prevent writing much extra codes for new controls if I can save the work anyhow.

Thank you

Hi what is your programing language ?

You should create static class to loging   with tow method for write and read information 

Then you can using timer or fier custome event  to show new changes in any dialog 

 

 

 

Edited by Iylin
Add some description
Posted

You may want to look into the MVC (Model-View-Controller) pattern for designing a code base that is separated from the UI to do things like this in an easier manner. Another alternative is that you could have the compact mode just move around the UI controls you already made, hide ones that are non-essential, resize the window etc. to make the compact UI as needed without having to recreate new controls for the same purpose. 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...