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

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

第一個Win32程序

2019-11-10 19:02:58
字體:
供稿:網(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;}

運行結(jié)果 VC6

完整版的“窗口”

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

窗口

//完整的“窗口”#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 ;}//窗口過程完成消息響應(yīng)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ā)表
主站蜘蛛池模板: 广丰县| 卓资县| 谢通门县| 孝义市| 尉氏县| 贡嘎县| 新密市| 沈丘县| 三门县| 晋城| 洛隆县| 南溪县| 凤城市| 巴中市| 互助| 秭归县| 和政县| 山东省| 府谷县| 北辰区| 黑龙江省| 泸州市| 开远市| 景泰县| 太仆寺旗| 石狮市| 长宁区| 河西区| 富川| 科技| 琼结县| 长春市| 延长县| 诸暨市| 特克斯县| 郸城县| 苍山县| 名山县| 项城市| 兖州市| 金山区|