home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 2001 June
/
VPR0106A.BIN
/
OLS
/
TCL228
/
TCL228.lzh
/
EXESRC.lzh
/
propsheet.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-09-18
|
5KB
|
197 lines
/*-------------------------------------------
PROPSHEET.C
設定用プロパティシートの表示
KAZUBON 1997-1998
---------------------------------------------*/
#include "tclock.h"
int CALLBACK PropSheetProc(HWND hDlg, UINT uMsg, LPARAM lParam);
LRESULT CALLBACK SubclassProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
void SetMyDialgPos(HWND hwnd);
//各プロパティページ用ダイアログプロシージャ
BOOL CALLBACK PageColorProc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK PageFormatProc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK PageAlarmProc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK PageMouseProc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK PageTaskbarProc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK PageSNTPProc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK PageMiscProc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK PageAboutProc(HWND, UINT, WPARAM, LPARAM);
void SetPropSheetPos(HWND hwnd);
static WNDPROC oldWndProc; //以前のウィンドウプロシージャの保存
static int startpage = 0; //最初に表示するページ
/*-------------------------------------------
プロパティシートの表示
---------------------------------------------*/
void MyPropertySheet(void)
{
PROPSHEETPAGE psp[8];
PROPSHEETHEADER psh;
DLGPROC PageProc[8] = { PageColorProc, PageFormatProc,
PageAlarmProc, PageMouseProc, PageTaskbarProc, PageSNTPProc,
PageMiscProc, PageAboutProc };
int i;
if(hwndSheet && IsWindow(hwndSheet))
{
SetForegroundWindow98(hwndSheet); return;
}
//プロパティページの設定
for(i = 0; i < 8; i++)
{
memset(&psp[i], 0, sizeof(PROPSHEETPAGE));
psp[i].dwSize = sizeof(PROPSHEETPAGE);
psp[i].dwFlags = PSP_HASHELP;
psp[i].hInstance = hInst;
psp[i].pszTemplate = MAKEINTRESOURCE(IDD_PAGECOLOR + i);
psp[i].pfnDlgProc = PageProc[i];
}
//プロパティシートの設定
memset(&psh, 0, sizeof(PROPSHEETHEADER));
psh.dwSize = sizeof(PROPSHEETHEADER);
//アイコン表示、ppspを使う、
//モードレス、コールバックを使う、ヘルプあり
psh.dwFlags = PSH_USEICONID | PSH_PROPSHEETPAGE |
PSH_MODELESS | PSH_USECALLBACK | PSH_HASHELP;
psh.hInstance = hInst;
psh.pszIcon = MAKEINTRESOURCE(IDI_ICON1);
psh.pszCaption = MyString(IDS_PROPERTY);
psh.nPages = 8;
psh.nStartPage = startpage;
psh.ppsp = psp;
psh.pfnCallback = PropSheetProc;
//プロパティシートの表示
//ウィンドウハンドルをグローバル変数に保存
hwndSheet = (HWND)PropertySheet(&psh);
SetForegroundWindow98(hwndSheet);
}
/*-------------------------------------------
プロパティシート用コールバック
---------------------------------------------*/
int CALLBACK PropSheetProc(HWND hDlg, UINT uMsg, LPARAM lParam)
{
LONG style;
if(uMsg == PSCB_INITIALIZED)
{
//「?」ボタンを消す
style = GetWindowLong(hDlg, GWL_EXSTYLE);
style ^= WS_EX_CONTEXTHELP;
SetWindowLong(hDlg, GWL_EXSTYLE, style);
//サブクラス化する
oldWndProc = (WNDPROC)SetWindowLong(hDlg, GWL_WNDPROC,
(LONG)SubclassProc);
SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)hIconTClock);
}
return 0;
}
/*--------------------------------------------------
プロパティシート用サブクラスウィンドウプロシージャ
----------------------------------------------------*/
LRESULT CALLBACK SubclassProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
LRESULT l;
switch(message)
{
case WM_SHOWWINDOW: // ウィンドウを画面の中心に
SetMyDialgPos(hwnd);
return 0;
}
//デフォルトの処理
l = CallWindowProc(oldWndProc, hwnd, message, wParam, lParam);
switch(message)
{
case WM_COMMAND:
{
WORD id;
id = LOWORD(wParam);
//OK、キャンセルボタンで閉じる
if(id == IDOK || id == IDCANCEL)
{
MyHelp(hwnd, -1);
startpage = SendMessage(
(HWND)SendMessage(hwnd, PSM_GETTABCONTROL, 0, 0),
TCM_GETCURSEL, 0, 0);
if(startpage < 0) startpage = 0;
DestroyWindow(hwnd);
hwndSheet = NULL;
}
//「OK」「更新」ボタンで時計を更新
if(id == IDOK || id == 0x3021)
{
InitAlarm();
InitWatchWallpaper();
PostMessage(hwndClock, WM_USER+1, 0, 0);
}
break;
}
//「×」ボタンでキャンセル
case WM_SYSCOMMAND:
{
if((wParam & 0xfff0) == SC_CLOSE)
PostMessage(hwnd, WM_COMMAND, IDCANCEL, 0);
break;
}
}
return l;
}
/*------------------------------------------------
ダイアログの表示位置調整
--------------------------------------------------*/
void SetMyDialgPos(HWND hwnd)
{
HWND hwndTray;
RECT rc, rcTray;
int wscreen, hscreen, wProp, hProp;
int x, y;
GetWindowRect(hwnd, &rc);
wProp = rc.right - rc.left;
hProp = rc.bottom - rc.top;
wscreen = GetSystemMetrics(SM_CXSCREEN);
hscreen = GetSystemMetrics(SM_CYSCREEN);
hwndTray = FindWindow("Shell_TrayWnd", NULL);
if(hwndTray == NULL) return;
GetWindowRect(hwndTray, &rcTray);
if(rcTray.right - rcTray.left >
rcTray.bottom - rcTray.top)
{
x = wscreen - wProp - 32;
if(rcTray.top < hscreen / 2)
y = rcTray.bottom + 2;
else
y = rcTray.top - hProp - 32;
if(y < 0) y = 0;
}
else
{
y = hscreen - hProp - 2;
if(rcTray.left < wscreen / 2)
x = rcTray.right + 2;
else
x = rcTray.left - wProp - 2;
if(x < 0) x = 0;
}
MoveWindow(hwnd, x, y, wProp, hProp, FALSE);
}