1 void DXUTDisplaySwitchingToREFWarning()
2 {
3 if( DXUTGetShowMsgBoxOnError() )
4 {
5 // Open the appropriate registry key
6 DWORD dwSkipWarning = 0;
7 HKEY hKey;
8 LONG lResult = RegOpenKeyEx( HKEY_CURRENT_USER, L"Software\\Microsoft\\DirectX 9.0 SDK", 0, KEY_READ, &hKey );
9 if( ERROR_SUCCESS == lResult )
10 {
11 DWORD dwType;
12 DWORD dwSize = sizeof(DWORD);
13 /*
14 获取一个项的设置值
15 返回值
16 Long,零(ERROR_SUCCESS)表示成功。其他任何值都代表一个错误代码
17 参数表
18 参数 类型及说明
19 HKEY hKey,一个已打开项的句柄,或者指定一个标准项名
20 LPCTSTR lpValueName,要获取值的名字
21 LPDWORD lpReserved,未用,设为零
22 LPDWORD lpType,用于装载取回数据类型的一个变量
23 LPBYTE lpData,用于装载指定值的一个缓冲区
24 LPDWORD lpcbData,用于装载lpData缓冲区长度的一个变量。一旦返回,它会设为实际装载到缓冲区的字节数
25 */
26 lResult = RegQueryValueEx( hKey, L"Skip Warning On REF", NULL, &dwType, (BYTE*)&dwSkipWarning, &dwSize );
27 RegCloseKey( hKey );
28 }
29
30 if( dwSkipWarning == 0 )
31 {
32 // Compact code to create a custom dialog box without using a template in a resource file.
33 // If this dialog were in a .rc file, this would be a lot simpler but every sample calling this function would
34 // need a copy of the dialog in its own .rc file. Also MessageBox API could be used here instead, but
35 // the MessageBox API is simpler to call but it can't provide a "Don't show again" checkbox
36 //设置对话框
37 typedef struct { DLGITEMTEMPLATE a; WORD b; WORD c; WORD d; WORD e; WORD f; } DXUT_DLG_ITEM;
38 typedef struct { DLGTEMPLATE a; WORD b; WORD c; WCHAR d[2]; WORD e; WCHAR f[14]; DXUT_DLG_ITEM i1; DXUT_DLG_ITEM i2; DXUT_DLG_ITEM i3; DXUT_DLG_ITEM i4; DXUT_DLG_ITEM i5; } DXUT_DLG_DATA;
39
40 DXUT_DLG_DATA dtp =
41 {
42 {WS_CAPTION|WS_POPUP|WS_VISIBLE|WS_SYSMENU|DS_ABSALIGN|DS_3DLOOK|DS_SETFONT|DS_MODALFRAME|DS_CENTER,0,5,0,0,269,82},0,0,L" ",8,L"MS Sans Serif",
43 {{WS_CHILD|WS_VISIBLE|SS_ICON|SS_CENTERIMAGE,0,7,7,24,24,0x100},0xFFFF,0x0082,0,0,0}, // icon
44 {{WS_CHILD|WS_VISIBLE,0,40,7,230,25,0x101},0xFFFF,0x0082,0,0,0}, // static text
45 {{WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,0,80,39,50,14,IDYES},0xFFFF,0x0080,0,0,0}, // Yes button
46 {{WS_CHILD|WS_VISIBLE,0,133,39,50,14,IDNO},0xFFFF,0x0080,0,0,0}, // No button
47 {{WS_CHILD|WS_VISIBLE|BS_CHECKBOX,0,7,59,70,16,IDIGNORE},0xFFFF,0x0080,0,0,0}, // checkbox
48 };
49
50 int nResult = (int) DialogBoxIndirect( DXUTGetHINSTANCE(), (DLGTEMPLATE*)&dtp, DXUTGetHWND(), DisplaySwitchToREFWarningProc );
51
52 //写入注册表保存,不再提示
53 if( (nResult & 0x80) == 0x80 ) // "Don't show again" checkbox was checked
54 {
55 lResult = RegOpenKeyEx( HKEY_CURRENT_USER, L"Software\\Microsoft\\DirectX 9.0 SDK", 0, KEY_WRITE, &hKey );
56 if( ERROR_SUCCESS == lResult )
57 {
58 dwSkipWarning = 1;
59 RegSetValueEx( hKey, L"Skip Warning On REF", 0, REG_DWORD, (BYTE*)&dwSkipWarning, sizeof(DWORD) );
60 RegCloseKey( hKey );
61 }
62 }
63
64 // User choose not to continue
65 if( (nResult & 0x0F) == IDNO )
66 DXUTShutdown(1);
67 }
68 }
69 }
1 //--------------------------------------------------------------------------------------
2 // MsgProc for DXUTDisplaySwitchingToREFWarning() dialog box
3 //--------------------------------------------------------------------------------------
4 INT_PTR CALLBACK DisplaySwitchToREFWarningProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
5 {
6 switch (message)
7 {
8 case WM_INITDIALOG:
9 // Easier to set text here than in the DLGITEMTEMPLATE
10 SetWindowText( hDlg, DXUTGetWindowTitle() );
11 SendMessage( GetDlgItem(hDlg, 0x100), STM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadIcon(0, IDI_QUESTION));
12 SetDlgItemText( hDlg, 0x101, L"Switching to the Direct3D reference rasterizer, a software device\nthat implements the entire Direct3D feature set, but runs very slowly.\nDo you wish to continue?" );
13 SetDlgItemText( hDlg, IDYES, L"&Yes" );
14 SetDlgItemText( hDlg, IDNO, L"&No" );
15 SetDlgItemText( hDlg, IDIGNORE, L"&Don't show again" );
16 break;
17
18 case WM_COMMAND:
19 switch (LOWORD(wParam))
20 {
21 case IDIGNORE: CheckDlgButton( hDlg, IDIGNORE, (IsDlgButtonChecked( hDlg, IDIGNORE ) == BST_CHECKED) ? BST_UNCHECKED : BST_CHECKED ); EnableWindow( GetDlgItem( hDlg, IDNO ), (IsDlgButtonChecked( hDlg, IDIGNORE ) != BST_CHECKED) ); break;
22 case IDNO: EndDialog(hDlg, (IsDlgButtonChecked( hDlg, IDIGNORE ) == BST_CHECKED) ? IDNO|0x80 : IDNO|0x00 ); return TRUE;
23 case IDCANCEL:
24 case IDYES: EndDialog(hDlg, (IsDlgButtonChecked( hDlg, IDIGNORE ) == BST_CHECKED) ? IDYES|0x80 : IDYES|0x00 ); return TRUE;
25 }
26 break;
27 }
28 return FALSE;
29 }