Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
4.1 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: dialog.c
  3. *
  4. * Dialog helper functions
  5. *
  6. * Copyright (c) 1995 Microsoft Corporation
  7. *
  8. \**************************************************************************/
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include <windows.h>
  13. #include <commdlg.h>
  14. #include <commctrl.h>
  15. #include "sscommon.h"
  16. #define BUF_SIZE 30
  17. static TCHAR szSectName[BUF_SIZE];
  18. static TCHAR szItemName[BUF_SIZE];
  19. static TCHAR szFname[BUF_SIZE];
  20. static TCHAR szTmp[BUF_SIZE];
  21. static HINSTANCE hInstance = 0;
  22. /******************************Public*Routine******************************\
  23. * ss_RegistrySetup
  24. *
  25. * Setup for registry access
  26. *
  27. \**************************************************************************/
  28. BOOL ss_RegistrySetup( HINSTANCE hinst, int section, int file )
  29. {
  30. if( LoadString(hInstance, section, szSectName, BUF_SIZE) &&
  31. LoadString(hInstance, file, szFname, BUF_SIZE) )
  32. {
  33. hInstance = hinst;
  34. return TRUE;
  35. }
  36. return FALSE;
  37. }
  38. /******************************Public*Routine******************************\
  39. * ss_GetRegistryInt
  40. *
  41. * Retrieve integer value from registry
  42. *
  43. \**************************************************************************/
  44. int ss_GetRegistryInt( int name, int iDefault )
  45. {
  46. if( LoadString( hInstance, name, szItemName, BUF_SIZE ) ) {
  47. return GetPrivateProfileInt(szSectName, szItemName, iDefault, szFname);
  48. }
  49. return 0;
  50. }
  51. /******************************Public*Routine******************************\
  52. * ss_GetRegistryString
  53. *
  54. * Retrieve string from registry
  55. *
  56. \**************************************************************************/
  57. void ss_GetRegistryString( int name, LPTSTR lpDefault, LPTSTR lpDest,
  58. int bufSize )
  59. {
  60. if( LoadString( hInstance, name, szItemName, BUF_SIZE ) ) {
  61. GetPrivateProfileString(szSectName, szItemName, lpDefault, lpDest,
  62. bufSize, szFname);
  63. }
  64. }
  65. /******************************Public*Routine******************************\
  66. * ss_WriteRegistryInt
  67. *
  68. * Write integer value to registry
  69. *
  70. \**************************************************************************/
  71. void ss_WriteRegistryInt( int name, int iVal )
  72. {
  73. if( LoadString(hInstance, name, szItemName, BUF_SIZE) ) {
  74. wsprintf(szTmp, TEXT("%ld"), iVal);
  75. WritePrivateProfileString(szSectName, szItemName, szTmp, szFname);
  76. }
  77. }
  78. /******************************Public*Routine******************************\
  79. * ss_WriteRegistryString
  80. *
  81. * Write string value to registry
  82. *
  83. \**************************************************************************/
  84. void ss_WriteRegistryString( int name, LPTSTR lpString )
  85. {
  86. if( LoadString(hInstance, name, szItemName, BUF_SIZE) ) {
  87. WritePrivateProfileString(szSectName, szItemName, lpString, szFname);
  88. }
  89. }
  90. /******************************Public*Routine******************************\
  91. * GetTrackbarPos
  92. *
  93. * Get the current position of a common control trackbar
  94. \**************************************************************************/
  95. int
  96. ss_GetTrackbarPos( HWND hDlg, int item )
  97. {
  98. return
  99. (int)SendDlgItemMessage(
  100. hDlg,
  101. item,
  102. TBM_GETPOS,
  103. 0,
  104. 0
  105. );
  106. }
  107. /******************************Public*Routine******************************\
  108. * SetupTrackbar
  109. *
  110. * Setup a common control trackbar
  111. \**************************************************************************/
  112. void
  113. ss_SetupTrackbar( HWND hDlg, int item, int lo, int hi, int lineSize,
  114. int pageSize, int pos )
  115. {
  116. SendDlgItemMessage(
  117. hDlg,
  118. item,
  119. TBM_SETRANGE,
  120. (WPARAM) TRUE,
  121. (LPARAM) MAKELONG( lo, hi )
  122. );
  123. SendDlgItemMessage(
  124. hDlg,
  125. item,
  126. TBM_SETPOS,
  127. (WPARAM) TRUE,
  128. (LPARAM) pos
  129. );
  130. SendDlgItemMessage(
  131. hDlg,
  132. item,
  133. TBM_SETPAGESIZE,
  134. (WPARAM) 0,
  135. (LPARAM) pageSize
  136. );
  137. SendDlgItemMessage(
  138. hDlg,
  139. item,
  140. TBM_SETLINESIZE,
  141. (WPARAM) 0,
  142. (LPARAM) lineSize
  143. );
  144. }