Danh mục

Giáo trình lập trình C cho Winform- P5

Số trang: 5      Loại file: pdf      Dung lượng: 276.07 KB      Lượt xem: 12      Lượt tải: 0    
Jamona

Hỗ trợ phí lưu trữ khi tải xuống: miễn phí Tải xuống file đầy đủ (5 trang) 0
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Giáo trình lập trình C cho Winform- P5: Các ứng dụng của Windows rất dễ sử dụng, nhưng rất khó đối với người đãtạo lập ra chúng. Để đạt được tính dễ dùng đòi hỏi người lập trình phải bỏra rất nhiều công sức để cài đặt.
Nội dung trích xuất từ tài liệu:
Giáo trình lập trình C cho Winform- P5 Bài 1:Giới thiệu chung Trần Minh Thái54 wcex.lpfnWndProc = (WNDPROC)WndProc;55 wcex.cbClsExtra = 0;56 wcex.cbWndExtra = 0;57 wcex.hInstance = hInstance;58 wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_BT1);59 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);60 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);61 wcex.lpszMenuName = (LPCSTR)IDC_BT1;62 wcex.lpszClassName = szWindowClass;63 wcex.hIconSm = LoadIcon(wcex.hInstance,(LPCTSTR)IDI_SMALL);64 return RegisterClassEx(&wcex);65 }66 // FUNCTION: InitInstance(HANDLE, int)67 // PURPOSE: Saves instance handle and creates main window68 // COMMENTS:69 // In this function, we save the instance handle in a global variable and70 // create and display the main program window.71 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)72 {73 HWND hWnd;74 hInst = hInstance; // Store instance handle in our global variable75 hWnd = CreateWindow(szWindowClass,76 szTitle,77 WS_OVERLAPPEDWINDOW,78 CW_USEDEFAULT,79 0,80 CW_USEDEFAULT,81 0,82 NULL,83 NULL,84 hInstance,85 NULL);86 if (!hWnd)87 {88 return FALSE;89 }90 ShowWindow(hWnd, nCmdShow);91 UpdateWindow(hWnd);92 return TRUE;93 }94 // FUNCTION: WndProc(HWND, unsigned, WORD, LONG)95 // PURPOSE: Processes messages for the main window.96 // WM_COMMAND - process the application menu97 // WM_PAINT - Paint the main window98 // WM_DESTROY - post a quit message and return Bài giảng: Lập trình C for Win .............................................................................................Trang 21/69 Bài 1:Giới thiệu chung Trần Minh Thái 99 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM100 wParam, LPARAM lParam)101 {102 int wmId, wmEvent,x,y;103 PAINTSTRUCT ps;104 HDC hdc;105 TCHAR szHello[MAX_LOADSTRING];106 LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);107 switch (message)108 {109 case WM_COMMAND:110 wmId = LOWORD(wParam);111 wmEvent = HIWORD(wParam);112 // Parse the menu selections:113 switch (wmId)114 {115 case IDM_ABOUT:116 DialogBox(hInst,(LPCTSTR)IDD_ABOUTBOX,117 hWnd, (DLGPROC)About);118 break;119 case IDM_EXIT:120 DestroyWindow(hWnd);121 break;122 default:123 return DefWindowProc(hWnd, message,124 wParam, lParam);125 }126 break;127 case WM_LBUTTONDOWN:128 hdc = GetDC(hWnd);129 // TODO: Add any drawing code here...130 x=LOWORD(lParam);131 y=HIWORD(lParam);132 TextOut(hdc,x,y,(LPCTSTR)szHello, strlen(szHello));133 break;134 case WM_PAINT:135 hdc = BeginPaint(hWnd, &ps);136 // TODO: Add any drawing code here...137 RECT rt;138 GetClientRect(hWnd, &rt);139 DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);140 EndPaint(hWnd, &ps);141 break;142 case WM_DESTROY:143 PostQuitMessage(0); ...

Tài liệu được xem nhiều: