国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

第一個Win32程序

2019-11-10 19:12:27
字體:
來源:轉載
供稿:網(wǎng)友
//第一個Win32程序#include <windows.h>int main(){ MessageBox(NULL,TEXT("Hello!"),TEXT("YPP"),MB_OK); return 0;}

在VS2010運行 VS2010

另一種形式

//第一個Win32程序#include <windows.h>int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPRevInstance, LPSTR lpCmdLine, int nCmdShow){ MessageBox(NULL,TEXT("Hello!"),TEXT("YPP"),MB_OK); return 0;}

運行結果 VC6

完整版的“窗口”

出自《Windows程序設計,第五版》作者Charles Petzold代碼的核心是WinProc,也就是真正實現(xiàn)消息響應的模塊

窗口

//完整的“窗口”#include <windows.h>LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; //原型int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){ static TCHAR szAppName[] = TEXT ("HelloWin") ; HWND hwnd ; MSG msg ; WNDCLASS wndclass ; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_application) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; if (!RegisterClass (&wndclass)) { MessageBox (NULL, TEXT ("YPP"), szAppName, MB_ICONERROR) ; return 0 ; } hwnd = CreateWindow (szAppName, TEXT ("The Hello Program"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL) ; ShowWindow (hwnd, iCmdShow) ; UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ;}//窗口過程完成消息響應LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){ HDC hdc ; PAINTSTRUCT ps ; RECT rect ; switch (message) { case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; GetClientRect (hwnd, &rect) ; DrawText (hdc, TEXT ("這是一個完整的“窗口”"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER) ; EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ;}

在VC6下 新建Win32 Application工程,在工程里新建.cpp 粘貼代碼,F(xiàn)7組建,Ctrl+F5運行 工程文件下載 有疑問咨詢 QQ/微信 784126524 公眾號: 公眾號


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 庐江县| 周至县| 长沙县| 吐鲁番市| 湘潭县| 盐边县| 密云县| 柏乡县| 施秉县| 城固县| 逊克县| 德州市| 含山县| 晴隆县| 新巴尔虎右旗| 巴彦淖尔市| 剑川县| 锡林浩特市| 五寨县| 临泉县| 朝阳市| 江油市| 屏东县| 喜德县| 东兴市| 盐津县| 汨罗市| 丰顺县| 陆河县| 诸暨市| 吉林市| 西畴县| 许昌县| 绩溪县| 张家港市| 西华县| 惠来县| 雷山县| 勐海县| 方城县| 大同市|