如果new一個project然後選Windows Application,出來的東西看起來就和微軟sdk寫法可說是一樣,因為有字數的限制所以它產生的註解就拿掉了,剩下只在WindowProcedure改一點點,沒有button也沒輸入框,有點太基本了.同樣的程式在Visual C++下也可以run.#include LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);char szClassName[ ] = "WindowsApp";int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil){ HWND hwnd; MSG messages; WNDCLASSEX wincl; wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; wincl.style = CS_DBLCLKS; wincl.cbSize = sizeof (WNDCLASSEX); wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; if (!RegisterClassEx (&wincl)) return 0; hwnd = CreateWindowEx ( 0, szClassName, "Windows App", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 544, 375, HWND_DESKTOP, NULL, hThisInstance, NULL ); ShowWindow (hwnd, nFunsterStil); while (GetMessage (&messages, NULL, 0, 0)) { TranslateMessage(&messages); DispatchMessage(&messages); } return messages.wParam;}LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){ HDC hdc; PAINTSTRUCT ps; RECT rect; switch (message) { case WM_DESTROY: PostQuitMessage (0); break; case WM_PAINT: hdc=BeginPaint(hwnd,&ps); GetClientRect(hwnd,&rect); DrawText(hdc,"Hello World!",-1,&rect,DT_CENTER); EndPaint(hwnd,&ps); default: return DefWindowProc (hwnd, message, wParam, lParam); } return 0;}
2006-07-14 10:58:29 補充:
如果你是第一次看到這種windows程式,有點生澀是正常的,新學也需一段時間,但也如你所問的,它在windows下「通用」. Dev-C++本身較陽春,沒你講的那種,你可以改試wxDev-C++. 網址http://wxdsgn.sourceforge.net
2006-07-13 11:46:18
·
answer #1
·
answered by chan 5
·
0⤊
0⤋