📄 cwnd.hpp
字号:
// This class encapsulates handles
#ifndef _CWND_HPP
#define _CWND_HPP
#include <windows.h>
#include "CString.hpp"
#include "CMenu.hpp"
class CWnd {
protected:
HWND handle; // Handle of window
bool IsOwner; // If we own the handle
public:
// Constructors
CWnd(HWND h) : handle(h) , IsOwner(false) {}
CWnd(CWnd& w) : handle(w.handle) , IsOwner(false) {} // Note: Ownership is not passed when copying
CWnd() : handle((HWND)NULL) , IsOwner(false){}
CWnd(CWnd& father,int nID) : handle(father.GetItem(nID).GetHWND()) , IsOwner(false) {}
CWnd& operator=(CWnd& w); // note: Ownership is NOT passed when assigning!
// To get and set Handle at runtime
bool SetHWND(HWND h);
bool SetHWND(CWnd& father,int nID);
HWND GetHWND() const { return handle; }
// To know if it is a child of us
bool IsChild(CWnd& child) { return ::IsChild(GetHWND(),child.GetHWND()) == TRUE; }
// To get Parent window
CWnd GetParent() const { return CWnd( ::GetParent(GetHWND()) ); }
// To post a message to the window
LONG PostMessage(UINT message,WPARAM wParam,LPARAM lParam) const { return ::PostMessage(GetHWND(), message, wParam, lParam); }
// To Send a message to the window
LONG SendMessage(UINT message,WPARAM wParam,LPARAM lParam) const { return ::SendMessage(GetHWND(), message, wParam, lParam); }
// To set longs
void SetLong(UINT Idx,LONG nbr) const { ::SetWindowLong(GetHWND(),Idx,nbr); }
// To show/hide windows
void Show(BOOL ShowIt=TRUE) const { ::ShowWindow(GetHWND(),ShowIt); }
// To get an Item contained in the window
CWnd GetItem(int nID) { return CWnd( ::GetDlgItem(GetHWND(),nID)); }
// To set Text
void SetText(LPTSTR Text) { ::SetWindowText(GetHWND(),Text); }
void SetText(CString& Text) { ::SetWindowText(GetHWND(),Text.Ptr()); }
// To get the Text
CString GetText();
// To create windows
bool Create(DWORD dwExStyle, LPCTSTR ClassName, LPCTSTR WindowName, DWORD dwStyle,int x,int y,int Width,int Height,CWnd& Parent, CMenu& Menu, HINSTANCE Instance, LPVOID lpParam);
// To check if window is open
bool IsOpen() const { return handle != NULL; }
// To destroy window if we own it
bool Destroy();
// Window destructor
~CWnd() { Destroy(); }
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -