added SSCLI 1.0
[windows-sources.git] / sdk / samples / WPFSamples / Win32Clock / win32clock / win32clock.cpp
blob2582ba87943625be4b9e58a529fdae8ab9a6ee05
1 // w32clock.cpp : Defines the entry point for the application.
2 //
4 #include "stdafx.h"
5 #include "win32clock.h"
6 #include "commctrl.h"
7 #include "uxtheme.h"
9 #define MAX_LOADSTRING 100
11 // Global Variables:
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,
22 LPTSTR lpCmdLine,
23 int nCmdShow)
25 UNREFERENCED_PARAMETER(hPrevInstance);
26 UNREFERENCED_PARAMETER(lpCmdLine);
28 // TODO: Place code here.
29 MSG msg;
30 HACCEL hAccelTable;
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);
44 return 0;
47 namespace ManagedCode
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(
56 0, // class style
57 WS_VISIBLE | WS_CHILD, // style
58 0, // exstyle
59 x, y, width, height,
60 "hi", // NAME
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) {
71 int result = 0;
72 RECT rectangle;
73 GetWindowRect(hwnd, &rectangle);
74 int width = rectangle.right - rectangle.left;
75 int height = rectangle.bottom - rectangle.top;
76 POINT point;
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);
87 switch (message)
89 case WM_INITDIALOG:
91 int result = 0;
93 //EnableThemeDialogTexture(hDlg, ETDT_USETABTEXTURE);
95 // initialize tab control
96 TCITEM tie;
97 HWND hwndTab = GetDlgItem(hDlg, IDC_TAB1);
98 tie.mask = TCIF_TEXT | TCIF_IMAGE;
99 tie.iImage = -1;
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);
116 RECT rectangle;
117 GetWindowRect(placeholder, &rectangle);
118 int width = rectangle.right - rectangle.left;
119 int height = rectangle.bottom - rectangle.top;
120 POINT point;
121 point.x = rectangle.left;
122 point.y = rectangle.top;
123 result = MapWindowPoints(NULL, hDlg, &point, 1);
125 ShowWindow( placeholder, SW_HIDE);
127 // demo #3
128 HWND clock = ManagedCode::GetHwnd(hDlg, point.x, point.y, width, height);
129 System::Windows::Interop::HwndSource^ hws = ManagedCode::HwndSource::FromHwnd(System::IntPtr(clock));
131 return TRUE;
133 case WM_COMMAND:
134 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDC_BUTTON2 )
136 EndDialog(hDlg, LOWORD(wParam));
137 return TRUE;
139 break;
140 case WM_CLOSE:
142 EndDialog(hDlg, LOWORD(wParam));
143 return TRUE;
145 break;
147 return FALSE;