Click to See Complete Forum and Search --> : [RESOLVED] DialogBox() VC++ 6 question
ifdef
October 22nd, 2008, 01:29 PM
I am working with some legacy code that uses the old VC++ 6 DialogBox call to create and update fields on a form. I'm looking to add a refresh button to this form. I have been able to add a button by manually editing the resource file but don't know how to trigger a refresh on the button click. To solve that problem I would like to know more about how the DialogBox function works.
I have read that the form will terminate when the EndDialog function is called. what happens between when the function that was passed into the form finishes and the user clicks the "&Close" button on the form to close the window?
Why do some buttons have names have an ampersand, "&", as their first character, Eg "&Close", and why dose the ampersand now show up in the buttons name on the form?
Would their be any problem having the function that is passed to the DialogBox run in a while loop polling to see if a button on the form was clicked?
Thanks,
kirants
October 22nd, 2008, 02:07 PM
I am working with some legacy code that uses the old VC++ 6 DialogBox call to create and update fields on a form. I'm looking to add a refresh button to this form. I have been able to add a button by manually editing the resource file but don't know how to trigger a refresh on the button click.
And what exactly does refresh do? Does it populate the controls on the dialog box with some new information.
I have read that the form will terminate when the EndDialog function is called. what happens between when the function that was passed into the form finishes and the user clicks the "&Close" button on the form to close the window?
Your dialog box procedure will be sent messages for you to process. If you do not do anything, they will be handled by the default dialog box procedure.
Why do some buttons have names have an ampersand, "&", as their first character, Eg "&Close", and why dose the ampersand now show up in the buttons name on the form?
Putting a & in front of a text on a button/static/menu item will place a underscore on the character next to it when the window shows up. That is a visual indication that the control can be reached by using the Alt key and the character combination. Slightly tricky, in case of buttons, the Alt - character combination would simulate a button click. In case of static control, the focus will be set to the control next to the static ( in tab order ).
[Would their be any problem having the function that is passed to the DialogBox run in a while loop polling to see if a button on the form was clicked?
No polling. Windows is a message driven system, so your dialog box procedure would listen in on messages. In case of button click, you would listen in on WM_COMMAND message and check for the WPARAM and LPARAM and do the necessary.
If you plan to do Windows programming for a while, suggest reading up a book that will explain a lot of these questions you already have and more that you will have later.
ifdef
October 22nd, 2008, 03:17 PM
And what exactly does refresh do? Does it populate the controls on the dialog box with some new information.
Right now the form controlls, check boxes & labels, are populated with data from the program. Refresh will repopulate these controlls with the newer data.
Your dialog box procedure will be sent messages for you to process. If you do not do anything, they will be handled by the default dialog box procedure.
Given:
DialogBox( hInstance, lpTemplate, hWndParent, (DLGPROC) lpDialogFunc);
What your saying is that DialogBox will exicute lpDialogFunc. Then lpDialogFunc will send messages to the form.
No polling. Windows is a message driven system, so your dialog box procedure would listen in on messages. In case of button click, you would listen in on WM_COMMAND message and check for the WPARAM and LPARAM and do the necessary.
Where would I listen for the messages? My orignal idea was to have the function lpDialogFunc loop and check for updates. Where would I put the listener if not in lpDialogFunc and how would I register it with the events on that form?
kirants
October 22nd, 2008, 03:26 PM
What your saying is that DialogBox will exicute lpDialogFunc. Not execute, but call it whenever there is a windows message.
Where would I listen for the messages? My orignal idea was to have the function lpDialogFunc loop and check for updates.
See example here:
http://msdn.microsoft.com/en-us/library/ms644996(VS.85).aspx
Note how IDOK is handled. You would do something similar for the refresh button and do the appropriate.
ifdef
October 22nd, 2008, 05:05 PM
I see, I tested the code I have by commenting out a EndDialog call and inserting a MessageBox. Every time i clicked "ok" I got my pop-up. How do I look for my specific button press?
I'm looking at:
http://msdn.microsoft.com/en-us/library/bb761825(VS.85).aspx
It seems like BN_CLICKED would take the two parameters and then i would inspect them for the element ID that my control was assigned then the event. Only thing is that the function doesn't look like it takes parameters by reference.
Thanks for all you help so far, I've learned a lot from your posts.
kirants
October 22nd, 2008, 05:54 PM
Repeat:
In case of button click, you would listen in on WM_COMMAND message and check for the WPARAM and LPARAM and do the necessary. Check documentation on WM_COMMAND also.
You would look for WM_COMMAND, and then you would look for HIWORD of the wParam that comes with it to see if it is BN_CLICKED and if it is, you would extract the LOWORD of wParam and check if it is the ID of refresh button and if it is.. do the stuff you need to do.
ifdef
October 23rd, 2008, 08:33 AM
I see now how to test wParam with LOWWORD to see if my control was sending a message. I have tested this in my code and its working. Thanks for all the help! :)
kirants
October 23rd, 2008, 10:46 AM
You are welcome. Again, I encourage you to get a book on Windows programming ( Charles Petzold is a good one for understanding basics of UI programming ) and go that route.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.