2022年Windows程序设计源代码A .pdf
《2022年Windows程序设计源代码A .pdf》由会员分享,可在线阅读,更多相关《2022年Windows程序设计源代码A .pdf(8页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、chap12-ClipText /*- CLIPTEXT.C - The Clipboard and Text (c) Charles Petzold, 1998 -*/ #include #include resource.h LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; #ifdef UNICODE #define CF_TCHAR CF_UNICODETEXT TCHAR szDefaultText = TEXT (Default Text - Unicode Version) ; TCHAR szCaption = TE
2、XT (Clipboard Text Transfers - Unicode Version) ; #else #define CF_TCHAR CF_TEXT TCHAR szDefaultText = TEXT (Default Text - ANSI Version) ; TCHAR szCaption = TEXT (Clipboard Text Transfers - ANSI Version) ; #endif int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int
3、iCmdShow) static TCHAR szAppName = TEXT (ClipText) ; HACCEL hAccel ; 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 (N
4、ULL, IDI_APPLICATION) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 8 页 - - - - - - - - - wndclass.lpszMenuName = szAppName ; wndclass.lpszClas
5、sName = szAppName ; if (!RegisterClass (&wndclass) MessageBox (NULL, TEXT (This program requires Windows NT!), szAppName, MB_ICONERROR) ; return 0 ; hwnd = CreateWindow (szAppName, szCaption, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL
6、) ; ShowWindow (hwnd, iCmdShow) ; UpdateWindow (hwnd) ; hAccel = LoadAccelerators (hInstance, szAppName) ; while (GetMessage (&msg, NULL, 0, 0) if (!TranslateAccelerator (hwnd, hAccel, &msg) TranslateMessage (&msg) ; DispatchMessage (&msg) ; return msg.wParam ; LRESULT CALLBACK WndProc (HWND hwnd, U
7、INT message, WPARAM wParam, LPARAM lParam) static PTSTR pText ; BOOL bEnable ; HGLOBAL hGlobal ; HDC hdc ; PTSTR pGlobal ; PAINTSTRUCT ps ; RECT rect ; switch (message) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 8 页 - - - - - - - - - case WM_CREATE: SendMes
8、sage (hwnd, WM_COMMAND, IDM_EDIT_RESET, 0) ; return 0 ; case WM_INITMENUPOPUP: EnableMenuItem (HMENU) wParam, IDM_EDIT_PASTE, IsClipboardFormatAvailable (CF_TCHAR) ? MF_ENABLED : MF_GRAYED) ; bEnable = pText ? MF_ENABLED : MF_GRAYED ; EnableMenuItem (HMENU) wParam, IDM_EDIT_CUT, bEnable) ; EnableMen
9、uItem (HMENU) wParam, IDM_EDIT_COPY, bEnable) ; EnableMenuItem (HMENU) wParam, IDM_EDIT_CLEAR, bEnable) ; break ; case WM_COMMAND: switch (LOWORD (wParam) case IDM_EDIT_PASTE: OpenClipboard (hwnd) ; if (hGlobal = GetClipboardData (CF_TCHAR) pGlobal = GlobalLock (hGlobal) ; if (pText) free (pText) ;
10、pText = NULL ; pText = malloc (GlobalSize (hGlobal) ; lstrcpy (pText, pGlobal) ; InvalidateRect (hwnd, NULL, TRUE) ; CloseClipboard () ; return 0 ; case IDM_EDIT_CUT: case IDM_EDIT_COPY: if (!pText) return 0 ; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 8 页
11、- - - - - - - - - hGlobal = GlobalAlloc (GHND | GMEM_SHARE, (lstrlen (pText) + 1) * sizeof (TCHAR) ; pGlobal = GlobalLock (hGlobal) ; lstrcpy (pGlobal, pText) ; GlobalUnlock (hGlobal) ; OpenClipboard (hwnd) ; EmptyClipboard () ; SetClipboardData (CF_TCHAR, hGlobal) ; CloseClipboard () ; if (LOWORD (
12、wParam) = IDM_EDIT_COPY) return 0 ; / fall through for IDM_EDIT_CUT case IDM_EDIT_CLEAR: if (pText) free (pText) ; pText = NULL ; InvalidateRect (hwnd, NULL, TRUE) ; return 0 ; case IDM_EDIT_RESET: if (pText) free (pText) ; pText = NULL ; pText = malloc (lstrlen (szDefaultText) + 1) * sizeof (TCHAR)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年Windows程序设计源代码A 2022 Windows 程序设计 源代码
限制150内