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

首頁 > 學院 > 開發設計 > 正文

第一個Win32程序

2019-11-10 18:43:32
字體:
來源:轉載
供稿:網友
//第一個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,也就是真正實現消息響應的模塊

窗口

//完整的“窗口”#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 粘貼代碼,F7組建,Ctrl+F5運行 工程文件下載 有疑問咨詢 QQ/微信 784126524 公眾號: 公眾號


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 镇原县| 福州市| 安平县| 贵德县| 阜康市| 山东省| 玉门市| 余江县| 文昌市| 西吉县| 鄂温| 峨边| 西安市| 临泽县| 湖北省| 永新县| 肃宁县| 龙州县| 舟山市| 勐海县| 凭祥市| 平泉县| 灵宝市| 高台县| 江城| 灌云县| 汪清县| 望都县| 南漳县| 乐陵市| 泰宁县| 吉安县| 固安县| 内江市| 宜州市| 镇赉县| 阜阳市| 双峰县| 美姑县| 古浪县| 衡山县|