国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 本溪市| 金山区| 霍城县| 平塘县| 垣曲县| 延安市| 元谋县| 易门县| 新巴尔虎左旗| 海原县| 固镇县| 济阳县| 监利县| 上思县| 思南县| 蒲江县| 沅江市| 大港区| 沙湾县| 招远市| 兴隆县| 赫章县| 新竹县| 卫辉市| 洛扎县| 容城县| 和静县| 清苑县| 桂林市| 岢岚县| 汝南县| 类乌齐县| 卓尼县| 汾阳市| 始兴县| 霍邱县| 中西区| 清涧县| 南木林县| 文化| 大洼县|