/*--------------------------------------------------- sinwave.h --- sinwave, (c) jiyun.xia 2011 ---------------------------------------------------*/ #ifndef SINWAVE_H_ #define SINWAVE_H_ #include <windows.h> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); #endif
/*----------------------------------------------- sinwave.cpp --- draw sine. ------------------------------------------------*/ #include "sinwave.h" #include <math.h> #include <time.h> #define ID_TIME1 1 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 | CS_OWNDC; 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; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static lineNum; static int cyClient, yHight; static int cxClient; HDC hdc; PAINTSTRUCT ps; HPEN hPen, hBlackPen; static int sign = -2; static unsigned char rColor, gColor, bColor; int i; static POINT *pPt; switch (message) { case WM_CREATE: ::SetTimer(hWnd, ID_TIME1, 10, NULL); return 0; case WM_SIZE: cyClient = HIWORD(lParam); cxClient = LOWORD(lParam); yHight = cyClient; sign = -2; if (!pPt) delete [] pPt; pPt = new POINT[cxClient + 1]; return 0; case WM_TIMER: if (wParam == ID_TIME1) { hdc = ::GetDC(hWnd); ::Polyline(hdc, pPt, cxClient); yHight +=sign; if (yHight <= -cyClient || yHight >= cyClient) sign *= -1; for (i = 0; i <= cxClient; ++i) { pPt[i].x = i; pPt[i].y =int(cyClient / 2.0 - yHight / 2.0 * sin(2 * 2 * 3.1415926 / cxClient * i)); } srand( (unsigned)time(NULL)); rColor = rand() % 255; gColor = rand() % 255; bColor = rand() % 255; hPen = ::CreatePen(PS_SOLID, 1, RGB(rColor, gColor, bColor)); hBlackPen= (HPEN)::SelectObject(hdc, (HPEN)hPen); ::Polyline(hdc, pPt, cxClient); SelectObject(hdc, (HPEN)hBlackPen); ::DeleteObject((HPEN)hPen); ::ReleaseDC(hWnd, hdc); } return 0; case WM_PAINT: hdc = ::BeginPaint(hWnd, &ps); for (i = 0; i <= cxClient; ++i) { pPt[i].x = i; pPt[i].y =int(cyClient / 2.0 * (1 - sin(2 * 3.1415926 / cxClient * i))); } ::Polyline(hdc, pPt, cxClient); ::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