void ProcessFileChange() { FILE_NOTIFY_INFORMATION* pFNI = (FILE_NOTIFY_INFORMATION*)&mFileChangeBuffer[0]; while (pFNI) { switch (pFNI->Action) { case FILE_ACTION_MODIFIED: { char fileName[MAX_PATH]; int count = WideCharToMultiByte(CP_ACP, 0, pFNI->FileName, pFNI->FileNameLength / sizeof(WCHAR), fileName, _ARRAYSIZE(fileName) - 1, 0, 0); fileName[count] = 0; auto unifiedPath = FileSystem::UnifyFilepath(fileName); LOCK_CRITICAL_SECTION lock(mChangedFilesGuard); mChangedFiles.insert(unifiedPath); mHasChangedFiles = true; if (sMonitorRaw){ sMonitorRaw->OnChangeDetected(); } } break; } pFNI = pFNI->NextEntryOffset ? (FILE_NOTIFY_INFORMATION*)(((char*)pFNI) + pFNI->NextEntryOffset) : 0; } }
int GetAllNeighbors( const CCoreDispInfo *pDisp, int iNeighbors[512] ) { int nNeighbors = 0; // Check corner neighbors. for ( int iCorner=0; iCorner < 4; iCorner++ ) { const CDispCornerNeighbors *pCorner = pDisp->GetCornerNeighbors( iCorner ); for ( int i=0; i < pCorner->m_nNeighbors; i++ ) { if ( nNeighbors < _ARRAYSIZE( iNeighbors ) ) iNeighbors[nNeighbors++] = pCorner->m_Neighbors[i]; } } for ( int iEdge=0; iEdge < 4; iEdge++ ) { const CDispNeighbor *pEdge = pDisp->GetEdgeNeighbor( iEdge ); for ( int i=0; i < 2; i++ ) { if ( pEdge->m_SubNeighbors[i].IsValid() ) if ( nNeighbors < 512 ) iNeighbors[nNeighbors++] = pEdge->m_SubNeighbors[i].GetNeighborIndex(); } } return nNeighbors; }
//初始化,加载图片资源等 void InitNotifyWnd(LPNOTIFYINFO pInfo) { TCHAR fname[MAX_PATH]; LOGFONT lf; if(pInfo == NULL) return; //To get the work area of a monitor other than the primary display monitor, //call the GetMonitorInfo function. SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&pInfo->rcWorkArea, 0); pInfo->dy = NOTIFY_DY; pInfo->gap = 4; COLORREF clrBk = GetSysColor(COLOR_INACTIVECAPTION); COLORREF clrBorder = GetBlendColor(clrBk, RGB(0, 0, 0), 30); pInfo->clrTitle = GetSysColor(COLOR_INACTIVECAPTIONTEXT); pInfo->clrContent = RGB(16, 64, 128); //pInfo->hBrush = CreateSolidBrush(clrBk); pInfo->hBrushBorder = CreateSolidBrush(clrBorder); //创建字体,标题为粗体 memset(&lf, 0, sizeof(LOGFONT)); _tcscpy_s(lf.lfFaceName, _ARRAYSIZE(lf.lfFaceName), NOTIFY_FONTFACE); lf.lfWeight = FW_BOLD; lf.lfHeight = NOTIFY_FONTSIZE; lf.lfQuality = DRAFT_QUALITY; //NONANTIALIASED_QUALITY; PROOF_QUALITY; //lf.lfPitchAndFamily = FIXED_PITCH; pInfo->hFontTitle = CreateFontIndirect(&lf); lf.lfWeight = FW_NORMAL; lf.lfHeight = NOTIFY_FONTSIZE; pInfo->hFontContent = CreateFontIndirect(&lf); //创建CImage并加载资源 GetAppFolderFileName(fname, MAX_PATH, _T("res\\icons_16.png")); pInfo->pIcons = new CImage(); pInfo->pIcons->Load(fname); if(!pInfo->pIcons->IsNull()) { pInfo->iconSize = pInfo->pIcons->GetHeight(); ApplyAlpha(pInfo->pIcons); } GetAppFolderFileName(fname, MAX_PATH, _T("res\\bitmaps_48.png")); pInfo->pImgs = new CImage(); pInfo->pImgs->Load(fname); if(!pInfo->pImgs->IsNull()) { pInfo->imgSize = pInfo->pImgs->GetHeight(); ApplyAlpha(pInfo->pImgs); } GetAppFolderFileName(fname, MAX_PATH, _T("res\\closebtns.bmp")); pInfo->pImgCloseBtns = new CImage(); pInfo->pImgCloseBtns->Load(fname); pInfo->closeBtnSize = pInfo->pImgCloseBtns->GetHeight(); }
wstring CWaveSession::BuildHash() { wstring szResult; szResult.reserve(12); for (INT i = 0; i < 12; i++) { szResult += *(WAVE_HASH_POOL + Rand(0, _ARRAYSIZE(WAVE_HASH_POOL) - 1)); } return szResult; }
void QuarkProcessVSAVSprites(GGPOSession *ggpo, QuarkSprite sprites[], int count) { static const struct { char *character; int id; } search[] = { {"Demitri", 15594 }, {"Morrigan", 15544 }, {"Victor", 15550 }, {"B.B.Hood", 15539 }, {"Q-Bee", 15610 }, {"Lilith", 15564 }, {"L.Rapter", 15501 }, {"Felicia", 15562 }, {"Jedah", 15726 }, {"J.Talbain", 15533 }, {"Bishamon", 15547 }, {"Anakaris", 15578 }, {"Hsien-Ko", 15597 }, {"Sasquatch", 15768 }, {"Rikuo", 15694 }, }; static const QuarkSpriteInfo finishSprite = { 64928, 104, 88 }; static const QuarkSpriteInfo startSprite = { 46365, 168, 104 }; /* * See if it's time to start a new game... */ if (GameInfo.state == STATE_IDLE) { if (SpriteInList(&startSprite, sprites, count)) { GameInfo.state = STATE_STARTING; } } else if (GameInfo.state == STATE_STARTING) { if (!SpriteInList(&startSprite, sprites, count)) { QuarkSpriteStartNewGame(ggpo, "vsav"); GameInfo.state = STATE_RUNNING; } } else if (GameInfo.state == STATE_RUNNING) { /* * We can go from running back to starting if someone * does something weird like resetting the game. So keep * looking for the start sprite. */ if (SpriteInList(&startSprite, sprites, count)) { GameInfo.state = STATE_STARTING; } /* * Identify the players... */ if (!GameInfo.p[0].id || !GameInfo.p[1].id) { for (int j = 0; j < _ARRAYSIZE(search); j++) { for (int k = 0; k < count; k++) { if (sprites[k].id == search[j].id && sprites[k].y == 24) { if (sprites[k].x < 160) { GameInfo.p[0].id = search[j].character; } else { GameInfo.p[1].id = search[j].character; } } } } } /* * See if we're finished... */ if (SpriteInList(&finishSprite, sprites, count)) { GameInfo.p[0].rounds = 0; GameInfo.p[1].rounds = 0; for (int k = 0; k < count; k++) { if (sprites[k].y == 23) { if (sprites[k].x == 8 || sprites[k].x == 34) { GameInfo.p[0].rounds++; } else if (sprites[k].x == 328 || sprites[k].x == 354) { GameInfo.p[1].rounds++; } } } QuarkSpriteFinishGame(ggpo); GameInfo.state = STATE_IDLE; } } }
int main(int argc, char* argv[]) { SDL_Init(SDL_INIT_VIDEO); // OpenGL 4.0! SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_Window* window = SDL_CreateWindow("OpenGL", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL); SDL_GLContext context = SDL_GL_CreateContext(window); glewExperimental = GL_TRUE; glewInit(); glGetError(); // Glew tends to generate GL_INVALID_ENUM (https://www.opengl.org/wiki/OpenGL_Loading_Library) const float triangle[] = { // X Y Z 0.0f, 0.5f, 0.0f, 0.5f, -0.5f, 0.0f, -0.5f, -0.5f, 0.0f, }; GLuint triangleBuffer; glCreateBuffers(1, &triangleBuffer); glBindBuffer(GL_ARRAY_BUFFER, triangleBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(triangle), triangle, GL_STATIC_DRAW); //glBindBuffer(GL_ARRAY_BUFFER, 0); const int indices[] = { 0, 1, 2 }; GLuint triangleIndexBuffer; glCreateBuffers(1, &triangleIndexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, triangleIndexBuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); const char* vertexShaderCode[] = { "#version 400\n", // This is the only line that requires a newline, all others do not need it! "in vec3 vertex;", "void main() {", " gl_Position = vec4(vertex, 1.0);", "}", }; const char* fragmentShaderCode[] = { "#version 400\n", // This is the only line that requires a newline, all others do not need it! "out vec4 colorRGBA;", "void main() {", " colorRGBA = vec4(1.0, 0.0, 0.0, 1.0);", "}", }; GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vertexShader, _ARRAYSIZE(vertexShaderCode), vertexShaderCode, nullptr); glCompileShader(vertexShader); GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fragmentShader, _ARRAYSIZE(fragmentShaderCode), fragmentShaderCode, nullptr); glCompileShader(fragmentShader); GLuint shaderProgram = glCreateProgram(); glAttachShader(shaderProgram, vertexShader); glAttachShader(shaderProgram, fragmentShader); glLinkProgram(shaderProgram); GLuint vertArray; glGenVertexArrays(1, &vertArray); glBindVertexArray(vertArray); glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, triangleBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, triangleIndexBuffer); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); bool done = false; while (!done) { SDL_Event event; while (SDL_PollEvent(&event)) { if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE || event.key.keysym.sym == SDLK_ESCAPE) { done = true; break; } } glClearColor(0.0f, 1.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); glUseProgram(shaderProgram); glBindVertexArray(vertArray); //glDrawArrays(GL_TRIANGLES, 0, _ARRAYSIZE(indices)); glDrawElements(GL_TRIANGLES, _ARRAYSIZE(indices), GL_UNSIGNED_INT, 0); SDL_GL_SwapWindow(window); } SDL_GL_DeleteContext(context); SDL_DestroyWindow(window); SDL_Quit(); return 0; }
{ return config_path; } struct nodenet_option { const char *name; void (*set)(const char *arg); const char *(*get)(); }; struct nodenet_option options[] = { {"worker", env_add_worker, NULL}, {"config", env_set_config, env_get_config}, }; static const int option_size = _ARRAYSIZE(options); void nodenet_setenv(const char *key, const char *value) { int i = 0; for(; i<option_size; ++i) { if(strcmp(key,options[i].name) == 0) { if(options[i].set) options[i].set(value); break; } } } const char * nodenet_getenv(const char *key) {
void ShowNotifyWnd(HWND hWnd, LPCTSTR title, LPCTSTR content, int timeoutMS, int nIcon, int nImg) { //EnterCriticalSection(&g_NotifyInfo.cs); //g_NotifyInfo.mode = mode; LPNOTIFYWND_DATA pInfo = (LPNOTIFYWND_DATA)GetWindowLongPtr(hWnd, GWLP_USERDATA); if(pInfo == NULL) return; _tcscpy_s(pInfo->szTitle, _ARRAYSIZE(pInfo->szTitle), title); _tcscpy_s(pInfo->szContent, _ARRAYSIZE(pInfo->szContent), content); if(nIcon >= 0) pInfo->rcTitle.left = pInfo->rcIcon.right + g_NotifyInfo.gap; else pInfo->rcTitle.left = 3 + g_NotifyInfo.gap; if(nImg >= 0) pInfo->rcContent.left = pInfo->rcImg.right + g_NotifyInfo.gap; else pInfo->rcContent.left = pInfo->rcContentOutter.left + g_NotifyInfo.gap; pInfo->rcContent.top = pInfo->rcContentOutter.top + g_NotifyInfo.gap; pInfo->rcContent.right = pInfo->rcContent.left + pInfo->contentWidth; pInfo->rcContentOutter.right = pInfo->rcContent.right + g_NotifyInfo.gap; pInfo->wndWidth = pInfo->rcContentOutter.right + 3; pInfo->rcTitle.right = pInfo->wndWidth - g_NotifyInfo.gap; pInfo->rcContent.bottom = pInfo->rcContent.top + 48; pInfo->rcContentOutter.bottom = pInfo->rcContent.bottom + g_NotifyInfo.gap; //rcCloseBtn pInfo->rcCloseBtn.right = pInfo->wndWidth - 3 - g_NotifyInfo.gap/2; pInfo->rcCloseBtn.left = pInfo->rcCloseBtn.right - g_NotifyInfo.closeBtnSize; pInfo->rcCloseBtn.top = (pInfo->rcTitle.top + pInfo->rcTitle.bottom - g_NotifyInfo.closeBtnSize)/2; pInfo->rcCloseBtn.bottom = pInfo->rcCloseBtn.top + g_NotifyInfo.closeBtnSize; SetBkMode(pInfo->hMemDC, TRANSPARENT); //DT_TOP = 0; (default) 在这里测量矩形 HGDIOBJ hOldFont = SelectObject(pInfo->hMemDC, g_NotifyInfo.hFontContent); DrawText(pInfo->hMemDC, pInfo->szContent, -1, &pInfo->rcContent, DT_LEFT | DT_WORDBREAK | DT_CALCRECT); //复原宽度 pInfo->rcContent.right = pInfo->rcContent.left + pInfo->contentWidth; if(pInfo->mode == MODE_PROGRESS) { pInfo->bDownloading = TRUE; pInfo->rcProgressText.left = pInfo->rcContent.left; pInfo->rcProgressText.top = pInfo->rcContent.bottom + g_NotifyInfo.gap; pInfo->rcProgressText.right = pInfo->rcContent.right; pInfo->rcProgressText.bottom = pInfo->rcProgressText.top + pInfo->titleHeight; pInfo->rcProgressBarOutter.left = pInfo->rcContent.left; pInfo->rcProgressBarOutter.top = pInfo->rcProgressText.bottom + g_NotifyInfo.gap; pInfo->rcProgressBarOutter.right = pInfo->rcContent.right; pInfo->rcProgressBarOutter.bottom = pInfo->rcProgressBarOutter.top + g_NotifyInfo.gap * 2 + 4; CopyRect(&pInfo->rcProgressBar, &pInfo->rcProgressBarOutter); InflateRect(&pInfo->rcProgressBar, -2, - 2); pInfo->rcContent.bottom = pInfo->rcProgressBar.bottom + g_NotifyInfo.gap; } //更新高度等 if(nImg >= 0 && pInfo->rcImg.bottom > pInfo->rcContent.bottom) pInfo->rcContentOutter.bottom = pInfo->rcImg.bottom + g_NotifyInfo.gap; else pInfo->rcContentOutter.bottom = pInfo->rcContent.bottom + g_NotifyInfo.gap; pInfo->wndHeight = pInfo->rcContentOutter.bottom + 3; //FillRgn(hdc, pInfo->hRgnBkGnd, pInfo->hBrush); RECT rc = { 0, 0, pInfo->wndWidth, pInfo->wndHeight }; FillRect(pInfo->hMemDC, &rc, GetSysColorBrush(COLOR_INACTIVECAPTION)); //pInfo->hBrush); FrameRect(pInfo->hMemDC, &rc, g_NotifyInfo.hBrushBorder); FillRect(pInfo->hMemDC, &pInfo->rcContentOutter, (HBRUSH)GetStockObject(WHITE_BRUSH)); //绘制标题icon if(nIcon >= 0 && !g_NotifyInfo.pIcons->IsNull()) { g_NotifyInfo.pIcons->AlphaBlend(pInfo->hMemDC, pInfo->rcIcon.left, pInfo->rcIcon.top, g_NotifyInfo.iconSize, g_NotifyInfo.iconSize, g_NotifyInfo.iconSize * nIcon, 0, g_NotifyInfo.iconSize, g_NotifyInfo.iconSize); } //绘制左上角Image if(nImg >= 0 && !g_NotifyInfo.pImgs->IsNull()) { g_NotifyInfo.pImgs->AlphaBlend(pInfo->hMemDC, pInfo->rcImg.left, pInfo->rcImg.top, g_NotifyInfo.imgSize, g_NotifyInfo.imgSize, g_NotifyInfo.imgSize * nImg, 0, g_NotifyInfo.imgSize, g_NotifyInfo.imgSize); } //绘制标题 SelectObject(pInfo->hMemDC, g_NotifyInfo.hFontTitle); SetTextColor(pInfo->hMemDC, g_NotifyInfo.clrTitle); DrawText(pInfo->hMemDC, pInfo->szTitle, -1, &pInfo->rcTitle, DT_LEFT | DT_VCENTER | DT_SINGLELINE); //绘制文本 SelectObject(pInfo->hMemDC, g_NotifyInfo.hFontContent); SetTextColor(pInfo->hMemDC, g_NotifyInfo.clrContent); DrawText(pInfo->hMemDC, pInfo->szContent, -1, &pInfo->rcContent, DT_LEFT | DT_WORDBREAK); //复原字体 SelectObject(pInfo->hMemDC, hOldFont); int scrollbar_width = GetSystemMetrics(SM_CXVSCROLL); //Width of the screen of the primary display monitor int screen_width = GetSystemMetrics(SM_CXSCREEN); if(pInfo->mode == MODE_TEXT) { SetWindowPos(hWnd, NULL, screen_width - pInfo->wndWidth - scrollbar_width, g_NotifyInfo.rcWorkArea.bottom, pInfo->wndWidth, 0, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOCOPYBITS | SWP_SHOWWINDOW); SetTimer(hWnd, TIMERID_NOTIFY_SHOWING, INTERVAL_NOTIFYWND, NULL); } else if(pInfo->mode == MODE_PROGRESS) { //绘制进度条的外边框 FrameRect(pInfo->hMemDC, &pInfo->rcProgressBarOutter, g_NotifyInfo.hBrushBorder); pInfo->szProgressText[0] = 0; pInfo->progress = 0; //SWP_NOCOPYBITS : 抛弃客户区内容(如果不设置,则系统把窗口的有效区域拷贝到移动后的窗口) //因为窗口的内容可能已经发生变更,所以指定这个属性,相当于强制窗口重绘(InvalidateRect)。 SetWindowPos(hWnd, NULL, screen_width - pInfo->wndWidth - scrollbar_width, g_NotifyInfo.rcWorkArea.bottom - pInfo->wndHeight, pInfo->wndWidth, pInfo->wndHeight, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOCOPYBITS | SWP_SHOWWINDOW); KillTimer(hWnd, TIMERID_NOTIFY_SHOWING); } //防止定时器冲突,kill 现有的所有显示定时器 KillTimer(hWnd, TIMERID_NOTIFY_HIDING); KillTimer(hWnd, TIMERID_NOTIFY_HIDE); //安装超时定时器, 如果这个参数小于等于0,则表示永远显示! if(timeoutMS > 0) SetTimer(hWnd, TIMERID_NOTIFY_TIMEOUT, timeoutMS, NULL); else KillTimer(hWnd, TIMERID_NOTIFY_TIMEOUT); //LeaveCriticalSection(&g_NotifyInfo.cs); }
//纯文本式的右下角浮出窗口过程 LRESULT CALLBACK NotifyWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { LPNOTIFYWND_DATA pInfo = NULL; RECT rc; POINT pt; //这是一个广播消息 if(message == g_NotifyInfo.nMsg_ExitNow) { pInfo = (LPNOTIFYWND_DATA)GetWindowLongPtr(hWnd, GWLP_USERDATA); //通知主窗口退出(即客户端主程序退出) if(pInfo != NULL && pInfo->mode == MODE_TEXT) PostMessage(g_NotifyInfo.hWndMainFrm, WM_EXITNOW, 0, 0); return TRUE; } switch (message) { case WM_NCCREATE: { SIZE _size = { 0 }; LPCREATESTRUCT pCreateStruct = (LPCREATESTRUCT)lParam; LPCTSTR pStr = _T("啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊"); pInfo = (LPNOTIFYWND_DATA)malloc(sizeof(NOTIFYWND_DATA)); memset(pInfo, 0, sizeof(NOTIFYWND_DATA)); pInfo->mode = (int)(pCreateStruct->lpCreateParams); //创建内存位图和DC HDC hdc = GetDC(hWnd); pInfo->hMemDC = CreateCompatibleDC(hdc); HGDIOBJ hOldFont = SelectObject(pInfo->hMemDC, g_NotifyInfo.hFontContent); GetTextExtentPoint32(pInfo->hMemDC, pStr, _tcslen(pStr), &_size); pInfo->hMemBm = CreateCompatibleBitmap(hdc, _size.cx + g_NotifyInfo.imgSize + 48, 600); ReleaseDC(hWnd, hdc); SelectObject(pInfo->hMemDC, hOldFont); SelectObject(pInfo->hMemDC, pInfo->hMemBm); pInfo->contentWidth = _size.cx + g_NotifyInfo.gap; pInfo->titleHeight = _size.cy; pInfo->rcIcon.left = 3 + g_NotifyInfo.gap; pInfo->rcTitle.left = pInfo->rcIcon.left + g_NotifyInfo.iconSize + g_NotifyInfo.gap; pInfo->rcTitle.top = 3 + g_NotifyInfo.gap; pInfo->rcTitle.bottom = pInfo->rcTitle.top + pInfo->titleHeight; pInfo->rcIcon.top = (pInfo->rcTitle.top + pInfo->rcTitle.bottom - g_NotifyInfo.iconSize)/2; pInfo->rcIcon.right = pInfo->rcIcon.left + g_NotifyInfo.iconSize; pInfo->rcIcon.bottom = pInfo->rcIcon.top + g_NotifyInfo.iconSize; pInfo->rcContentOutter.left = 3; pInfo->rcContentOutter.top = pInfo->rcTitle.bottom + g_NotifyInfo.gap; pInfo->rcImg.left = pInfo->rcContentOutter.left + g_NotifyInfo.gap; pInfo->rcImg.top = pInfo->rcContentOutter.top + g_NotifyInfo.gap; pInfo->rcImg.right = pInfo->rcImg.left + g_NotifyInfo.imgSize; pInfo->rcImg.bottom = pInfo->rcImg.top + g_NotifyInfo.imgSize; SetWindowPos(hWnd, HWND_TOPMOST, -10000, -10000, pInfo->wndWidth, pInfo->wndHeight, SWP_HIDEWINDOW); pInfo->tme.cbSize = sizeof(TRACKMOUSEEVENT); pInfo->tme.dwFlags = TME_LEAVE; //我们需要 WM_MOUSELEAVE 消息; pInfo->tme.hwndTrack = hWnd; SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)pInfo); } return TRUE; case WM_PAINT: { pInfo = (LPNOTIFYWND_DATA)GetWindowLongPtr(hWnd, GWLP_USERDATA); if(pInfo == NULL) return TRUE; PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); BitBlt(hdc, 0, 0, pInfo->wndWidth, pInfo->wndHeight, pInfo->hMemDC, 0, 0, SRCCOPY); //绘制closebtn(有进度条时,不能关闭) int imgIndex = IMG_NORMAL; if(pInfo->bMouseOnClose) { imgIndex = (pInfo->bMouseDown && pInfo->bCloseBtnPushed)? IMG_PUSHED : IMG_HOVER; } g_NotifyInfo.pImgCloseBtns->TransparentBlt(hdc, pInfo->rcCloseBtn.left, pInfo->rcCloseBtn.top, g_NotifyInfo.closeBtnSize, g_NotifyInfo.closeBtnSize, imgIndex * g_NotifyInfo.closeBtnSize, 0, g_NotifyInfo.closeBtnSize, g_NotifyInfo.closeBtnSize, RGB(255, 0, 255)); EndPaint(hWnd, &ps); } return TRUE; case WM_ERASEBKGND: return TRUE; case WM_UPDATEPROGRESS: pInfo = (LPNOTIFYWND_DATA)GetWindowLongPtr(hWnd, GWLP_USERDATA); if(pInfo == NULL) return TRUE; if(pInfo->mode == MODE_PROGRESS) { LPCTSTR pStr = (LPCTSTR)lParam; if(pStr != NULL) _tcscpy_s(pInfo->szProgressText, _ARRAYSIZE(pInfo->szProgressText), pStr); pInfo->progress = (int)wParam; //绘制进度条 HGDIOBJ hOldFont = SelectObject(pInfo->hMemDC, g_NotifyInfo.hFontContent); SetTextColor(pInfo->hMemDC, g_NotifyInfo.clrContent); FillRect(pInfo->hMemDC, &pInfo->rcProgressText, (HBRUSH)GetStockObject(WHITE_BRUSH)); DrawText(pInfo->hMemDC, pInfo->szProgressText, -1, &pInfo->rcProgressText, DT_LEFT | DT_TOP | DT_SINGLELINE); SelectObject(pInfo->hMemDC, hOldFont); FillRect(pInfo->hMemDC, &pInfo->rcProgressBar, (HBRUSH)GetStockObject(WHITE_BRUSH)); CopyRect(&rc, &pInfo->rcProgressBar); rc.right = pInfo->rcProgressBar.left + (pInfo->rcProgressBar.right - pInfo->rcProgressBar.left) * pInfo->progress / 100; FillRect(pInfo->hMemDC, &rc, GetSysColorBrush(COLOR_ACTIVECAPTION)); //pInfo->hBrush); if(pInfo->progress >= 100) { //5 秒后自动隐藏 pInfo->bDownloading = FALSE; SetTimer(hWnd, TIMERID_NOTIFY_HIDE, 2000, NULL); } UnionRect(&rc, &pInfo->rcProgressText, &pInfo->rcProgressBar); InvalidateRect(hWnd, &rc, FALSE); } return TRUE; case WM_MOUSEMOVE: { pInfo = (LPNOTIFYWND_DATA)GetWindowLongPtr(hWnd, GWLP_USERDATA); if(pInfo == NULL) return TRUE; pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam); BOOL bTmp = PtInRect(&pInfo->rcCloseBtn, pt); if(bTmp != pInfo->bMouseOnClose) { pInfo->bMouseOnClose = bTmp; InvalidateRect(hWnd, &pInfo->rcCloseBtn, FALSE); } TrackMouseEvent(&pInfo->tme); } break; case WM_MOUSELEAVE: pInfo = (LPNOTIFYWND_DATA)GetWindowLongPtr(hWnd, GWLP_USERDATA); if(pInfo == NULL) return TRUE; if(pInfo->bMouseOnClose) { pInfo->bMouseOnClose = FALSE; InvalidateRect(hWnd, &pInfo->rcCloseBtn, FALSE); } break; case WM_LBUTTONDOWN: pInfo = (LPNOTIFYWND_DATA)GetWindowLongPtr(hWnd, GWLP_USERDATA); if(pInfo == NULL) return TRUE; pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam); pInfo->bMouseDown = TRUE; if(PtInRect(&pInfo->rcCloseBtn, pt)) { pInfo->bCloseBtnPushed = TRUE; InvalidateRect(hWnd, &pInfo->rcCloseBtn, FALSE); SetCapture(hWnd); } break; case WM_LBUTTONUP: pInfo = (LPNOTIFYWND_DATA)GetWindowLongPtr(hWnd, GWLP_USERDATA); if(pInfo == NULL) return TRUE; pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam); pInfo->bMouseDown = FALSE; if(pInfo->bCloseBtnPushed) { pInfo->bCloseBtnPushed = FALSE; ReleaseCapture(); if(PtInRect(&pInfo->rcCloseBtn, pt)) { KillTimer(hWnd, TIMERID_NOTIFY_SHOWING); KillTimer(hWnd, TIMERID_NOTIFY_HIDING); KillTimer(hWnd, TIMERID_NOTIFY_TIMEOUT); KillTimer(hWnd, TIMERID_NOTIFY_HIDE); InvalidateRect(hWnd, &pInfo->rcCloseBtn, FALSE); //ShowWindow(hDlg, SW_HIDE); //用渐隐( AW_BLEND )的方式隐藏窗口,动画时间:200ms AnimateWindow(hWnd, 200, AW_HIDE | AW_BLEND); } } break; case WM_TIMER: pInfo = (LPNOTIFYWND_DATA)GetWindowLongPtr(hWnd, GWLP_USERDATA); if(pInfo == NULL) return TRUE; GetWindowRect(hWnd, &rc); switch(wParam) { case TIMERID_NOTIFY_SHOWING: if((rc.bottom - rc.top) >= (pInfo->wndHeight - g_NotifyInfo.dy)) { KillTimer(hWnd, wParam); SetWindowPos(hWnd, NULL, rc.left, rc.bottom - pInfo->wndHeight, pInfo->wndWidth, pInfo->wndHeight, SWP_NOZORDER | SWP_NOACTIVATE); } else { SetWindowPos(hWnd, NULL, rc.left, rc.top - g_NotifyInfo.dy, pInfo->wndWidth, (rc.bottom - rc.top) + g_NotifyInfo.dy, SWP_NOZORDER | SWP_NOACTIVATE); } break; case TIMERID_NOTIFY_HIDING: { UINT flags = SWP_NOZORDER | SWP_NOACTIVATE; if((rc.bottom - rc.top) <= 0) { KillTimer(hWnd, wParam); flags = flags | SWP_HIDEWINDOW; } SetWindowPos(hWnd, NULL, rc.left, rc.top + g_NotifyInfo.dy, pInfo->wndWidth, rc.bottom - rc.top - g_NotifyInfo.dy, flags); } break; case TIMERID_NOTIFY_TIMEOUT: { KillTimer(hWnd, TIMERID_NOTIFY_SHOWING); KillTimer(hWnd, TIMERID_NOTIFY_TIMEOUT); KillTimer(hWnd, TIMERID_NOTIFY_HIDE); SetTimer(hWnd, TIMERID_NOTIFY_HIDING, INTERVAL_NOTIFYWND, NULL); } break; case TIMERID_NOTIFY_HIDE: //立即隐藏 { KillTimer(hWnd, TIMERID_NOTIFY_SHOWING); KillTimer(hWnd, TIMERID_NOTIFY_HIDING); KillTimer(hWnd, TIMERID_NOTIFY_TIMEOUT); KillTimer(hWnd, TIMERID_NOTIFY_HIDE); AnimateWindow(hWnd, 200, AW_HIDE | AW_BLEND); } break; } break; case WM_POWERBROADCAST: { //TCHAR szText[256]; //PBT_APMQUERYSUSPEND //_stprintf_s(szText, _ARRAYSIZE(szText), _T("NotifyWnd_PowerEvent: event = %x"), wParam); //WriteLogLine(szText); pInfo = (LPNOTIFYWND_DATA)GetWindowLongPtr(hWnd, GWLP_USERDATA); if(pInfo != NULL && pInfo->mode == MODE_TEXT) return SendMessage(g_NotifyInfo.hWndMainFrm, WM_POWERBROADCAST, wParam, lParam); } break; case WM_NCDESTROY: { pInfo = (LPNOTIFYWND_DATA)GetWindowLongPtr(hWnd, GWLP_USERDATA); if(pInfo == NULL) return TRUE; //DeleteCriticalSection(&g_NotifyInfo.cs); DeleteObject(pInfo->hMemBm); DeleteDC(pInfo->hMemDC); free(pInfo); SetWindowLongPtr(hWnd, GWLP_USERDATA, NULL); } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
BOOL CALLBACK DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) { char szSysPath[MAX_PATH], szLibPath[MAX_PATH]; WSADATA Wsa; switch(dwReason) { case DLL_PROCESS_ATTACH: l_hFakeDll = hInstance; if(MessageBoxA(NULL, "Connect to Packet Parser?", "Packet Parser", MB_YESNO|MB_ICONQUESTION)==IDNO) { use_dll = FALSE; } {// rewrite system DLL load path LPFNSETDLLDIRECTORYA lpfnSetDllDirectoryA = (LPFNSETDLLDIRECTORYA)GetProcAddress(GetModuleHandle("KERNEL32.DLL"), "SetDllDirectoryA"); if(lpfnSetDllDirectoryA) { lpfnSetDllDirectoryA("."); } } GetSystemDirectoryA(szSysPath, _ARRAYSIZE(szSysPath)); wsprintfA(szLibPath, "%s\\ws2_32.dll", szSysPath); l_hRealDll = LoadLibraryA(szLibPath); if(l_hRealDll) { if(l_hRealDll==l_hFakeDll) {// oops FreeLibrary(l_hRealDll); l_hRealDll = NULL; MessageBoxA(NULL, "Attempted self-load.", "Library Error", MB_OK|MB_ICONSTOP); return FALSE; } #define LOADFUNC(x,y) l_WsFuncs.y = (x)GetProcAddress(l_hRealDll, #y) LOADFUNC(LPFN_CLOSESOCKET,closesocket); LOADFUNC(LPFN_CONNECT,connect); LOADFUNC(LPFN_HTONL,htonl); LOADFUNC(LPFN_HTONS,htons); LOADFUNC(LPFN_IOCTLSOCKET,ioctlsocket); LOADFUNC(LPFN_INET_ADDR,inet_addr); LOADFUNC(LPFN_INET_NTOA,inet_ntoa); LOADFUNC(LPFN_NTOHL,ntohl); LOADFUNC(LPFN_NTOHS,ntohs); LOADFUNC(LPFN_RECV,recv); LOADFUNC(LPFN_SELECT,select); LOADFUNC(LPFN_SEND,send); LOADFUNC(LPFN_SENDTO,sendto); LOADFUNC(LPFN_SETSOCKOPT,setsockopt); LOADFUNC(LPFN_SHUTDOWN,shutdown); LOADFUNC(LPFN_SOCKET,socket); LOADFUNC(LPFN_GETHOSTBYNAME,gethostbyname); LOADFUNC(LPFN_GETHOSTNAME,gethostname); LOADFUNC(LPFN_WSAGETLASTERROR,WSAGetLastError); LOADFUNC(LPFN_WSASTARTUP,WSAStartup); LOADFUNC(LPFN_WSACLEANUP,WSACleanup); #undef LOADFUNC if(use_dll) { if(l_WsFuncs.WSAStartup(MAKEWORD(2,2), &Wsa)) { FreeLibrary(l_hRealDll); l_hRealDll = NULL; MessageBoxA(NULL, "Failed to initialize actual Windows Sockets.", "Library Error", MB_OK|MB_ICONSTOP); return FALSE; } if((l_hSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP))==INVALID_SOCKET) { l_WsFuncs.WSACleanup(); FreeLibrary(l_hRealDll); l_hRealDll = NULL; MessageBoxA(NULL, "Failed to create socket.", "Library Error", MB_OK|MB_ICONSTOP); return FALSE; } else { struct sockaddr_in sin; sin.sin_family = AF_INET; sin.sin_addr.s_addr = l_WsFuncs.htonl(SOCK_JOINIP(127,0,0,1)); sin.sin_port = l_WsFuncs.htons(13554); if(connect(l_hSock, (struct sockaddr*)&sin, sizeof(sin))==SOCKET_ERROR) { l_WsFuncs.shutdown(l_hSock, SD_BOTH); l_WsFuncs.closesocket(l_hSock); l_hSock = INVALID_SOCKET; l_WsFuncs.WSACleanup(); FreeLibrary(l_hRealDll); l_hRealDll = NULL; MessageBoxA(NULL, "Failed to connect to 127.0.0.1:13554 (TCP).", "Library Error", MB_OK|MB_ICONSTOP); use_dll = FALSE; //return FALSE; } } } } else { return FALSE; } break; case DLL_PROCESS_DETACH: if(l_hRealDll) { if(l_hSock!=INVALID_SOCKET) { l_WsFuncs.shutdown(l_hSock, SD_BOTH); l_WsFuncs.closesocket(l_hSock); l_hSock = INVALID_SOCKET; } l_WsFuncs.WSACleanup(); FreeLibrary(l_hRealDll); l_hRealDll = NULL; } l_hFakeDll = NULL; break; } return TRUE; // unused lpReserved; }