#include #include const TCHAR g_szTitle[] = TEXT("Test Program"); const TCHAR g_szClassName[] = TEXT("Test Program Main Window Class"); const TCHAR g_szChildClassName[] = TEXT("Test Program Child Window Class"); HINSTANCE g_hInstance; HWND g_hMainWnd; HWND g_hPager; HWND g_hChildWnd; VOID ChildWnd_OnTimer(HWND hwnd) { TCHAR sz[MAX_PATH]; RECT rc; SIZE siz; DWORD style; // move the child window MoveWindow(hwnd, 0, 0, 100, 100, TRUE); // recalculate size Pager_RecalcSize(g_hPager); // get the size of child window GetWindowRect(hwnd, &rc); siz.cx = rc.right - rc.left; siz.cy = rc.bottom - rc.top; if (siz.cx == 100 && siz.cy == 100) MessageBox(hwnd, TEXT("Success"), TEXT("Result"), MB_ICONINFORMATION); else MessageBox(hwnd, TEXT("Failure"), TEXT("Result"), MB_ICONINFORMATION); } BOOL ChildWnd_OnCreate(HWND hwnd) { SetTimer(hwnd, 999, 200, NULL); return TRUE; } LRESULT CALLBACK ChildWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_CREATE: if (!ChildWnd_OnCreate(hwnd)) return -1; break; case WM_TIMER: KillTimer(hwnd, 999); ChildWnd_OnTimer(hwnd); break; default: return DefWindowProc(hwnd, uMsg, wParam, lParam); } return 0; } BOOL OnCreate(HWND hwnd) { DWORD style; // create a pager control style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP | PGS_AUTOSCROLL | PGS_DRAGNDROP; style |= PGS_HORZ; g_hPager = CreateWindow(WC_PAGESCROLLER, NULL, style, 0, 0, 0, 0, hwnd, (HMENU)-1, g_hInstance, NULL); if (g_hPager == NULL) return FALSE; // create the child window g_hChildWnd = CreateWindow(g_szChildClassName, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, g_hPager, NULL, g_hInstance, NULL); if (g_hChildWnd == NULL) return FALSE; Pager_SetChild(g_hPager, g_hChildWnd); return TRUE; } LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_CREATE: if (!OnCreate(hwnd)) return -1; break; case WM_DESTROY: DestroyWindow(g_hChildWnd); PostQuitMessage(0); break; default: return DefWindowProc(hwnd, uMsg, wParam, lParam); } return 0; } INT WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pszCmdLine, INT nCmdShow) { WNDCLASS wc; MSG msg; g_hInstance = hInstance; InitCommonControls(); // register main window class wc.style = 0; wc.lpfnWndProc = WindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1); wc.lpszMenuName = NULL; wc.lpszClassName = g_szClassName; if (!RegisterClass(&wc)) { MessageBox(NULL, TEXT("RegisterClass failed"), NULL, MB_ICONERROR); return 1; } // register child window class wc.style = 0; wc.lpfnWndProc = ChildWindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1); wc.lpszMenuName = NULL; wc.lpszClassName = g_szChildClassName; if (!RegisterClass(&wc)) { MessageBox(NULL, TEXT("RegisterClass failed"), NULL, MB_ICONERROR); return 1; } // create the main window g_hMainWnd = CreateWindow( g_szClassName, g_szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (g_hMainWnd == NULL) { MessageBox(NULL, TEXT("CreateWindow failed"), NULL, MB_ICONERROR); return 2; } // show it ShowWindow(g_hMainWnd, nCmdShow); UpdateWindow(g_hMainWnd); while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (INT)msg.wParam; }