clipboard&file operating.
- /*-------------------------------------------------
- Code By Pnig0s1992
- -------------------------------------------------*/
-
- #include <windows.h>
- #include <windowsx.h>
- #define DIVISIONS 5
-
- LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
-
- int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
- PSTR szCmdLine, int iCmdShow)
- {
- static TCHAR szAppName[] = TEXT ("pwn0ne") ;
- 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 ("Program requires Windows NT!"),
- szAppName, MB_ICONERROR) ;
- return 0 ;
- }
-
- hwnd = CreateWindow (szAppName, TEXT ("pwn0ne"),
- 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)
- {
- static PTSTR pText;
- HBRUSH hBrush;
- HDC hdc;
- PAINTSTRUCT ps;
- RECT rc;
- HGLOBAL hGlobal;
- PTSTR pGlobal;
- HANDLE hHandle;
- LPCWSTR szFilePath = L"example.txt";
- DWORD dzWriteDataSize;
- LPSTR szFileData = "Test for clipboard&file operating.";
- int i,iLength = strlen(szFileData);
- BOOL bAvailable;
- BOOL bOpen;
-
- switch(message){
- case WM_CREATE:
- hGlobal = GlobalAlloc(GPTR,iLength+1);
- pGlobal = GlobalLock(hGlobal);
- for(i=0;i<iLength;i++){
- *pGlobal++=*szFileData++;
- }
- GlobalUnlock(hGlobal);
-
- OpenClipboard(hwnd);
- EmptyClipboard();
- SetClipboardData(CF_TEXT,hGlobal);
- CloseClipboard();
- return 0;
- case WM_PAINT:
- hdc = BeginPaint(hwnd,&ps);
- GetClientRect(hwnd,&rc);
- hBrush=CreateSolidBrush(RGB(0,0,255));
- FillRect(hdc,&rc,hBrush);
- if(bAvailable = IsClipboardFormatAvailable(CF_TEXT)){
- MessageBox(hwnd,TEXT("Clipboard is empty."),TEXT("Tip"),MB_OK);
- SendMessage(hwnd,WM_DESTROY,0,0);
- }
- if(!(bOpen = OpenClipboard(hwnd))){
- MessageBox(hwnd,TEXT("Open clipboard failed."),TEXT("Tip"),MB_OK);
- SendMessage(hwnd,WM_DESTROY,0,0);
- }
- hGlobal = GetClipboardData(CF_TEXT);
- pText = (char*)malloc(GlobalSize(hGlobal));
- pGlobal = GlobalLock(hGlobal);
- lstrcpy(pText,pGlobal);
- GlobalUnlock(hGlobal);
- CloseClipboard();
-
- hHandle = CreateFile(szFilePath,GENERIC_WRITE,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,NULL);
-
- if(hHandle == INVALID_HANDLE_VALUE){
- MessageBox(hwnd,TEXT("Create file failed."),TEXT("Warnning"),MB_OK);
- SendMessage(hwnd,WM_DESTROY,0,0);
- }else{
- if(!WriteFile(hHandle,szFileData,iLength,&dzWriteDataSize,NULL)){
- MessageBox(hwnd,TEXT("Write file failed."),TEXT("Warnning"),MB_OK);
- SendMessage(hwnd,WM_DESTROY,0,0);
- }else{
- MessageBox(hwnd,TEXT("Write file successed."),TEXT("Tip"),MB_OK);
- SendMessage(hwnd,WM_DESTROY,0,0);
- }
- }
- EndPaint(hwnd,&ps);
- DeleteObject(hBrush);
- return 0;
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- }
- return DefWindowProc(hwnd,message,wParam,lParam);
- }
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
양식 제출 후 제출 버튼 비활성화텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.