1 // w32clock.cpp : Defines the entry point for the application.
5 #include "win32clock.h"
9 #define MAX_LOADSTRING 100
12 HINSTANCE hInst
; // current instance
13 TCHAR szTitle
[MAX_LOADSTRING
]; // The title bar text
14 TCHAR szWindowClass
[MAX_LOADSTRING
]; // the main window class name
16 // Forward declarations of functions included in this code module:
17 LRESULT CALLBACK
About(HWND
, UINT
, WPARAM
, LPARAM
);
19 [System::STAThreadAttribute
]
20 int APIENTRY
_tWinMain(HINSTANCE hInstance
,
21 HINSTANCE hPrevInstance
,
25 UNREFERENCED_PARAMETER(hPrevInstance
);
26 UNREFERENCED_PARAMETER(lpCmdLine
);
28 // TODO: Place code here.
32 INITCOMMONCONTROLSEX st
;
33 st
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
34 st
.dwICC
= ICC_TAB_CLASSES
| ICC_DATE_CLASSES
;
35 InitCommonControlsEx(&st
);
38 // Initialize global strings
39 LoadString(hInstance
, IDS_APP_TITLE
, szTitle
, MAX_LOADSTRING
);
40 LoadString(hInstance
, IDC_W32CLOCK
, szWindowClass
, MAX_LOADSTRING
);
42 DialogBox(hInst
, (LPCTSTR
)IDD_PROPPAGE_MEDIUM
, NULL
, (DLGPROC
)About
);
49 using namespace System
;
50 using namespace System::Windows
;
51 using namespace System::Windows::Interop
;
52 using namespace System::Windows::Media
;
54 HWND
GetHwnd(HWND parent
, int x
, int y
, int width
, int height
) {
55 HwndSource
^ source
= gcnew
HwndSource(
57 WS_VISIBLE
| WS_CHILD
, // style
61 IntPtr(parent
) // parent window
64 UIElement
^ page
= gcnew
WPFClock::Clock();
65 source
->RootVisual
= page
;
66 return (HWND
) source
->Handle
.ToPointer();
70 void Reparent(HWND hwnd
, HWND oldParent
, HWND newParent
) {
73 GetWindowRect(hwnd
, &rectangle
);
74 int width
= rectangle
.right
- rectangle
.left
;
75 int height
= rectangle
.bottom
- rectangle
.top
;
77 point
.x
= rectangle
.left
;
78 point
.y
= rectangle
.top
;
79 result
= MapWindowPoints(NULL
, newParent
, &point
, 1);
80 SetWindowPos( hwnd
, HWND_TOP
, point
.x
, point
.y
, width
, height
, SWP_NOSIZE
);
81 SetParent(hwnd
, newParent
);
84 LRESULT CALLBACK
About(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
86 UNREFERENCED_PARAMETER(lParam
);
93 //EnableThemeDialogTexture(hDlg, ETDT_USETABTEXTURE);
95 // initialize tab control
97 HWND hwndTab
= GetDlgItem(hDlg
, IDC_TAB1
);
98 tie
.mask
= TCIF_TEXT
| TCIF_IMAGE
;
100 tie
.pszText
= "Date && Time";
101 TabCtrl_InsertItem(hwndTab
, 0, &tie
);
102 tie
.pszText
= "Time Zone";
103 TabCtrl_InsertItem(hwndTab
, 1, &tie
);
105 // Initialize edit and combo box
106 HWND edit
= GetDlgItem(hDlg
, IDC_EDIT1
);
107 SetWindowText( edit
, "2005");
108 HWND combo
= GetDlgItem(hDlg
, IDC_COMBO1
);
109 SendMessage(combo
, CB_ADDSTRING
, 0, (LPARAM
) "January");
110 SendMessage(combo
, CB_ADDSTRING
, 0, (LPARAM
) "February");
111 SendMessage( combo
, WM_SETTEXT
, 0, (LPARAM
) "March");
113 // Find out where the clock should go
114 // by looking for the placeholder hwnd
115 HWND placeholder
= GetDlgItem(hDlg
, IDC_CLOCK
);
117 GetWindowRect(placeholder
, &rectangle
);
118 int width
= rectangle
.right
- rectangle
.left
;
119 int height
= rectangle
.bottom
- rectangle
.top
;
121 point
.x
= rectangle
.left
;
122 point
.y
= rectangle
.top
;
123 result
= MapWindowPoints(NULL
, hDlg
, &point
, 1);
125 ShowWindow( placeholder
, SW_HIDE
);
128 HWND clock
= ManagedCode::GetHwnd(hDlg
, point
.x
, point
.y
, width
, height
);
129 System::Windows::Interop::HwndSource
^ hws
= ManagedCode::HwndSource::FromHwnd(System::IntPtr(clock
));
134 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDC_BUTTON2
)
136 EndDialog(hDlg
, LOWORD(wParam
));
142 EndDialog(hDlg
, LOWORD(wParam
));