⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 control.cpp

📁 通用网络游戏开发框架
💻 CPP
字号:
// ============================================================================
// Control implementation
//
// (c) 2003 Ken Reed
//
// This is free software. You can redistribute it and/or modify it under the
// terms of the GNU General Public License version 2 as published by the Free
// Software Foundation.
// ============================================================================

#include "stdafx.h"
#include "control.h"
#include "exception.h"

#include <commctrl.h>
#include <vector>

using namespace std;

namespace {
   vector<Control *> controls;
}


// ============================================================================
// Construction
// ============================================================================

Control::Control(const int control_id)
{
   id = control_id;
   controls.push_back(this);
}


// ============================================================================
// Register controls
// ============================================================================

void register_controls(HWND dialog_window)
{
   vector<Control *>::iterator p;

   for (p = controls.begin(); p != controls.end(); p++) {
      (*p)->dialog = dialog_window;
      (*p)->handle = GetDlgItem(dialog_window, (*p)->id);
      if ((*p)->handle == 0) {
         Win_exception e("Could not obtain control handle");
         RAISE(e);
      }
   }
}


// ============================================================================
// Get check button state
// ============================================================================

bool Control::get_state()
{
   int state = IsDlgButtonChecked(dialog, id);
   if (state == BST_CHECKED) {
      return true;
   }

   return false;
}


// ============================================================================
// Set enabled state
// ============================================================================

void Control::enable(bool state)
{
   EnableWindow(handle, state);
}


// ============================================================================
// Set checked state
// ============================================================================

void Control::checked(bool set_tick)
{
   if (set_tick) {
      SendMessage(handle, BM_SETCHECK, BST_CHECKED, 0);
   }
   else {
      SendMessage(handle, BM_SETCHECK, BST_UNCHECKED, 0);
   }
}


// ============================================================================
// Set range
// ============================================================================

void Control::set_range(int low, int high)
{
   SendMessage(handle, UDM_SETRANGE, 0, MAKELONG(high, low));
}


// ============================================================================
// Set value
// ============================================================================

void Control::set_value(int value)
{
   SendMessage(handle, UDM_SETPOS, 0, MAKELONG(value, 0));
}


// ============================================================================
// Get value
// ============================================================================

int Control::get_value()
{
   return (int) SendMessage(handle, UDM_GETPOS, 0, 0);
}


// ============================================================================
// Convert to HWND
// ============================================================================

Control::operator HWND() const
{
   return handle;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -