如何用对话框控件中的值填充CList? [英] How to populate a CList with values from dialog controls?

查看:60
本文介绍了如何用对话框控件中的值填充CList?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是一个绝对的初学者,正在尝试为ffmpeg多媒体编码器(使用Visual Studio 2008 SP1和MFC)制作一个简单的GUI.
有一个带有很少属性页的属性表(视频对话框,音频对话框等)
由于ffmpeg命令行包含开关/值对(例如-i input_file_name),因此我创建了一个结构,其中包含两个CString,switch和value,以及一个CList,其中包含这些结构. 我将如何使用包含开关/值对的结构来馈送CList?可以从对话框控件中选择值,但是如何将开关存储在哪里以及如何将它们与适当的值相关联?用户更改某些设置时如何更新CList?
有没有更好的(阅读的,更简单的)方法来实现呢?
代码示例将不胜感激:)
谢谢.

Hello, I am an absolute beginner and trying to make a simple GUI to ffmpeg multimedia encoder (using Visual Studio 2008 SP1, MFC).
Have a property sheet with few property pages (video dialog, audio dialog etc.)
Since ffmpeg command line comprises of switch/value pairs (for example, -i input_file_name), I created a struct which holds two CStrings, switch and value, and a CList which holds these structs.
How would I go about feeding a CList with structs holding switch/value pairs? Values would be picked from dialog controls, but where do I store switches and how do I associate them with the appropriate values? How would I update CList when user changes some setting?
Is there a better (read, simpler) way to implement this?
Code examples will be much appreciated :)
Thanks.

推荐答案

主要原理是:不要从控件中填充控件.

而是创建一个(小)数据层.从数据填充所有控件.当控件事件应该更改某些数据时,请在数据层上进行操作,然后向所有控件使用的其他控件发送通知,以重新填充或相应地调整数据表示.也就是说,您的控件应该扮演侦听器可观察数据结构的角色.即使您没有明确介绍这些概念(尽管建议这样做),代码的设计也应遵循这种或类似的模式.

我建议您学习并分析以下建筑模式的适用性( http://en.wikipedia .org/wiki/Architectural_pattern_(computer_science) [^ ]):

MVVM —模型视图视图模型,
http://en.wikipedia.org/wiki/Model_View_ViewModel [> http://en.wikipedia.org/wiki/Model-view-controller [ ^ ])),

MVA —模型视图适配器,
http://en.wikipedia.org/wiki/Model–view–adapter [ ^ ],

MVP —模型视图呈现器,
> http://en.wikipedia.org/wiki/Model-view-presenter [ ^ ].
请注意这些架构的动机.如果您了解它,就可以提出更好的设计思路.

—SA
Main principle is this: don''t populate a control from a control.

Instead, create a (tiny) data layer. Populate all controls from data. When a control event is supposed to change some data, do it on your data layer, then send a notifications to other controls used by all controls to re-populate or adjust data presentation accordingly. That means, you control should play the role of listeners or the observable data structure. Even if you don''t introduce those concept explicitly (which is recommended though), the design of the code should follow this or similar pattern.

I suggest you learn and analyze applicability of the following architectural patterns (http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)[^]):

MVVM — Model View View Model,
http://en.wikipedia.org/wiki/Model_View_ViewModel[^],

MVC — Model-View-Controller,
http://en.wikipedia.org/wiki/Model-view-controller[^]),

MVA — Model-View-Adapter,
http://en.wikipedia.org/wiki/Model–view–adapter[^],

MVP — Model-View-Presenter,
http://en.wikipedia.org/wiki/Model-view-presenter[^].
Pay attention for the motivation of those architectures. If you understand it, you would be able to create better design ideas.

—SA


始终将业务逻辑与UI逻辑分开,尤其是在MFC中.您可以定义的越清晰,应用程序运行的越好,维护起来就越容易.如果我需要管理多个窗口的设置,那么我通常会使用一个静态应用程序状态类,这样,两个窗口就不需要了解彼此.他们只需要从应用程序状态对象中填充自己即可.让每个人都响应更改的简单方法是创建一些窗口可以响应的自定义窗口消息,以便仅知道它们需要什么.
Always separate business logic from UI logic, especially in MFC. The clearer you can define these, the better your application will run and the easier it will be to maintain. I usually use a static application state class if I need to manage settings for multiple windows so that no two windows need to know anything about each other. They just need to populate themselves from the application state object. The easy way to get each one to respond to changes is to create some custom window messages that windows can respond to in order to know only what they need to.


这篇关于如何用对话框控件中的值填充CList?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆