tlib

tlib是一个轻便、精小的win32窗口程序框架,配合ResEdit工具来绘制图形程序的用户界面,仅仅通过少量的代码来实现对图形界面的控制

Demo

使用ResEdit新建一个Resource script(*.rc)工程,并绘制一个窗口界面,保存文件为resource.res

编写程序(注意使用GB2312编码)

#include "resource.h"
#include "tlib.h"

/*----------------------------------------------------------------------
|   TMainWin
+---------------------------------------------------------------------*/
class TMainWin : public TDlg {
 public:
  TMainWin(TWin *_parent = NULL);
  virtual ~TMainWin() override;

  TMainWin(const TMainWin &) = delete;
  TMainWin &operator=(const TMainWin &) = delete;

  virtual BOOL EvCommand(WORD wNotifyCode, WORD wID,
                         LPARAM hwndCtl) override final;
  virtual BOOL EvCreate(LPARAM lParam) override final;

  virtual void Destroy(void) override final;
  virtual BOOL EvClose(void) override final;

 private:
  HWND btn1Wnd;
  HWND btn2Wnd;
  HWND btn3Wnd;
};

TMainWin::TMainWin(TWin *_parent)
  : TDlg(IDD_DIALOG1, _parent) {
  hAccel = ::LoadAccelerators(TApp::GetInstance(), MAKEINTRESOURCE(IDR_ACCELERATOR1));
}

TMainWin::~TMainWin() {
}

BOOL TMainWin::EvCreate(LPARAM lParam) {

  btn1Wnd = GetDlgItem(IDM_OK);
  btn2Wnd = GetDlgItem(IDM_CANCEL);
  btn3Wnd = GetDlgItem(IDM_EXIT);

  return TRUE;
}

BOOL TMainWin::EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl) {
  int wmId = LOWORD(wID);
  switch (wmId) {
    case IDM_OK:
      ::MessageBox(NULL, "你按下了确认键", "提示", MB_OK);
      break;
    case IDM_CANCEL:
      ::MessageBox(NULL, "你按下了取消键", "提示", MB_OK);
      break;
    case IDM_EXIT:
      ::MessageBox(NULL, "关闭界面", "提示", MB_OK);
      DestroyWindow(hWnd);
      break;
    default:
      return FALSE;
  }
  return TRUE;
}

void TMainWin::Destroy(void) { PostQuitMessage(0); }

BOOL TMainWin::EvClose(void) {
  EndDialog(0);
  PostQuitMessage(0);
  return TRUE;
}

/*----------------------------------------------------------------------
|   SimpleUIApp
+---------------------------------------------------------------------*/
class SimpleUIApp : public TApp {
 public:
  explicit SimpleUIApp(HINSTANCE _hI);
  virtual ~SimpleUIApp() override;

  SimpleUIApp(const SimpleUIApp &) = delete;
  SimpleUIApp &operator=(const SimpleUIApp &) = delete;

  virtual void InitWindow(void) override final;
};

SimpleUIApp::SimpleUIApp(HINSTANCE _hI)
  : TApp(_hI) {
}

SimpleUIApp::~SimpleUIApp() {
}

void SimpleUIApp::InitWindow(void) {
  mainWnd = new TMainWin();
  mainWnd->Create();
  mainWnd->Show();
}

auto main(int argc, char **argv) -> int {

  HINSTANCE hInstance = GetModuleHandle(NULL);
  SimpleUIApp app(hInstance);

  return app.Run();;
}

程序源码

https://gitee.com/silentdxx/tlib.git