// Exclude rarely-used stuff from Windows headers and speed up the build process #define WIN32_LEAN_AND_MEAN #define VC_EXTRALEAN #include #include #include //Forward declarations void RegisterMainClass(HINSTANCE, WNDCLASSEX&); void RegisterChildClass(HINSTANCE, WNDCLASSEX&); void printTable(HWND hWnd) { HDC hdc; PAINTSTRUCT ps; hdc = BeginPaint(hWnd, &ps); int x_pos = 0; int y_pos = 0; for(int i=1; i<=9; i++) { for(int j=1; j<=9; j++) { std::string s; char f1[8]; char f2[8]; char prod[8]; _itoa_s(i, f1, 10); _itoa_s(j, f2, 10); _itoa_s(i*j, prod, 10); s.append(f1); s.append(" * "); s.append(f2); s.append(" = "); s.append(prod); TextOut(hdc, x_pos, y_pos, s.c_str(), s.size()); y_pos += 16; } y_pos = 0; x_pos += 80; } EndPaint( hWnd, &ps ); } LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { //case WM_PAINT: // draw our window - note: you must paint something here or not trap it! //break; case WM_DESTROY: PostQuitMessage(0); break; default: // We do not want to handle this message so pass back to Windows return DefWindowProc(hWnd, uMsg, wParam, lParam); } return 0; } LRESULT CALLBACK WndProcChild(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_PAINT: printTable(hWnd); break; case WM_DESTROY: //PostQuitMessage(0); break; default: // We do not want to handle this message so pass back to Windows return DefWindowProc(hWnd, uMsg, wParam, lParam); } return 0; } int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { WNDCLASSEX main_wcex; WNDCLASSEX child_wcex; RegisterMainClass(hInstance, main_wcex); RegisterChildClass(hInstance, child_wcex); RegisterClassEx(&main_wcex); RegisterClassEx(&child_wcex); //Create the window HWND hWnd = CreateWindow( "MainWindowClass", // this is class name the window is to be based on "The title of the Window", // this is the title of the window that will appear in the bar at the top. WS_OVERLAPPEDWINDOW, // this is the style of window we want CW_USEDEFAULT, // x position CW_USEDEFAULT, // y position CW_USEDEFAULT, // window width CW_USEDEFAULT, // window height NULL, // if this is a child window of another window you need to give the parents handle here NULL, // if your window uses a menu give it here hInstance, // the program instance NULL); // this is a pointer to anything you want to pass to your windows procedure when the window is created. Normally NULL ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); //Create the child window HWND hWndChild = CreateWindow( "ChildWindowClass", // this is class name the window is to be based on "The title of the child Window", // this is the title of the window that will appear in the bar at the top. WS_DLGFRAME, // this is the style of window we want CW_USEDEFAULT, // x position CW_USEDEFAULT, // y position 720, // window width 200, // window height hWnd, // if this is a child window of another window you need to give the parents handle here NULL, // if your window uses a menu give it here hInstance, // the program instance NULL); // this is a pointer to anything you want to pass to your windows procedure when the window is created. Normally NULL ShowWindow(hWndChild, nCmdShow); UpdateWindow(hWndChild); // The message loop // The call to GetMessage: // The first parameter is a pointer to a message structure Windows will fill for us, // the second parameter is the handle of the window we want to receive messages from or NULL // for all our windows and the last two parameters allow us to filter messages by range. // Handling the messate: // When we receive the message we call TranslateMessage which converts virtual key messages // (used for localisation purposes) into character messages and then passes the result on to // DispatchMessage which sends the message to the windows procedure we defined in our window class. // If GetMessage returns 0 our application is exiting and we drop out of the bottom of WinMain and // the program closes. This happens when a WM_QUIT message is received. MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } // The return value from WinMain should be the message wParam if the program closes // normally otherwise it should be 0 if the message loop is never entered. return (int)msg.wParam; } void RegisterMainClass(HINSTANCE hInstance, WNDCLASSEX& wcex) { wcex.cbSize = sizeof(WNDCLASSEX); wcex.style= CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc= (WNDPROC)WndProc; wcex.cbClsExtra= 0; wcex.cbWndExtra= 0; wcex.hInstance= hInstance; wcex.hIcon= 0; wcex.hCursor= LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground= (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName= 0; wcex.lpszClassName= "MainWindowClass"; wcex.hIconSm= 0; } void RegisterChildClass(HINSTANCE hInstance, WNDCLASSEX& wcex) { wcex.cbSize = sizeof(WNDCLASSEX); wcex.style= CS_HREDRAW | CS_VREDRAW | CS_NOCLOSE; wcex.lpfnWndProc= (WNDPROC)WndProcChild; wcex.cbClsExtra= 0; wcex.cbWndExtra= 0; wcex.hInstance= hInstance; wcex.hIcon= 0; wcex.hCursor= LoadCursor(NULL, IDC_CROSS); wcex.hbrBackground= (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName= 0; wcex.lpszClassName= "ChildWindowClass"; wcex.hIconSm= 0; }