/*
* Window.h
* Copyright (c) 2009 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL++2000
// 2008/08/13 Added setRedraw method.
// 2008/12/12 Added setText(const wchar_t*) method.
#pragma once
#include <sol\Object.h>
#include <sol\Typedef.h>
#include <sol/String.h>
#include <sol/StringT.h>
#include <sol/Event.h>
namespace SOL {
class Window :public Object {
private:
HWND hwnd;
public:
Window()
:hwnd(null)
{
//
}
public:
~Window()
{
}
public:
TCHAR* getText()
{
int len = getTextLength();
TCHAR* text = new TCHAR[len + 1];
if(text) {
::GetWindowText(hwnd, text, len+1);
}
return text;
}
HWND childWindowFromPoint(POINT pt) {
return ::ChildWindowFromPoint(hwnd, pt);
}
void destroyWindow() {
if (isWindow())
::DestroyWindow(hwnd);
}
Boolean isEqual(HWND handle) {
return (hwnd == handle);
}
void enableWindow(Boolean flag) {
::EnableWindow(hwnd, flag);
}
void getClassName(TCHAR* name, int size) {
::GetClassName(hwnd, name, size);
}
HWND getFocus() {
return ::GetFocus();
}
HINSTANCE getInstanceHandle() {
return (HINSTANCE)getWindowLong(GWL_HINSTANCE);
}
Boolean getPlacement(WINDOWPLACEMENT* place) {
return ::GetWindowPlacement(hwnd, place);
}
HANDLE getProp(const TCHAR* name) {
return ::GetProp(hwnd, name);
}
HWND getWindow() { return hwnd; }
long getWindowLong(int indx) {
return ::GetWindowLong(hwnd, indx);
}
WORD getWindowWord(int indx) {
return ::GetWindowWord(hwnd, indx);
}
long getClassLong(int indx) {
return ::GetClassLong(hwnd, indx);
}
WORD getClassWord(int indx) {
return ::GetClassWord(hwnd, indx);
}
//2008/07/02
virtual void getClientSize(int& width, int& height) {
RECT r;
::GetClientRect(hwnd, &r);
width = r.right - r.left;
height = r.bottom - r.top;
}
virtual void getClientRect(RECT* rect) {
::GetClientRect(hwnd, rect);
}
void getWindowRect(RECT* rect) {
::GetWindowRect(hwnd, rect);
}
Boolean isEnabled() {
return ::IsWindowEnabled(hwnd);
}
Boolean isVisible() {
return ::IsWindowVisible(hwnd);
}
Boolean isWindow() {
return ::IsWindow(hwnd);
}
Boolean killTimer(UINT id) {
return ::KillTimer(hwnd, id);
}
void move(int x, int y, int width, int height, Boolean flag = TRUE) {
::MoveWindow(hwnd, x, y, width, height, flag);
}
virtual void reshape(int x, int y, int width, int height, Boolean flag = TRUE) {
::MoveWindow(hwnd, x, y, width, height, flag);
}
//2009/10/17
int getText(__out String& text) {
size_t size = ::GetWindowTextLength(hwnd);
if (size>0) {
TCHAR* tstring = new TCHAR[size+1];
if (GetWindowText(hwnd, tstring, size+1)>0) {
text.shallowCopy(tstring);
}
}
return size;
}
//2009/10/18
int getText(__out StringT<char>& text) {
size_t size = ::GetWindowTextLengthA(hwnd);
if (size>0) {
char* string = new char[size+1];
if (GetWindowTextA(hwnd, string, size+1)>0) {
text.shallowCopy(string);
}
}
return size;
}
//2009/10/18
int getText(__out StringT<wchar_t>& text) {
size_t size = ::GetWindowTextLengthW(hwnd);
if (size>0) {
wchar_t* string = new wchar_t[size+1];
if (
GetWindowTextW(hwnd, string, size+1)>0) {
text.shallowCopy(string);
}
}
return size;
}
int getText(char* text, size_t len) {
return ::GetWindowTextA(hwnd, text, len);
}
int getText(wchar_t* text, size_t len) {
return ::GetWindowTextW(hwnd, text, len);
}
int getTextLength() {
return ::GetWindowTextLength(hwnd);
}
int getCharTextLength() {
return ::GetWindowTextLengthA(hwnd);
}
int getWCharTextLength() {
return ::GetWindowTextLengthW(hwnd);
}
void getCursorPos(POINT* p) {
::GetCursorPos(p);
}
Boolean invalidate(const RECT* rect, Boolean flag = TRUE) {
return ::InvalidateRect(hwnd, rect, flag);
}
Boolean invalidate(HRGN r, Boolean flag = TRUE) {
return ::InvalidateRgn(hwnd, r, flag);
}
long post(UINT message, WPARAM wParam, LPARAM lParam) {
return ::PostMessage(hwnd, message, wParam, lParam);
}
HANDLE removeProp(const TCHAR* name) {
return ::RemoveProp(hwnd, name);
}
Boolean releaseCapture() {
return ::ReleaseCapture();
}
int showCursor(Boolean flag) {
return ::ShowCursor(flag);
}
Boolean scroll(int dx, int dy, RECT* scroll, RECT* clip,
HRGN hrgnUpdate=NULL,LPRECT prcUpdate=NULL,
UINT flags = SW_ERASE|SW_INVALIDATE|SW_SCROLLCHILDREN) {
return ::ScrollWindowEx(hwnd, dx, dy, scroll, clip,
hrgnUpdate, prcUpdate, flags);
}
long send(UINT message, WPARAM wParam, LPARAM lParam) {
return ::SendMessage(hwnd, message, wParam, lParam);
}
void setClassLong(int indx, long val) {
::SetClassLong(hwnd, indx, val);
}
void setClassWord(int indx, WORD val) {
::SetClassWord(hwnd, indx, val);
}
HWND setFocus(HWND target) {
return ::SetFocus(target);
}
HWND setFocus() {
return ::SetFocus(hwnd);
}
void setParent(HWND hParent) {
::SetParent(hwnd, hParent);
}
Boolean setPlacement(WINDOWPLACEMENT* place) {
return ::SetWindowPlacement(hwnd, place);
}
Boolean setPos(HWND insertAfter, int x, int y, int width,
int height, UINT flag) {
return ::SetWindowPos(hwnd, insertAfter, x, y,
width, height, flag);
}
Boolean setProp(const TCHAR* name, HANDLE data) {
return ::SetProp(hwnd, name, data);
}
//<modified date="2009/10/12">
void setText(const char* text) {
::SetWindowTextA(hwnd, text);
}
void setText(const wchar_t* text) {
::SetWindowTextW(hwnd, text);
}
//</modified>
UINT setTimer(UINT id, UINT elapse, TIMERPROC proc) {
return ::SetTimer(hwnd, id, elapse, proc);
}
void setWindow(HWND hwnd1) {
hwnd = hwnd1;
}
void capture() {
::SetCapture(hwnd);
}
Boolean setForegroundWindow() {
return ::SetForegroundWindow(hwnd);
}
void setWindowLong(int indx, LONG val) {
::SetWindowLong(hwnd, indx, val);
}
void setWindowWord(int indx, WORD val) {
::SetWindowWord(hwnd, indx, val);
}
void show(int cmd) {
::ShowWindow(hwnd, cmd);
}
void toClient(POINT* pt) {
::ScreenToClient(hwnd, pt);
}
void toScreen(POINT* pt) {
::ClientToScreen(hwnd, pt);
}
void update() {
::UpdateWindow(hwnd);
}
void update(const RECT* r) {
invalidate(r);
::UpdateWindow(hwnd);
}
Boolean flash(Boolean invert) {
return ::FlashWindow(hwnd, invert);
}
HWND getLastActivePopup() {
return ::GetLastActivePopup(hwnd);
}
HWND getTopWindow() {
return ::GetTopWindow(hwnd);
}
DWORD getThreadProcessId(DWORD* processId) {
return ::GetWindowThreadProcessId(hwnd, processId);
}
Boolean redraw(const RECT* rect, HRGN rgn, UINT flags) {
return ::RedrawWindow(hwnd, rect, rgn, flags);
}
Boolean validate(const RECT* r) {
return ::ValidateRect(hwnd, r);
}
Boolean validate(HRGN r) {
return ::ValidateRgn(hwnd, r);
}
Boolean send(UINT message, WPARAM wParam, LPARAM lParam,
SENDASYNCPROC callback, DWORD data) {
return ::SendMessageCallback(hwnd, message,
wParam, lParam, callback, data);
}
long send(UINT message, WPARAM wParam, LPARAM lParam,
UINT flags, UINT timeOut, DWORD* result) {
return ::SendMessageTimeout(hwnd, message,
wParam, lParam, flags, timeOut, result);
}
long sendNotify(UINT message, WPARAM wParam, LPARAM lParam) {
return ::SendNotifyMessage(hwnd, message,
wParam, lParam);
}
Boolean showAsync(int cmd) {
return ::ShowWindowAsync(hwnd, cmd);
}
Boolean hideOwnedPopups() {
return ::ShowOwnedPopups(hwnd, FALSE);
}
Boolean showOwnedPopups() {
return ::ShowOwnedPopups(hwnd, TRUE);
}
//2008/08/13
public:
void setRedraw(BOOL flag) {
send(WM_SETREDRAW, flag, 0);
}
public:
//2009/11/04
virtual BOOL translate(MSG* msg) {
return FALSE;
}
};
}
|