属性表数据验证
当用户单击属性表上的“确定”或“应用”按钮并且程序确定某些页面上的数据无效时,如何使包含错误的页面与描述错误的消息框一起显示?
目前,执行验证的过程在处理 PSN_APPLY 通知时执行以下操作。
MessageBox (hDlg, "Data must be positive!", "Error", MB_OK);
SetWindowLong (hDlg, DWL_MSGRESULT, PSNRET_INVALID);
如果当前显示执行验证的页面 (A),但如果正在显示某个其他页面 (B),则此方法可以正常工作,则将显示消息框并显示该页面 (B),然后当回答消息框时,页面显示验证错误 (A)。我考虑过设置一些标志,以便当该页面 (A) 收到 PSN_SETACTIVE 通知时,它会显示消息框,但这似乎有点做作。
C++ 中的 Win32 API,没有 MFC,没有 NET,没什么花哨的。
When the user clicks the OK or APPLY button on a property sheet and the program determines data on some page is invalid, how can I cause the page containing the error to be displayed along with a message box describing the error?
Currently the procedure doing the validation does the following while processing the PSN_APPLY notification.
MessageBox (hDlg, "Data must be positive!", "Error", MB_OK);
SetWindowLong (hDlg, DWL_MSGRESULT, PSNRET_INVALID);
This works ok if the page doing the validation (A) is currently displayed but if some other page (B) is being displayed, the message box appears with that page (B) being displayed, then when the message box is answered, the page with the validation error (A) is displayed. I thought about setting some flag so that when that page (A) gets the PSN_SETACTIVE notification it displays the message box but that seems kind of hokey.
Win32 API in c++, no MFC, no NET, nothing fancy.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题在于验证的设计及其演示。
我是否正确地认为您会迭代属性表,验证它们并在出现问题时显示消息框?因为当然,如果我在属性页 3 上,并且我在属性页 1 上的字段中写入了废话,那么您所目睹的事情就会发生。
最简单的解决方案是,在验证时,记下有问题的字段是哪个属性页,然后如果用户在您的字段之一中写入了废话,则将其设置为活动状态。这似乎是最快的方法。
另外,不要弹出一个烦人的消息框,而是在属性页下方保留一些空间来显示有关原因的文本(红色或其他)警告,然后更改到适当的属性页,并突出显示有问题的控制。您的验证例程可以在循环过程中轻松轻松地完成此任务。
更好的是,不要因第一个错误而停止。我讨厌的一件事是纠正一个我认为是唯一问题的字段,每次我点击“确定”或“提交”时都会被告知我还错过了其他内容。
我认真地认为你应该考虑在这里加倍努力......循环所有控件,并将所有无效控件添加到列表中。然后更改每个有问题的控件的背景颜色、选项卡颜色等...然后用户可以完成并纠正,无论他或她犯了多少错误。
I think the problem is in the design of your validation and it's presentation.
Am I right in thinking that you iterate through your property sheets, validate them and display a message box if something is awry? Because of course, what you have witnessed will happen, if I am on property page 3 and I wrote crap in to a field on property page 1.
The easiest solution is, when validating, note which property page the field in question is, and set that one active if the user has written crap in to one of your fields. This seems the fastest way possible.
Also, rather than spring up an annoying message box, reserve some room beneath the property pages to display a textual (red or otherwise) warning as to why, and then change to the appropriate property page, and highlight the offending control. Your validation routine can do this nice and easily as it loops through.
Even better, don't stop at the first error. One thing I HATE is correcting one field that I think is the only issue, only to be told every time I hit "OK" or "SUBMIT" that there's something else I missed.
I seriously think you should consider going the extra mile here... loop through ALL controls, and add all invalid ones to a list. Then change each offending control's background colour, tab colour etc... Then the user can work through and correct, no matter how many errors he or she made.