/*--------------------------------------------------- bezier.h --- bezier, (c) jiyun.xia 2011 ---------------------------------------------------*/ #ifndef BEZIER_H_ #define BEZIER_H_ #include <windows.h> enum DRICTION {NO_DIR = 0, X_ADD, X_SUB, Y_ADD, Y_SUB}; struct LINE { POINT start; POINT end; DRICTION dirc; }; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); BOOL GetNextPoint(POINT curPt, int curLine, POINT &nextPt, int &indexLine); #endif
/*----------------------------------------------- bezier.cpp --- draw bezier. ------------------------------------------------*/ #include "bezier.h" #include <math.h> #include <time.h> #define ID_TIME1 1 #define PEN_WIDTH 0.1 #define LINE_LEN 5 LINE line[4]; int index = 0; POINT bezierPt[4], bezierPt1[4]; bool start = true; long cxClient, cyClient; unsigned char rColor = 0, gColor = 255, bColor = 0; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT("sinwave"); HWND hWnd; MSG msg; WNDCLASS wndClass; wndClass.cbClsExtra = 0; wndClass.cbWndExtra = 0; wndClass.hbrBackground = (HBRUSH)::GetStockObject(BLACK_BRUSH); wndClass.hCursor = ::LoadCursor(NULL, IDC_ARROW); wndClass.hIcon = ::LoadIcon(NULL, IDI_APPLICATION); wndClass.hInstance = hInstance; wndClass.lpfnWndProc = WndProc; wndClass.lpszClassName = szAppName; wndClass.lpszMenuName = NULL; wndClass.style = CS_HREDRAW | CS_VREDRAW; if (!::RegisterClass(&wndClass)) { ::MessageBox(NULL, TEXT("This program requires Windows NT!"), szAppName, MB_ICONERROR); return 0; } hWnd = ::CreateWindow(szAppName, TEXT("sinwave No.1"), 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; } BOOL GetNextPoint(POINT curPt, int curLine, POINT &nextPt, int &indexLine) { float k; indexLine = curLine; do { switch (line[indexLine].dirc) { case NO_DIR: break; case X_ADD: k = (float)(line[indexLine].end.y - line[indexLine].start.y) / (line[indexLine].end.x - line[indexLine].start.x); nextPt.x = curPt.x + (long)((LINE_LEN) / ::sqrt(1 + k * k)); if (nextPt.x > line[indexLine].end.x) break; nextPt.y = curPt.y + long(k * (nextPt.x - curPt.x)); return true; case X_SUB: k = (float)(line[indexLine].end.y - line[indexLine].start.y) / (line[indexLine].end.x - line[indexLine].start.x); nextPt.x = curPt.x - (long)((LINE_LEN) / ::sqrt(1 + k * k)); if (nextPt.x < line[indexLine].end.x) break; nextPt.y = curPt.y + long(k * (nextPt.x - curPt.x)); return true; case Y_ADD: if (line[indexLine].end.x == line[indexLine].start.x) { nextPt.x = curPt.x; nextPt.y = curPt.y + LINE_LEN; if (nextPt.y > line[indexLine].end.y) break; return true; } else { k = (float)(line[indexLine].end.y - line[indexLine].start.y) / (line[indexLine].end.x - line[indexLine].start.x); nextPt.y = curPt.y + (long)((LINE_LEN) / ::sqrt((k * k) / (1 + k * k))); if (nextPt.y > line[indexLine].end.y) break; nextPt.x = curPt.x + long((nextPt.y - curPt.y) / k); return true; } case Y_SUB: if (line[indexLine].end.x == line[indexLine].start.x) { nextPt.x = curPt.x; nextPt.y = curPt.y - LINE_LEN; if (nextPt.y < line[indexLine].end.y) break; return true; } else { k = (float)(line[indexLine].end.y - line[indexLine].start.y) / (line[indexLine].end.x - line[indexLine].start.x); nextPt.y = curPt.y - (long)((LINE_LEN) / ::sqrt((k * k) / (1 + k * k))); if (nextPt.y < line[indexLine].end.y) break; nextPt.x = curPt.x + long((nextPt.y - curPt.y) / k); return true; } } indexLine++; if (indexLine > 4) indexLine = 0; curPt = bezierPt[indexLine]; }while (indexLine != curLine); return false; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; POINT nextPt; int i, nextLine; LOGPEN lgPen; HPEN hOldPen, hCurPen; switch (message) { case WM_CREATE: ::SetTimer(hWnd, ID_TIME1, 10, NULL); return 0; case WM_SIZE: cyClient = (long)HIWORD(lParam); cxClient = (long)LOWORD(lParam); line[0].start = line[0].end; line[3].start = line[3].end; hdc = ::GetDC(hWnd); ::SetMapMode(hdc, MM_LOMETRIC); ::SetWindowOrgEx(hdc, cxClient / 2, cyClient / 2, NULL); ::srand((unsigned int)::time(NULL)); for (i = 0; i < 4; ++i) { if (i != 0 && i != 3) { line[i].start.x = ::rand() % cxClient; line[i].start.y = ::rand() % cyClient; ::DPtoLP(hdc, &line[i].start, 1); } line[i].end.x = ::rand() % cxClient; line[i].end.y = ::rand() % cyClient; ::DPtoLP(hdc, &line[i].end, 1); bezierPt[i] = line[i].start; if (i == 0 || i == 3) { if (line[i].end.x > line[i].start.x) { line[i].dirc = X_ADD; } else if (line[i].end.x < line[i].start.x) { line[i].dirc = X_SUB; } else if (line[i].end.y > line[i].start.y) { line[i].dirc = Y_ADD; } else if (line[i].end.y < line[i].start.y) { line[i].dirc = Y_SUB; } else line[i].dirc = NO_DIR; } else { if (line[i].end.y > line[i].start.y) { line[i].dirc = Y_ADD; } else if (line[i].end.y < line[i].start.y) { line[i].dirc = Y_SUB; } else if (line[i].end.x > line[i].start.x) { line[i].dirc = X_ADD; } else if (line[i].end.x < line[i].start.x) { line[i].dirc = X_SUB; } else line[i].dirc = NO_DIR; } } ::ReleaseDC(hWnd, hdc); return 0; case WM_TIMER: if (wParam != ID_TIME1) return 0; index++; if (index > 4) { index = 0; } hdc = ::GetDC(hWnd); ::SetMapMode(hdc, MM_LOMETRIC); ::SetWindowOrgEx(hdc, cxClient / 2, cyClient / 2, NULL); lgPen.lopnColor = RGB(0, 0, 0); lgPen.lopnStyle = PS_SOLID; lgPen.lopnWidth.x = PEN_WIDTH; hCurPen = ::CreatePenIndirect(&lgPen); hOldPen = (HPEN)::SelectObject(hdc, (HPEN)hCurPen); ::PolyBezier(hdc, bezierPt, 4); bezierPt1[0] = bezierPt[1]; bezierPt1[3] = bezierPt[2]; bezierPt1[1] = bezierPt[0]; bezierPt1[2] = bezierPt[3]; ::PolyBezier(hdc, bezierPt1, 4); //::MoveToEx(hdc, bezierPt[0].x, bezierPt[0].y, NULL); //for (i = 1; i < 4; ++i) // ::LineTo(hdc, bezierPt[i].x, bezierPt[i].y); //::LineTo(hdc, bezierPt[0].x, bezierPt[0].y); ::DeleteObject((HPEN)::SelectObject(hdc, (HPEN)hOldPen)); if (!GetNextPoint(bezierPt[index], index, nextPt, nextLine)) { long lparam = cyClient; lparam <<= 16; lparam += cxClient; ::SendMessage(hWnd, WM_SIZE, 0, lparam); return 0; } if (nextLine == index && nextPt.x == bezierPt[index].x && nextPt.y == bezierPt[index].y) { long lparam = cyClient; lparam <<= 16; lparam += cxClient; ::SendMessage(hWnd, WM_SIZE, 0, lparam); return 0; } bezierPt[nextLine] = nextPt; lgPen.lopnColor = RGB(rColor, gColor, bColor); hCurPen = ::CreatePenIndirect(&lgPen); hOldPen = (HPEN)::SelectObject(hdc, (HPEN)hCurPen); ::PolyBezier(hdc, bezierPt, 4); bezierPt1[0] = bezierPt[1]; bezierPt1[3] = bezierPt[2]; bezierPt1[1] = bezierPt[0]; bezierPt1[2] = bezierPt[3]; ::PolyBezier(hdc, bezierPt1, 4); //::MoveToEx(hdc, bezierPt[0].x, bezierPt[0].y, NULL); //for (i = 1; i < 4; ++i) // ::LineTo(hdc, bezierPt[i].x, bezierPt[i].y); //::LineTo(hdc, bezierPt[0].x, bezierPt[0].y); ::DeleteObject((HPEN)::SelectObject(hdc, (HPEN)hOldPen)); ::ReleaseDC(hWnd, hdc); return 0; case WM_PAINT: hdc = ::BeginPaint(hWnd, &ps); ::SetMapMode(hdc, MM_LOMETRIC); ::SetWindowOrgEx(hdc, cxClient / 2, cyClient / 2, NULL); lgPen.lopnColor = RGB(rColor, gColor, bColor); lgPen.lopnStyle = PS_SOLID; lgPen.lopnWidth.x = PEN_WIDTH; hCurPen = ::CreatePenIndirect(&lgPen); hOldPen = (HPEN)::SelectObject(hdc, (HPEN)hCurPen); ::PolyBezier(hdc, bezierPt, 4); bezierPt1[0] = bezierPt[1]; bezierPt1[3] = bezierPt[2]; bezierPt1[1] = bezierPt[0]; bezierPt1[2] = bezierPt[3]; ::PolyBezier(hdc, bezierPt1, 4); //::MoveToEx(hdc, bezierPt[0].x, bezierPt[0].y, NULL); //for (i = 1; i < 4; ++i) // ::LineTo(hdc, bezierPt[i].x, bezierPt[i].y); //::LineTo(hdc, bezierPt[0].x, bezierPt[0].y); ::SelectObject(hdc, (HPEN)hOldPen); ::DeleteObject((HPEN)hCurPen); ::EndPaint(hWnd, &ps); return 0; case WM_DESTROY: ::PostQuitMessage(0); return 0; } return ::DefWindowProc(hWnd, message, wParam, lParam); }
我不知道是自已的腦子太笨還是C語言基礎不太好, 這本書的開頭看得我腦子都快要爆了,雖然作者講得很詳細,但是很是有很多的東東我不太懂:1。windows 環境中的動態鏈接,API,內存管理,講得很抽象2 寬字符和8位字符與庫函數
源地址: http://www.qqgb.com/Program/VC/VCJC/Program_251616.html 桌面圖標是放在 SysListView32這個列表中,下面得到了它的句柄,如何遍歷它得到各各桌面圖標的句柄? 如
CString GetBuffer() and ReleaseBuffer() 2009-05-12 16:32 原文地址:http://hi.baidu.com/winnyang/blog/item/067b0a5423805f173
I'm whiny when I feel exhausted. I think I'm not very good at programming. I'm study about 《Windows programming》rec
補充一點保存設備描述表的內容。 在某些情況下,您可能想改變某些設備描述表屬性,用改變後的屬性進行繪圖,然後恢復原來的設備描述表。要簡化這一過程,可以通過如下調用來保存設備描述表的狀態: idSaved =
在windows中可以使用fprintf,但不能使用printf 下面是兩者的區別和聯繫, int sprintf(char *szBuffer,const char *szFormat …):第一個參數是字符緩衝區,後面的是格式字符串
要求: 在窗口中使用一個定時器,每隔1S交替使用紅色、綠色、藍色刷新整個窗口客戶區。 分析一下: 首先是 定義三個畫刷分別定義爲紅色、藍色、綠色。 然後是獲得整個窗口客戶區,使用函數 GetClientRect(hwnd,&
先說一哈 其實這個 惡意程序 大部分都是參考了 網上的資料 也就是說==== 我這裏代碼都是 網上能找到的 出現了好長時間的代碼 沒有什麼創新性=== so 還請大佬們繞道了== 先說一下程序的大概情況=== 其實 程序外表就是一個
其實網絡編程一開始都搞過 只不過當時 精力都在CTF上面 一直想寫一些小玩意=== 但是都沒有空-- 所以現在打算抽兩天空寫一哈=== 最後也算是寫完了 其實一開始打算用的是選擇模型 最後感覺這個還是比較好玩的 就 打算用這個模型寫一
阻止屏幕保護 bool active = false; SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, false, &active, SPIF_SENDWININICHANGE