2012-09-21 49 views
0

我從這個頁面了: http://msdn.microsoft.com/en-us/library/ms692402%28v=vs.85%29.aspx#initializing_the_magnifier_run-time_library不能運行微軟的API放大的功能用C

此功能例如:

BOOL SetZoom(float magnificationFactor) 
{ 
    // A magnification factor less than 1.0 is not valid. 
    if (magnificationFactor < 1.0) 
    { 
     return FALSE; 
    } 

    // Calculate offsets such that the center of the magnified screen content 
    // is at the center of the screen. The offsets are relative to the 
    // unmagnified screen content. 
    int xDlg = (int)((float)GetSystemMetrics(
      SM_CXSCREEN) * (1.0 - (1.0/magnificationFactor))/2.0); 
    int yDlg = (int)((float)GetSystemMetrics(
      SM_CYSCREEN) * (1.0 - (1.0/magnificationFactor))/2.0); 

    return MagSetFullscreenTransform(magnificationFactor, xDlg, yDlg); 
} 

而我只是做 - 複製 - 粘貼到開發-C++

但是,當我編譯此代碼我得到一個錯誤:

'BOOL' does not name a type 

我做錯了什麼?

+0

你的錯誤是什麼? –

+0

錯誤是: 「BOOL」沒有指定類型 – gil123

+2

是否包含''? – chris

回答

0

首先,該錯誤信息是告訴你的編譯器不知道什麼BOOL手段。這不是C++中的內置關鍵字。 Windows程序通常使用BOOL,因爲它在windows.h頭文件中定義。爲了使用它,你必須#include這個文件。

要解釋得遠一點,這個例子給出並不意味着是一個完整的程序。有幾件遺失,以便編譯和運行它:

  1. 您需要#include <windows.h>

  2. 您需要一個main()WinMain()函數,它告訴計算機程序啓動的地方。通常,WinMain()用於Windows程序,並且通常包含用於啓動事件處理的循環。

  3. (可選)您如果要處理事件,並創建一個UI需要一個WinProc()功能。

此處假定使用WinAPI。如果你想使用MFC,你需要類似的設置代碼,但我不熟悉細節。用WinAPI或MFC編程相當複雜。在進入這個領域之前,您首先需要學習C和/或C++語言的細節。

+0

誰說你需要一個窗口過程?那些只顯示消息框的問候世界的Windows程序呢?我的觀點是,Windows API比事件處理和UI還要多。 – chris

+0

@chris好點。我的經驗是事件處理。我已經更新了我的答案,表明WinProc()是可選的。主要觀點仍然是示例代碼不能獨立存在。回答1中的 –

+0

,你能舉個小例子嗎? 這是我學習東西的方式。 – gil123