【正文】
osh development requires a separate code base from the Windows sources, increasing the plexity of maintenance and enhancement. Because porting code from Windows to the Macintosh can be the most difficult porting case, this paper concentrates in this area. In general, if your code base is sufficiently portable to enable straightforward repiling for the Macintosh (excluding any platformspecific, or edge code, you may elect to include), you39。t know C++. Can I still use MFC? Sure. MFC is based on C++, but you can mix C and C++ code seamlessly. ? How can I get started using MFC? Start by taking some classes and/or reading some books. Visual C++ ships with a fine tutorial on MFC (Scribble). Then, check out the MFC Migration Kit (available on CompuServe or, for a modest shipping and handling fee, from Microsoft). It will help you migrate your Cbased application code to MFC and C++. All porting will be easier if you begin today writing more portable programs. Following some basic portability guidelines will make your code less platformspecific. Never assume anything. Particularly, don39。re not specifically interested. On the Macintosh, you have a big main event loop to handle all possible events. ? Windows uses the concept of child windows. The Macintosh uses no child windows. ? Windowsbased applications can draw using either pens or brushes. Macintosh applications can use only pens. ? Controls in Windows are builtin window classes. On the Macintosh, controls are unrelated to windows. ? Windows allows for 256 binary raster operations。 但是到了今天,有了一種新的辦法。 Microsoft Visual C++針對(duì) Macintosh 提供的跨平臺(tái)編輯器提供了一些工具,這些工具是在 Windows NT 或 Windows 95 平臺(tái)上運(yùn)行,可以把 Windows 代碼再編譯,使其適應(yīng) Motorola 680x0 和 PowerPC 處理器。 Macintosh 應(yīng)用程序在 Macintosh 平臺(tái)上運(yùn)行,并且在遠(yuǎn)端的 Windows 機(jī)器上面調(diào)試。 5. 使用微軟基礎(chǔ)類庫 MFC 實(shí)現(xiàn)一些新功能,例如 OLE ,服務(wù)器,客戶端或者利用 ODBC 的數(shù)據(jù)庫支持。 很早的時(shí)候,你可以選擇是編寫基于原始 API 或者基于 MFC 的程序。 不要假定任何事,特別是不要假定數(shù)據(jù)類型的大小、機(jī)器的狀態(tài)、數(shù)據(jù)類型排序、或者隊(duì)列不要假定簡(jiǎn)單數(shù)據(jù)類型的大小,因?yàn)樗鼈冊(cè)诓煌奶幚砥魃嫌胁煌拇?小。像 Microsoft Visual C++這樣有內(nèi)置匯編程序的編譯器,可以很容易的擺脫匯編碼來提高速度。 Microsoft Visual C++提供了一個(gè)編譯器選項(xiàng),可以用來檢查 ANSI 的兼容性。 遵循上面的方針,將會(huì)是你的代碼容易轉(zhuǎn)換,但是,如果你代碼是 16 位的 Windows代碼,那你第一步要做的是使它能在 Win32 下正常工作,這需要你的資源作額外的改變。接著,把復(fù)雜的函數(shù)和匯編語言函數(shù)用子函數(shù)代替,然后,利用上面的技術(shù)使你的主程序正確的工作。在 Macintosh 里,你有一個(gè)大的事件循環(huán)來處理所有可能出現(xiàn)的消息。兩個(gè)處理器家族間的區(qū)別包括尋址和字節(jié)排序,還有 opcodes, 指令集 ,以及寄存器的名字和數(shù)量。 與之對(duì)比, Motorola 68000 和 PowerPC 處理器只能訪問 平坦的 32bit 存儲(chǔ)空間, 理論上說,這種平坦的存儲(chǔ)空間簡(jiǎn)化了存儲(chǔ)器尋址。 Macintosh 應(yīng)用程序通常包含 Apple menu,它包含了所有桌面安裝的附件,以及應(yīng)用程序的入口。另一方面 Macintosh 應(yīng)用程序處理的文件名卻類似于 September, 1993 Accounting Data. MDI 窗口允許一個(gè)活動(dòng)窗口框架內(nèi)有多個(gè)子窗口,許多 Windows 程序,例如 Microsoft Word 是 MDI 應(yīng)用程序。 。每個(gè) MDI 子窗口也會(huì)自己的菜單 。 Windows 應(yīng)用程序通常在窗口左上角有一個(gè)系統(tǒng)菜單,這個(gè) 菜單包含系統(tǒng)級(jí)功能如窗口大小,移動(dòng),關(guān)閉窗口,還有一個(gè)可以在應(yīng)用程序之間切換的被稱作任務(wù)管理器的項(xiàng)目。 Microsoft Windows 和 Windows NT 只能運(yùn)行在所謂的 littleendian 機(jī)器上— 處理器把不重要的字節(jié) 放在前面,把最重要的字節(jié)放在最后面,與之對(duì)比, Motorola 680x0 和 PowerPC (一個(gè)所謂的 bigendian 結(jié)構(gòu) )把最重要的字節(jié)放在最前面,緊接著放第二重要的字節(jié),依此類推,最不重要的放在最后面。為了支持使用更大的內(nèi)存, Intel 使用分段存儲(chǔ)器結(jié)構(gòu), 這樣利用 16bit 寄存器可以訪問 1 兆 (2^20 bytes)內(nèi)存,還有一個(gè) unsigned 16bit 的偏移量。 ? Windows 應(yīng)用程序可以使用畫筆或者畫刷繪圖, Macintosh 應(yīng)用程序只能使用畫筆。 當(dāng)你已經(jīng)成功地把你的 Windows 程序從 16 bits 轉(zhuǎn)換為 32 bits,你應(yīng)該準(zhǔn)備好了著手把它轉(zhuǎn)換成 Macintosh,因?yàn)檫@兩個(gè)平臺(tái)之間存在很大的區(qū)別,所以這個(gè)工作會(huì)顯得令人畏懼。可轉(zhuǎn)換的代碼應(yīng)該能在任意平臺(tái)上正確的編譯和執(zhí)行。使用 Microsoft C 擴(kuò)充的程序可以轉(zhuǎn)換到 Microsoft Visual C++的任何其它執(zhí)行操作。如果不是必須的,當(dāng)今的編譯器可以產(chǎn)生和手動(dòng)產(chǎn)生效果一樣好的匯編碼。使用 size of()來替換。但是,開發(fā)人員常常對(duì) MFC 有些疑問,例如: ? 如果我需要一種操作系統(tǒng)服務(wù),但應(yīng)用程序框架沒有提供如何處理 ? 直接調(diào)用 Win32 API, MFC 不會(huì)阻止你任何 Win32 API 的直接調(diào)用,只要你在函數(shù)名前面加全局運(yùn)算符 (::)就可以了 . ? 我不懂 C++,還能用 MFC 嗎? 當(dāng)然可以。 6. 編寫專門的 Macintosh 代碼,可以利用 Macintosh 的獨(dú)特特點(diǎn),利用 Apple 事件或出版和定購。轉(zhuǎn)換的幾個(gè)步驟取決于你處理的程序是 16 位還是 32 位。這就使你可以開發(fā)單一的源代碼(針對(duì) Win32174。本文要關(guān)注的就是與這種新辦法相關(guān)的方法和論點(diǎn)。s Balloon Help and the Application menu for switching between applications. Windowsbased applications always have a System menu at the upperleft corner of their toplevel window. This menu contains systemlevel functions for sizing, moving, and closing the window, as well as an item that calls the Task Manager for switching applications. Generally, Windowsbased applications contain keyboard equivalents in their menus. These are underlined letters in each menu entry that the user can select with the keyboard in lieu of the mouse. This, however, is convention rather than requirement. Although some Macintosh applications have these equivalents, most do not. Filenames and pathnames represent one of the most fundamental differences between Windows and the Macintosh, as well as perhaps the one most difficult to deal with. Many programmers report dealing with filenames as the area of porting in which the most time and energy is spent. Your Windowsbased application probably already handles (and expects) filenames such as C:\ACCTG\DATA\. Applications for the MSDOS and Windows operating systems are bound by the traditional filename format. Macintosh applications, on the other hand, can handle filenames such as September, 1993 Accounting Data. MDI windows allow for multiple child windows within the borders of a toplevel window (the MDI frame). Many Windowsbased applications, such as the Microsoft Word word processor for Windows, are MDI applications. Characteristic of MDI applications are clipped child windows that can be minimized to an icon within the MDI frame. Each MDI child window can also have its own menu. The Macintosh does not support MDI windows. An application can have multiple windows open。t assume the size of primitive types, because these have different si