1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
/*
MagnifierWindow.cpp
Thin wrapper around win32 window objects.
Copyright (C) 2005 Chris O'Donnell
This file is part of Virtual Magnifying Glass for Windows.
Virtual Magnifying Glass for Windows is free software;
you can redistribute it and/or modify it under the
terms ofthe GNU General Public License version 2
as published by the Free Software Foundation.
Virtual Magnifying Glass for Windows is distributed in the hope
that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more details.
Please note that the General Public License version 2 does not permit
incorporating Virtual Magnifying Glass for Windows into proprietary
programs.
*/
#include "stdafx.h"
#include "MagnifierWindow.h"
////////////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK MagnifierWindow::windowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
// Won't be valid during WM_CREATE
MagnifierWindow* d = reinterpret_cast<MagnifierWindow*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
LRESULT result = 1;
switch(uMsg)
{
case WM_CREATE:
break;
default:
if(d)
{
result = d->handleMessage(hwnd, uMsg, wParam, lParam);
}
break;
}
if(result)
{
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
MagnifierWindow::MagnifierWindow()
: mHinst(NULL)
, mHwnd(NULL)
{
}
////////////////////////////////////////////////////////////////////////////////
MagnifierWindow::~MagnifierWindow()
{
}
////////////////////////////////////////////////////////////////////////////////
int MagnifierWindow::create(
HINSTANCE inst,
int x, int y,
int width, int height,
LPCWSTR className,
LPCWSTR caption,
DWORD windowStyle,
int icon /*= 0*/,
int iconSmall /*= 0*/,
DWORD classStyle /*= 0*/)
{
mHinst = inst;
mX = x;
mY = y;
mWidth = width;
mHeight = height;
mClassName = className;
mCaption = caption;
mIcon = icon;
mIconSmall = iconSmall;
WNDCLASSEX wndclass;
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_OWNDC | classStyle;
wndclass.lpfnWndProc = windowProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = mHinst;
wndclass.hIcon = LoadIcon (mHinst, MAKEINTRESOURCE(mIcon));
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject (/*COLOR_BACKGROUND*/NULL_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = mClassName;
wndclass.hIconSm = LoadIcon(mHinst, MAKEINTRESOURCE(mIconSmall));
RegisterClassEx (&wndclass);
mHwnd = CreateWindowEx(
0,
mClassName,
mCaption,
windowStyle/*WS_SYSMENU | WS_CAPTION*/,
mX,
mY,
mWidth,
mHeight,
NULL,
NULL,
mHinst,
NULL);
// Connect the wndProc to this object
SetWindowLongPtr(mHwnd, GWLP_USERDATA, (LONG)this);
afterCreate();
return 0;
}
////////////////////////////////////////////////////////////////////////////////
VOID CALLBACK TimerProc(
HWND hwnd,
UINT uMsg,
UINT_PTR idEvent,
DWORD dwTime)
{
MagnifierWindow* m = reinterpret_cast<MagnifierWindow*>(idEvent);
m->handleTimer();
}
////////////////////////////////////////////////////////////////////////////////
void MagnifierWindow::handleTimer()
{
}
////////////////////////////////////////////////////////////////////////////////
void MagnifierWindow::afterCreate()
{
SetTimer(hwnd(), (UINT_PTR)this, 100 /*msecs*/, TimerProc);
}
////////////////////////////////////////////////////////////////////////////////
void MagnifierWindow::show(bool shouldShow)
{
if(!mHwnd)
{
return;
}
ShowWindow(mHwnd, shouldShow ? SW_SHOW : SW_HIDE);
UpdateWindow(mHwnd);
}
////////////////////////////////////////////////////////////////////////////////
int MagnifierWindow::destroy()
{
if(mHwnd)
{
DestroyWindow(mHwnd);
mHwnd = 0;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
LRESULT MagnifierWindow::handleMessage(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
LRESULT result = 1;
switch(uMsg)
{
case WM_COMMAND:
result = 1;
break;
default:
break;
}
return result;
}
////////////////////////////////////////////////////////////////////////////////
HWND MagnifierWindow::hwnd()
{
return mHwnd;
}
|