最簡單的(最低金額庫)創建一個簡單的Windows窗體應用程序的方式是:
- 用資源編輯器奠定了其上具有必要的字段作爲一個.RC一個簡單的對話框文件
然後,下面的.cpp文件將加載該對話框並顯示它。
#include <windows.h>
#include "resource.h" // this file should be created with the .rc file
// If you are building with MSVC 8 or later, this will ensure that the dialog looks
// pretty, rather than flat and grey.
#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls'
version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
INT_PTR MyDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
switch(uMsg){
case WM_INITDIALOG:
return TRUE;
}
return FALSE;
}
INT WINAPI WinMain(HINSTANCE hInstance,HINSTANCE, LPCTSTR, INT){
return DialogBoxParam(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,MyDialogProc,0L);
}
(假設IDD_DIALOG1是您的.rc文件中對話框資源的ID)。
只需這段代碼,你應該有一個對話框,在屏幕上 - 所有你需要做的就是填寫MyDialogProc與處理像WM_COMMAND
將被稱爲消息是響應用戶的交互。 WM_INITDIALOG是您應該添加代碼以預先填充控件的位置。可以使用SetDlgItemText來設置各種控件上的文本。
如果您使用Microsoft Visual C++ Express或大多數其他非MS開發環境,則不包括資源編輯器/對話框編輯器。 ResEdit在這種情況下我可以免費下載。使用Microsoft Visual C++,可以使用Add-New-Item菜單選項創建.rc文件。
可能重複[在Windows上編寫輕量級GUI程序的最快路徑是什麼?](http://stackoverflow.com/questions/272764/what-is-the-quickest-path-to-writing-a -lightweight-gui-windows-program) – 2011-06-07 10:57:03
如果您正在尋找Devopment環境的鏈接,請查看堆棧溢出的Windows標記信息頁面。 – 2011-06-09 11:35:40