Counter Strike : Global Offensive Source Code
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.

58 lines
1.7 KiB

  1. #include <windows.h>
  2. /* test_bitboxes() - use a static text box for selecting/changing a list of bits, hex bytes,
  3. or other evenly spaced things. */
  4. /* scrPos.x = x coord */
  5. /* scrPos.y = y coord */
  6. /* box_id = an array of dialog ID's, one for each box */
  7. /* ndiv = number of divisions per box */
  8. /* nboxes = number of boxes */
  9. /* return value = selection number or -1 if point is outside of all boxes */
  10. int
  11. test_bitboxes( HWND hDlg, unsigned long pos, unsigned ndiv, int nboxes, const int *box_id )
  12. {
  13. int i;
  14. POINT scrPos;
  15. /* find current position in screen coordinates. */
  16. scrPos.x = (int)LOWORD(pos);
  17. scrPos.y = (int)HIWORD(pos);
  18. ClientToScreen(hDlg, &scrPos);
  19. for( i = 0; i < nboxes; i++ ) {
  20. RECT box;
  21. HWND hWndItem;
  22. HDC hDC;
  23. static char buf[100];
  24. /* Check point against bounding box of text box */
  25. hWndItem = GetDlgItem(hDlg, box_id[i]);
  26. GetWindowRect(hWndItem, &box);
  27. GetWindowText(hWndItem, buf, sizeof(buf));
  28. hDC = GetDC(hWndItem);
  29. if (hDC) {
  30. SIZE stringSize;
  31. GetTextExtentPoint(hDC, buf, strlen(buf), &stringSize);
  32. // heuristic rule: sometimes GetTextExtentPoint lies
  33. // when the font is manually reduced in size, say 70%.
  34. // So, only believe the string size if it is smaller
  35. // than the box size.
  36. if (stringSize.cx < (box.right - box.left)) {
  37. // now correct the right side of box for string size.
  38. box.right=box.left + stringSize.cx;
  39. }
  40. ReleaseDC(hWndItem,hDC);
  41. }
  42. if( scrPos.x > box.left && scrPos.x < box.right &&
  43. scrPos.y > box.top && scrPos.y < box.bottom ) {
  44. /* Check which character the point is in */
  45. return (ndiv*i + (ndiv*(scrPos.x - box.left)) / (box.right - box.left));
  46. }
  47. }
  48. return -1;
  49. }