| OLD | NEW |
| 1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
| 4 */ | 4 */ |
| 5 | 5 |
| 6 // This project demonstrates how to migrate a Windows desktop app to Native | 6 // This project demonstrates how to migrate a Windows desktop app to Native |
| 7 // Client, running first as a Win32 application (define STEP1), then as a PPAPI | 7 // Client, running first as a Win32 application (define STEP1), then as a PPAPI |
| 8 // plugin (define STEP2 through STEP6), and finally as a Native Client module. | 8 // plugin (define STEP2 through STEP6), and finally as a Native Client module. |
| 9 | 9 |
| 10 // Start with STEP1 defined and the defines for STEP2 through STEP6 commented | 10 // Start with STEP1 defined and the defines for STEP2 through STEP6 commented |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 PP_Instance myInstance; | 104 PP_Instance myInstance; |
| 105 | 105 |
| 106 int InitInstanceInPCWindow(); | 106 int InitInstanceInPCWindow(); |
| 107 void InitInstanceInBrowserWindow(); | 107 void InitInstanceInBrowserWindow(); |
| 108 | 108 |
| 109 #endif | 109 #endif |
| 110 | 110 |
| 111 | 111 |
| 112 #ifdef STEP4 | 112 #ifdef STEP4 |
| 113 // Implements message handling in a callback function. | 113 // Implements message handling in a callback function. |
| 114 void HelloWorldCallback(void* user_data, int32_t result) { | 114 void HelloWorldCallbackFun(void* user_data, int32_t result); |
| 115 struct PP_CompletionCallback HelloWorldCallback = { |
| 116 HelloWorldCallbackFun, NULL }; |
| 117 |
| 118 void HelloWorldCallbackFun(void* user_data, int32_t result) { |
| 115 MSG uMsg; | 119 MSG uMsg; |
| 116 if (PeekMessage(&uMsg, NULL, 0, 0, PM_REMOVE)) { | 120 if (PeekMessage(&uMsg, NULL, 0, 0, PM_REMOVE)) { |
| 117 TranslateMessage(&uMsg); | 121 TranslateMessage(&uMsg); |
| 118 DispatchMessage(&uMsg); | 122 DispatchMessage(&uMsg); |
| 119 } | 123 } |
| 120 ppb_core_interface->CallOnMainThread(100, HelloWorldCallback, 0); | 124 ppb_core_interface->CallOnMainThread(100, HelloWorldCallback, 0); |
| 121 } | 125 } |
| 122 | |
| 123 struct PP_CompletionCallback HelloWorldCallback = { HelloWorldCallback, NULL }; | |
| 124 #endif | 126 #endif |
| 125 | 127 |
| 126 #ifdef STEP2 | 128 #ifdef STEP2 |
| 127 // The basic framework needed for all Native Client Modules. Handles creation | 129 // The basic framework needed for all Native Client Modules. Handles creation |
| 128 // of the module instance and initial handshake with the browser. | 130 // of the module instance and initial handshake with the browser. |
| 129 /** | 131 /** |
| 130 * Creates new string PP_Var from C string. Useful utility for | 132 * Creates new string PP_Var from C string. Useful utility for |
| 131 * message-handling. | 133 * message-handling. |
| 132 */ | 134 */ |
| 133 static struct PP_Var CStrToVar(const char* str) { if (ppb_var_interface != | 135 static struct PP_Var CStrToVar(const char* str) { if (ppb_var_interface != |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 winClass.hCursor = LoadCursor(NULL, IDC_ARROW); | 367 winClass.hCursor = LoadCursor(NULL, IDC_ARROW); |
| 366 winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); | 368 winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); |
| 367 winClass.lpszMenuName = NULL; | 369 winClass.lpszMenuName = NULL; |
| 368 winClass.cbClsExtra = 0; | 370 winClass.cbClsExtra = 0; |
| 369 winClass.cbWndExtra = 0; | 371 winClass.cbWndExtra = 0; |
| 370 | 372 |
| 371 if (!RegisterClassEx(&winClass)) | 373 if (!RegisterClassEx(&winClass)) |
| 372 return E_FAIL; | 374 return E_FAIL; |
| 373 | 375 |
| 374 g_hWnd = CreateWindowEx( | 376 g_hWnd = CreateWindowEx( |
| 375 NULL, _T("MY_WINDOWS_CLASS"), | 377 0, _T("MY_WINDOWS_CLASS"), |
| 376 _T("hello_nacl"), WS_OVERLAPPEDWINDOW, | 378 _T("hello_nacl"), WS_OVERLAPPEDWINDOW, |
| 377 0, 0, 640, 480, NULL, NULL, g_hInstance, NULL); | 379 0, 0, 640, 480, NULL, NULL, g_hInstance, NULL); |
| 378 | 380 |
| 379 if (g_hWnd == NULL) | 381 if (g_hWnd == NULL) |
| 380 return E_FAIL; | 382 return E_FAIL; |
| 381 | 383 |
| 382 ShowWindow(g_hWnd, 1); | 384 ShowWindow(g_hWnd, 1); |
| 383 | 385 |
| 384 UpdateWindow(g_hWnd); | 386 UpdateWindow(g_hWnd); |
| 385 | 387 |
| 386 #ifdef STEP4 | 388 #ifdef STEP4 |
| 387 // Skip the message loop, schedule a callback instead to periodically check | 389 // Skip the message loop, schedule a callback instead to periodically check |
| 388 // for messages. Here we schedule at 100ms intervals. | 390 // for messages. Here we schedule at 100ms intervals. |
| 389 ppb_core_interface->CallOnMainThread(100, HelloWorldCallback, 0); | 391 ppb_core_interface->CallOnMainThread(100, HelloWorldCallback, 0); |
| 390 return 0; | 392 return 0; |
| 391 #else | 393 #else |
| 392 // Main message loop, Windows style. | 394 // Main message loop, Windows style. |
| 393 while(uMsg.message != WM_QUIT) { | 395 while(uMsg.message != WM_QUIT) { |
| 394 if (PeekMessage(&uMsg, NULL, 0, 0, PM_REMOVE)) { | 396 if (PeekMessage(&uMsg, NULL, 0, 0, PM_REMOVE)) { |
| 395 TranslateMessage( &uMsg ); | 397 TranslateMessage( &uMsg ); |
| 396 DispatchMessage( &uMsg ); | 398 DispatchMessage( &uMsg ); |
| 397 } | 399 } |
| 398 } | 400 } |
| 399 return uMsg.wParam; | 401 return uMsg.wParam; |
| 400 #endif | 402 #endif |
| 401 | 403 |
| 402 } | 404 } |
| 403 #endif | 405 #endif |
| OLD | NEW |