extern "C" __declspec(dllexport) BOOL CaptureTextEnable(HWND hHookServer, HWND hWnd, POINT pMouse, BOOL *isWChr) { ScreenToClient(hWnd, &pMouse); g_hHookServer = hHookServer; g_pMouse = pMouse; #if 0 DWORD ret; SendMessageTimeoutA(g_hHookServer, WM_CW_DEBUG, -2, -2, SMTO_ABORTIFHUNG, 50, &ret); SendMessageTimeoutA(g_hHookServer, WM_CW_DEBUG, g_pMouse.x, g_pMouse.y, SMTO_ABORTIFHUNG, 50, &ret); #endif if (pMouse.y >= 0) { RECT UpdateRect; GetClientRect(hWnd, &UpdateRect); UpdateRect.top = pMouse.y; UpdateRect.bottom = pMouse.y + 1; g_bCapture = TRUE; g_tPos = -1; g_cbString = -1; InvalidateRect(hWnd, &UpdateRect, FALSE); //InvalidateRect(hWnd, NULL, FALSE); UpdateWindow(hWnd); *isWChr = g_bWChr; g_bCapture = FALSE; if (g_tPos != -1) return TRUE; } return FALSE; }
static void TestSendMessageTimeout( _In_ HWND hWnd, _In_ UINT Msg) { LRESULT ret; DWORD_PTR result; ret = SendMessageTimeoutW(hWnd, Msg, 0, 0, SMTO_NORMAL, 0, NULL); ok(ret == 0, "ret = %Id\n", ret); result = 0x55555555; ret = SendMessageTimeoutW(hWnd, Msg, 0, 0, SMTO_NORMAL, 0, &result); ok(ret == 0, "ret = %Id\n", ret); ok(result == 0, "result = %Iu\n", result); ret = SendMessageTimeoutA(hWnd, Msg, 0, 0, SMTO_NORMAL, 0, NULL); ok(ret == 0, "ret = %Id\n", ret); result = 0x55555555; ret = SendMessageTimeoutA(hWnd, Msg, 0, 0, SMTO_NORMAL, 0, &result); ok(ret == 0, "ret = %Id\n", ret); ok(result == 0, "result = %Iu\n", result); }
//*********************************************************************** // http://www.flounder.com/nomultiples.htm // // This technique sends a user-defined message to each enumerated // top-level window on the current desktop. // It expects the sought window to respond with the same // user-defined message. //*********************************************************************** static BOOL CALLBACK searcher(HWND hWnd, LPARAM lParam) { DWORD result; LRESULT ok = SendMessageTimeoutA(hWnd, WM_ARE_YOU_ME, 0, 0, SMTO_BLOCK | SMTO_ABORTIFHUNG, 200, &result); if (ok == 0) return true; // ignore this and continue if (result == WM_ARE_YOU_ME) { /* found it */ HWND *target = (HWND *) lParam; *target = hWnd; return false; // stop search } /* found it */ return true; // continue search } // CMyApp::searcher
/***************************************************************************************************\ * Функа ChangeRegKey; * изменение (добавление) значения параметра реестра (в данной ситуации добавляем своё значение в 'Path'); * Вход: * hKey - дескриптор указанного ключа реестра; * pszSubKey - адрес имени открываемого подключа (раздела реестра) * pszValName - адрес имени параметра (значения); * pszAddVal - адрес строкового значения, которое будет добавлено в уже существующее значение указанного параметра; * Выход: * 1 - если всё прошло успешно, или 0 - если хуйня * Замметки: * по умолчанию в этом модуле изменяется системная переменная окружения 'Path'; * в Win7/etc - это админская привилегия, так что будем аккуратней =)! \***************************************************************************************************/ DWORD ChangeRegKey(HKEY hKey, char *pszSubKey, char *pszValName, char *pszAddVal) { long lRes; HKEY hNewKey; char *pszData; DWORD num = MAX_LEN_BUF; DWORD dwRes = 0; lRes = RegOpenKeyExA(hKey, pszSubKey, 0, KEY_QUERY_VALUE | KEY_SET_VALUE, &hNewKey); //open the specified reg key; if(lRes != ERROR_SUCCESS) return 0; lRes = RegQueryValueExA(hNewKey, pszValName, 0, 0, 0, &num); //get num_bytes for our buffer; if(lRes != ERROR_SUCCESS) return 0; else { pszData = (char*)malloc(sizeof(char) * num + strlen(pszAddVal) + 1); //alloc lRes = RegQueryValueExA(hNewKey, pszValName, 0, 0, pszData, &num); //get reg key value; if(lRes != ERROR_SUCCESS) { free(pszData); return 0; } } strcat(pszData, pszAddVal); //add new value; lRes = RegSetValueExA(hNewKey, pszValName, 0, REG_EXPAND_SZ, pszData, strlen(pszData) + 1); //update reg key value; free(pszData); if(lRes != ERROR_SUCCESS) return 0; lRes = RegCloseKey(hNewKey); //close reg key; if(lRes != ERROR_SUCCESS) return 0; //tell the system (programs etc) about change (new path); SendMessageTimeoutA(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment", SMTO_ABORTIFHUNG, 5000, &dwRes); return 1; }
BOOL SkypeAttach(HWND hwnd) { LRESULT result; _hwndSkype = NULL; result = SendMessageTimeoutA(HWND_BROADCAST, _msgDiscover, (WPARAM)hwnd, (LPARAM)NULL, 2, 5000, NULL); if (!result) { MessageBox(hwnd, "cannot send message discover", "error", MB_OK | MB_ICONSTOP | MB_APPLMODAL); return TRUE; } return FALSE; }
static BOOL CaptureTextOut(HDC hdc, int nXStart, int nYStart, LPCSTR lpszString, int cbString, BOOL bWChr) { SIZE tSize; POINT ptTextPos; RECT Rect; BOOL bInsideRect = FALSE; POINT pMouse = g_pMouse; GetTextExtentPoint32X(hdc, lpszString, cbString, &tSize, bWChr); ptTextPos.x = nXStart; ptTextPos.y = nYStart; LPtoDP(hdc, &ptTextPos, 1); Rect.left = ptTextPos.x; Rect.right = ptTextPos.x + tSize.cx; Rect.top = ptTextPos.y; Rect.bottom = ptTextPos.y + tSize.cy; /* * On some situation, RECT will be [0,4,-100,-83] or [36,114,-9,8], * while mouse point be [47, 100]. It seems 'ptTexPos.y' being wrong. */ #if 0 DWORD ret; SendMessageTimeoutA(g_hHookServer, WM_CW_DEBUG, -1, cbString, SMTO_ABORTIFHUNG, 50, &ret); SendMessageTimeoutA(g_hHookServer, WM_CW_DEBUG, Rect.left, Rect.right, SMTO_ABORTIFHUNG, 50, &ret); SendMessageTimeoutA(g_hHookServer, WM_CW_DEBUG, Rect.top, Rect.bottom, SMTO_ABORTIFHUNG, 50, &ret); #endif if (Rect.top < 0) { if (Rect.left <= pMouse.x && Rect.right >= pMouse.x) bInsideRect = TRUE; } else { if (PtInRect(&Rect, pMouse)) bInsideRect = TRUE; } if (bInsideRect) { int pos; SIZE iterSize; pos =(int)((pMouse.x - Rect.left) * cbString /((float)tSize.cx)+0.5); GetTextExtentPoint32X(hdc, lpszString, pos+1, &iterSize, bWChr); if(iterSize.cx < pMouse.x - ptTextPos.x) { do { pos++; GetTextExtentPoint32X(hdc, lpszString, pos+1, &iterSize, bWChr); }while((iterSize.cx < pMouse.x - ptTextPos.x) && (pos < cbString-1)); } else if (iterSize.cx > pMouse.x - ptTextPos.x) { do { pos--; GetTextExtentPoint32X(hdc, lpszString, pos+1, &iterSize, bWChr); }while((iterSize.cx > pMouse.x - ptTextPos.x) && (pos > 0)); } g_tPos = pos; int size = cbString; if (bWChr) size = size * sizeof(WCHAR); size = size > 253 ? 253 : size; // ending with '/0' CopyMemory(g_strbuf, lpszString, size); g_strbuf[size] = '\0'; g_strbuf[size+1] = '\0'; return TRUE; } return FALSE; }
int main() { HINSTANCE hins = GetModuleHandle(0); char* caption = "DxPlayer"; DWORD_PTR dwResult; hWnd = CreateWindowDefault(L"DxPlayer", 20, 20, 640, 480, hins); if (hWnd == INVALID_HANDLE_VALUE) { return 1; } RECT rect; GetClientRect(hWnd, &rect); DxPlayer player(hWnd); if (player.initDriver(rect.right - rect.left, rect.bottom - rect.top) == false) { return false; } SendMessageTimeoutA(hWnd, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(caption), SMTO_ABORTIFHUNG, 2000, &dwResult); ShowWindow(hWnd, SW_SHOWNORMAL); UpdateWindow(hWnd); MSG msg = { 0 }; JpgStreamReceiver* recv = new JpgStreamReceiver(4); recv->open("http://localhost:8090/?action=stream", err_handler, NULL); while (1) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); if (msg.message == WM_QUIT) break; } else { Image* img = recv->pop(); if (img&&ImageFactory::decodeJpegToRGB(img)) { player.beginScene(); player.showImage(img); player.endScene(); delete img; } } Sleep(1); } recv->close(); UnregisterClass(L"DXPLAYERWND",hins); //delete[] img.buffer; return 0; }