This topic is now archived and is closed to further replies.


Common file CD3DApplication::SelectDeviceProc

Recommended Posts

Please bear with me. I tried to logically approach the question. It is simple for most of you. 1-this is in the common file frame programs. I am progressing slowly to go through all the source code of the SDK common. 2-Method CD3Dapplication::BuildDeviceList. I comprehended peacefully 3-In CD3Dapplication::BuildDeviceList, the programmer builds a list of adapters, devices, and modes. All the information is stored in a structure array that is a member variable of CD3Dapplication. This member variable will be used by other methods later. 4- CD3Dapplication::SelectDeviceProc is a dialog procedure that deals with the UI for selecting a device, full screen mode vs windowed, adapter modes, and antialiazing selection. It is part 4 above that I need help with Lets us write some psecude. If this simplified code is confusing, you can open the common file frame CD3DApplication::SelectDeviceProc.
INT_PTR CALLBACK CD3DApplication::SelectDeviceProc( HWND hDlg, UINT msg,
                                                    WPARAM wParam, LPARAM lParam )
1-HWND hwndDeviceList         = GetDlgItem( hDlg, IDC_DEVICE_COMBO );
2-    static CD3DApplication* pd3dApp;
3-    static DWORD  dwOldDevice,  dwNewDevice;
4- if( WM_INITDIALOG == msg )
5- set the dwOldDevice to the value from the adapters information list found in
BuildDeviceList above. That value was stored in an member array of the class
6- dwNewDevice  = dwOldDevice;

7- if( WM_COMMAND == msg ){
8- if( IDOK == LOWORD(wParam) ){
9-if(  dwNewDevice  != dwOldDevice  )
{Update the dialog controls}
My question How did the variable dwNewDevice changed when the user clicks the drop down list(he calls it comboBox) I mean the last time any value was assigned to dwNewDevice is in line 6 above, yet somehere that value changed to take the value from the comboBox in the change device dialog box.

Share this post

Link to post
Share on other sites
SelectDeviceProc is a windows message processing function handling the user interaction with the "Select Device" dialog (I think you got that far). The dwNewDevice variable, and some others are "static" and their contents are preserved no matter how many times windows calls the procedure.

Upon first call; windows will likely be passing a WM_INITDIALOG message, where many values are initialised.

Subsequent calls (that we''re intersted in) will be WM_COMMAND messages and the procedure uses the wParam to distinguish between clicks on the ok and cancel buttons.

The other main message the routine is interested in is the CBN_SELENDOK. This informs the procedure that the user has selected something from one of the combo boxes, the wParam is used to see which combo box it was. The dwNewMode or dwNewDevice variables are changed according to the selection.

When the WM_COMMAND message signifies the click of the OK button the dwNewDevice is compared to dwOldDevice etc etc.

It''s all about Win32 controls and messages really and I think that is what has caught you out.



Share this post

Link to post
Share on other sites
Thanks for the reply
If you can spare a minute with me and open CD3Dapplication::SelectDeviceProc in d3dapp.cpp

and go to "about" line 28 of the procedure as shown below.

dwNewDevice = dwOldDevice;//keep this in mind for a second

now go to the line (I reduced it here for clarity)

if( dwNewDevice != dwOldDevice )//

Now if you run the any SDK sample application that use the common file frame enter the dialog box and change the device, the dwNewDevice will take a value which is different than the value assigned to it in ( dwNewDevice = dwOldDevice)

My question is when the value of dwNewDevice has changed from what has been assigned to it in (dwNewDevice = dwOldDevice)

Many thanks

Share this post

Link to post
Share on other sites
dwNewMode is changed in this else-if block:

else if( CBN_SELENDOK == HIWORD(wParam) )
{ ... }

that code is executed when you pick a different combobox item in one of the comboboxes.

Share this post

Link to post
Share on other sites
I got it now. It took longer time because I got mixed with the nesting levels. Basicly the "Ok", "Cancel", and the selection of any combo box are all in the same "if" level.

Many Thanks for the help.

Share this post

Link to post
Share on other sites