QSystemTrayIconSys::QSystemTrayIconSys(QSystemTrayIcon *object) : hIcon(0), q(object) { currentShellVersion = detectShellVersion(); notifyIconSizeA = FIELD_OFFSET(NOTIFYICONDATAA, szTip[64]); // NOTIFYICONDATAA_V1_SIZE notifyIconSizeW = FIELD_OFFSET(NOTIFYICONDATAW, szTip[64]); // NOTIFYICONDATAW_V1_SIZE; maxTipLength = 64; #if NOTIFYICON_VERSION >= 3 if (currentShellVersion >=5) { notifyIconSizeA = FIELD_OFFSET(NOTIFYICONDATAA, guidItem); // NOTIFYICONDATAA_V2_SIZE notifyIconSizeW = FIELD_OFFSET(NOTIFYICONDATAW, guidItem); // NOTIFYICONDATAW_V2_SIZE; maxTipLength = 128; } #endif // For restoring the tray icon after explorer crashes if (!MYWM_TASKBARCREATED) { MYWM_TASKBARCREATED = QT_WA_INLINE(RegisterWindowMessageW(L"TaskbarCreated"),RegisterWindowMessageA("TaskbarCreated")); } }
namespace widget { UINT sDefaultBrowserMsgId = RegisterWindowMessageW(L"DefaultBrowserClosing"); } }
static INT_PTR CALLBACK FormatChooseDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { PACMFORMATCHOOSEW afc = (PACMFORMATCHOOSEW)GetPropW(hWnd, fmt_prop); TRACE("hwnd=%p msg=%i 0x%08lx 0x%08lx\n", hWnd, msg, wParam, lParam); switch (msg) { case WM_INITDIALOG: afc = (PACMFORMATCHOOSEW)lParam; SetPropW(hWnd, fmt_prop, (HANDLE)afc); MSACM_FillFormatTags(hWnd); MSACM_FillFormat(hWnd); if ((afc->fdwStyle & ~(ACMFORMATCHOOSE_STYLEF_CONTEXTHELP| ACMFORMATCHOOSE_STYLEF_SHOWHELP| ACMFORMATCHOOSE_STYLEF_ENABLETEMPLATEHANDLE| ACMFORMATCHOOSE_STYLEF_ENABLETEMPLATE)) != 0) FIXME("Unsupported style %08x\n", afc->fdwStyle); if (!(afc->fdwStyle & ACMFORMATCHOOSE_STYLEF_SHOWHELP)) ShowWindow(GetDlgItem(hWnd, IDD_ACMFORMATCHOOSE_BTN_HELP), SW_HIDE); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: EndDialog(hWnd, MSACM_GetWFX(hWnd, afc)); return TRUE; case IDCANCEL: EndDialog(hWnd, ACMERR_CANCELED); return TRUE; case IDD_ACMFORMATCHOOSE_CMB_FORMATTAG: switch (HIWORD(wParam)) { case CBN_SELCHANGE: MSACM_FillFormat(hWnd); break; default: TRACE("Dropped dlgNotif (fmtTag): 0x%08x 0x%08lx\n", HIWORD(wParam), lParam); break; } break; case IDD_ACMFORMATCHOOSE_BTN_HELP: if (afc->fdwStyle & ACMFORMATCHOOSE_STYLEF_SHOWHELP) SendMessageW(afc->hwndOwner, RegisterWindowMessageW(ACMHELPMSGSTRINGW), 0L, 0L); break; default: TRACE("Dropped dlgCmd: ctl=%d ntf=0x%04x 0x%08lx\n", LOWORD(wParam), HIWORD(wParam), lParam); break; } break; case WM_CONTEXTMENU: if (afc->fdwStyle & ACMFORMATCHOOSE_STYLEF_CONTEXTHELP) SendMessageW(afc->hwndOwner, RegisterWindowMessageW(ACMHELPMSGCONTEXTMENUW), wParam, lParam); break; #if defined(WM_CONTEXTHELP) case WM_CONTEXTHELP: if (afc->fdwStyle & ACMFORMATCHOOSE_STYLEF_CONTEXTHELP) SendMessageW(afc->hwndOwner, RegisterWindowMessageW(ACMHELPMSGCONTEXTHELPW), wParam, lParam); break; #endif default: TRACE("Dropped dlgMsg: hwnd=%p msg=%i 0x%08lx 0x%08lx\n", hWnd, msg, wParam, lParam ); break; } return FALSE; }
static void register_messages(void) { oleui_msg_help = RegisterWindowMessageW(SZOLEUI_MSG_HELPW); oleui_msg_enddialog = RegisterWindowMessageW(SZOLEUI_MSG_ENDDIALOGW); }
BOOL WINAPI DllMain(HANDLE hinstDLL,DWORD dwReason, LPVOID lpvReserved) { WCHAR MsgBuffer[600]; if (dwReason == DLL_PROCESS_ATTACH) { ihinstDLL = (HINSTANCE) hinstDLL; GetModuleFileNameW((HMODULE) hinstDLL,MsgBuffer,sizeof(MsgBuffer)); HOOK_GUI_MSG = RegisterWindowMessageW(MsgBuffer); CBT_MSG = RegisterWindowMessageW(L"CBT_MSG"); DEBUG_MSG = RegisterWindowMessageW(L"DEBUG_MSG"); FOREGROUNDIDLE_MSG = RegisterWindowMessageW(L"FOREGROUNDIDLE_MSG"); GETMESSAGE_MSG = RegisterWindowMessageW(L"GETMESSAGE_MSG"); KEYBOARD_MSG = RegisterWindowMessageW(L"KEYBOARD_MSG"); MOUSE_MSG = RegisterWindowMessageW(L"MOUSE_MSG"); MSGFILTER_MSG = RegisterWindowMessageW(L"MSGFILTER_MSG"); SHELL_MSG = RegisterWindowMessageW(L"SHELL_MSG"); KEYBOARDLL_MSG = RegisterWindowMessageW(L"KEYBOARDLL_MSG"); MOUSELL_MSG = RegisterWindowMessageW(L"MOUSELL_MSG"); atexit(AtExitHookExW); } return 1; }
namespace widget { // Native event callback message. UINT sAppShellGeckoMsgId = RegisterWindowMessageW(L"nsAppShell:EventID"); } }
void WinSevenTaskbar::init(void) { m_winMsg = RegisterWindowMessageW(L"TaskbarButtonCreated"); m_ptbl = NULL; }
QWinEventFilter::QWinEventFilter() : tbButtonCreatedMsgId(RegisterWindowMessageW(L"TaskbarButtonCreated")) { }
BOOL LibMain( HANDLE hModule, DWORD dwReason, LPVOID lpRes) { switch (dwReason) { case ( DLL_THREAD_ATTACH ) : { // // Threads can only enter the comdlg32 dll from the // Get{Open,Save}FileName apis, so the TLS lpCurDir alloc is // done inside the InitFileDlg routine in fileopen.c // return (TRUE); break; } case ( DLL_THREAD_DETACH ) : { LPTSTR lpCurDir; LPDWORD lpCurThread; LPDWORD lpExtError; if (lpCurDir = (LPTSTR)TlsGetValue(g_tlsiCurDir)) { LocalFree(lpCurDir); TlsSetValue(g_tlsiCurDir, NULL); } if (lpCurThread = (LPDWORD)TlsGetValue(g_tlsiCurThread)) { LocalFree(lpCurThread); TlsSetValue(g_tlsiCurThread, NULL); } if (lpExtError = (LPDWORD)TlsGetValue(g_tlsiExtError)) { LocalFree(lpExtError); TlsSetValue(g_tlsiExtError, NULL); } return (TRUE); } case ( DLL_PROCESS_ATTACH ) : { g_hinst = (HANDLE)hModule; if (!FInitColor(g_hinst) || !FInitFile(g_hinst)) { goto CantInit; } DisableThreadLibraryCalls(hModule); // // msgHELP is sent whenever a help button is pressed in one of // the common dialogs (provided an owner was declared and the // call to RegisterWindowMessage doesn't fail. // msgHELPA = RegisterWindowMessageA((LPSTR)szCommdlgHelpA); msgHELPW = RegisterWindowMessageW((LPWSTR)szCommdlgHelpW); // // Need a semaphore locally for managing array of disk info. // InitializeCriticalSection(&g_csLocal); // // Need a semaphore for control access to CreateThread. // InitializeCriticalSection(&g_csNetThread); // // Need a semaphore for access to extended error info. // InitializeCriticalSection(&g_csExtError); // // Allocate a tls index for curdir so we can make it per-thread. // if ((g_tlsiCurDir = TlsAlloc()) == 0xFFFFFFFF) { StoreExtendedError(CDERR_INITIALIZATION); goto CantInit; } // // Allocate a tls index for curthread so we can give each a // number. // if ((g_tlsiCurThread = TlsAlloc()) == 0xFFFFFFFF) { StoreExtendedError(CDERR_INITIALIZATION); goto CantInit; } // // Allocate a tls index for extended error. // if ((g_tlsiExtError = TlsAlloc()) == 0xFFFFFFFF) { StoreExtendedError(CDERR_INITIALIZATION); goto CantInit; } dwNumDisks = 0; // // NetEnumBuf allocated in ListNetDrivesHandler. // cbNetEnumBuf = WNETENUM_BUFFSIZE; hMPR = NULL; hLNDEvent = NULL; return (TRUE); break; } case ( DLL_PROCESS_DETACH ) : { // // We only want to do our clean up work if we are being called // with freelibrary, not if the process is ending. // if (lpRes == NULL) { TermFile(); TermPrint(); TermColor(); TermFont(); TlsFree(g_tlsiCurDir); TlsFree(g_tlsiCurThread); TlsFree(g_tlsiExtError); DeleteCriticalSection(&g_csLocal); DeleteCriticalSection(&g_csNetThread); DeleteCriticalSection(&g_csExtError); } return (TRUE); break; } } CantInit: return (FALSE); lpRes; }
//------------------------------------------------------------------------------------------------- static LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { //Skype begin static UINT iIdSkypeControlApiAttach; static constexpr const LPARAM iSkypeControlApiAttachSuccess = 0; static COLORREF colRef = RGB(255, 127, 0); static bool bNeedSkype = true; //Skype end static HFONT hFont; static bool bTimerActive = false; static const wchar_t *wSoundCardName; switch (uMsg) { case WM_CREATE: { if ((hFont = CreateFontW(48, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH, L"Tahoma")) && SetLayeredWindowAttributes(hWnd, 0, 0, LWA_COLORKEY) && //Skype begin ((iIdSkypeControlApiAttach = RegisterWindowMessageW(L"SkypeControlAPIAttach")))) if (const UINT iCount = RegisterWindowMessageW(L"SkypeControlAPIDiscover")) if (PostMessageW(HWND_BROADCAST, iCount, reinterpret_cast<WPARAM>(hWnd), 0) && //Skype end SetTimer(hWnd, 1, 1500, nullptr)) { bTimerActive = true; wSoundCardName = static_cast<wchar_t*>(reinterpret_cast<const CREATESTRUCT*>(lParam)->lpCreateParams); return 0; } return -1; } case WM_PAINT: { PAINTSTRUCT ps; if (const HDC hDc = BeginPaint(hWnd, &ps)) { RECT rect; if (GetClientRect(hWnd, &rect)) { rect.top = 40; SelectObject(hDc, hFont); SetBkColor(hDc, RGB(1, 1, 1)); SetTextColor(hDc, colRef); //Skype DrawTextW(hDc, wSoundCardName, -1, &rect, DT_CENTER); } EndPaint(hWnd, &ps); } return 0; } //Skype begin case WM_COPYDATA: if (bNeedSkype) { const COPYDATASTRUCT *const copyData = reinterpret_cast<const COPYDATASTRUCT*>(lParam); if (copyData->dwData == 0 && copyData->cbData > 10 && strncmp(static_cast<const char*>(copyData->lpData), "AUDIO_OUT ", 10) == 0) { colRef = RGB(255, 255, 0); InvalidateRect(hWnd, nullptr, FALSE); bNeedSkype = false; } } return TRUE; //Skype end case WM_TIMER: { KillTimer(hWnd, 1); bTimerActive = false; PostMessageW(hWnd, WM_CLOSE, 0, 0); return 0; } case WM_DESTROY: { if (bTimerActive) KillTimer(hWnd, 1); if (hFont) DeleteObject(hFont); PostQuitMessage(0); return 0; } } //Skype begin if (uMsg == iIdSkypeControlApiAttach) { if (lParam == iSkypeControlApiAttachSuccess) { const wchar_t *wIt = wSoundCardName; while (*wIt++); int iLen = wIt-wSoundCardName-1; if (iLen <= 256) { char cBuf[14+256*sizeof(wchar_t)] = "SET AUDIO_OUT "; if (const int iSize = WideCharToMultiByte(CP_UTF8, 0, wSoundCardName, -1, cBuf+14, iLen*sizeof(wchar_t), nullptr, nullptr)) { COPYDATASTRUCT copyData; copyData.dwData = 0; copyData.cbData = 14 + iSize; copyData.lpData = cBuf; SendMessageTimeoutW(reinterpret_cast<HWND>(wParam), WM_COPYDATA, reinterpret_cast<WPARAM>(hWnd), reinterpret_cast<LPARAM>(©Data), SMTO_ABORTIFHUNG, 0, nullptr); } } } return 0; } //Skype end return DefWindowProcW(hWnd, uMsg, wParam, lParam); }
void Q_mswin::init(WId wid) { _windowId = wid; _taskbarMessageId = RegisterWindowMessageW(L"TaskbarButtonCreated"); }
// Если (anFromShowWindow != -1), значит функу зовут из ShowWindow void OnGuiWindowAttached(HWND hWindow, HMENU hMenu, LPCSTR asClassA, LPCWSTR asClassW, DWORD anStyle, DWORD anStyleEx, BOOL abStyleHidden, int anFromShowWindow/*=-1*/) { DWORD nCurStyle = (DWORD)GetWindowLongPtr(hWindow, GWL_STYLE); DWORD nCurStyleEx = (DWORD)GetWindowLongPtr(hWindow, GWL_EXSTYLE); AllowSetForegroundWindow(ASFW_ANY); // VLC создает несколько "подходящих" окон, но ShowWindow зовет // только для одного из них. Поэтому фактический аттач делаем // только в том случае, если окно "видимое" if ((!(nCurStyle & WS_VISIBLE)) && (anFromShowWindow <= SW_HIDE)) { // Значит потом, из ShowWindow return; } ghAttachGuiClient = hWindow; gnAttachGuiClientThreadId = GetWindowThreadProcessId(hWindow, NULL); gbForceShowGuiClient = TRUE; gbAttachGuiClient = FALSE; // Только одно окно приложения. Пока? #if 0 // Для WS_CHILDWINDOW меню нельзя указать при создании окна if (!hMenu && !ghAttachGuiClientMenu && (asClassA || asClassW)) { BOOL lbRcClass; WNDCLASSEXA wca = {sizeof(WNDCLASSEXA)}; WNDCLASSEXW wcw = {sizeof(WNDCLASSEXW)}; if (asClassA) { lbRcClass = GetClassInfoExA(GetModuleHandle(NULL), asClassA, &wca); if (lbRcClass) ghAttachGuiClientMenu = LoadMenuA(wca.hInstance, wca.lpszMenuName); } else { lbRcClass = GetClassInfoExW(GetModuleHandle(NULL), asClassW, &wcw); if (lbRcClass) ghAttachGuiClientMenu = LoadMenuW(wca.hInstance, wcw.lpszMenuName); } hMenu = ghAttachGuiClientMenu; } if (hMenu) { // Для WS_CHILDWINDOW - не работает SetMenu(hWindow, hMenu); HMENU hSys = GetSystemMenu(hWindow, FALSE); TODO("Это в принципе прокатывает, но нужно транслировать WM_SYSCOMMAND -> WM_COMMAND, соответственно, перехватывать WndProc, или хук ставить"); if (hSys) { TODO("Хотя, хорошо бы не все в Popup засоывать, а извлечь ChildPopups из hMenu"); InsertMenu(hSys, 0, MF_BYPOSITION|MF_POPUP, (UINT_PTR)hMenu, L"Window menu"); InsertMenu(hSys, 1, MF_BYPOSITION|MF_SEPARATOR, NULL, NULL); } } #endif DWORD nSize = sizeof(CESERVER_REQ_HDR)+sizeof(CESERVER_REQ_ATTACHGUIAPP); CESERVER_REQ *pIn = ExecuteNewCmd(CECMD_ATTACHGUIAPP, nSize); gnAttachGuiClientFlags = agaf_Success; // С приложенями .Net - приходится работать как с WS_CHILD, // иначе в них "не нажимаются" тулбары и меню if (IsDotNetWindow(hWindow)) { gnAttachGuiClientFlags |= (agaf_DotNet|agaf_WS_CHILD); } // Если в окне нет меню - работаем с ним как с WS_CHILD // так не возникает проблем с активацией и т.д. else if (GetMenu(hWindow) == NULL) { if (IsQtWindow(asClassA, asClassW)) gnAttachGuiClientFlags |= (agaf_NoMenu|agaf_QtWindow|agaf_WS_CHILD); else gnAttachGuiClientFlags |= (agaf_NoMenu|agaf_WS_CHILD); } pIn->AttachGuiApp.nFlags = gnAttachGuiClientFlags; pIn->AttachGuiApp.nPID = GetCurrentProcessId(); pIn->AttachGuiApp.nServerPID = gnServerPID; pIn->AttachGuiApp.hAppWindow = hWindow; pIn->AttachGuiApp.Styles.nStyle = nCurStyle; // стили могли измениться после создания окна, pIn->AttachGuiApp.Styles.nStyleEx = nCurStyleEx; // поэтому получим актуальные GetWindowRect(hWindow, &pIn->AttachGuiApp.rcWindow); GetModuleFileName(NULL, pIn->AttachGuiApp.sAppFilePathName, countof(pIn->AttachGuiApp.sAppFilePathName)); pIn->AttachGuiApp.hkl = (DWORD)(LONG)(LONG_PTR)GetKeyboardLayout(0); wchar_t szGuiPipeName[128]; msprintf(szGuiPipeName, countof(szGuiPipeName), CEGUIPIPENAME, L".", (DWORD)ghConEmuWnd); // AttachThreadInput DWORD nConEmuTID = GetWindowThreadProcessId(ghConEmuWnd, NULL); DWORD nTID = GetCurrentThreadId(); _ASSERTEX(nTID==gnHookMainThreadId || nTID==gnAttachGuiClientThreadId); BOOL bAttachRc = AttachThreadInput(nTID, nConEmuTID, TRUE); DWORD nAttachErr = GetLastError(); UNREFERENCED_PARAMETER(bAttachRc); UNREFERENCED_PARAMETER(nAttachErr); HWND hPreFocus = GetFocus(); CESERVER_REQ* pOut = ExecuteCmd(szGuiPipeName, pIn, 0/*Default timeout*/, NULL); ExecuteFreeResult(pIn); // abStyleHidden == TRUE, если окно при создании указало флаг WS_VISIBLE (т.е. не собиралось звать ShowWindow) if (pOut) { if (pOut->hdr.cbSize > sizeof(CESERVER_REQ_HDR)) { _ASSERTE((pOut->AttachGuiApp.nFlags & agaf_Success) == agaf_Success); BOOL lbRc = FALSE; _ASSERTE(pOut->AttachGuiApp.hConEmuBack && pOut->AttachGuiApp.hConEmuDc && (HWND)pOut->AttachGuiApp.hConEmuDc!=(HWND)pOut->AttachGuiApp.hConEmuBack); _ASSERTE((ghConEmuWndBack==NULL) || (pOut->AttachGuiApp.hConEmuBack==ghConEmuWndBack)); _ASSERTE(ghConEmuWnd && (ghConEmuWnd==pOut->AttachGuiApp.hConEmuWnd)); ghConEmuWnd = pOut->AttachGuiApp.hConEmuWnd; SetConEmuHkWindows(pOut->AttachGuiApp.hConEmuDc, pOut->AttachGuiApp.hConEmuBack); //gbGuiClientHideCaption = pOut->AttachGuiApp.bHideCaption; gGuiClientStyles = pOut->AttachGuiApp.Styles; #ifdef _DEBUG HWND hFocus = GetFocus(); DWORD nFocusPID = 0; if (hFocus) { GetWindowThreadProcessId(hFocus, &nFocusPID); DWORD nConEmuPID = 0; GetWindowThreadProcessId(ghConEmuWnd, &nConEmuPID); if (nFocusPID != GetCurrentProcessId() && nFocusPID != nConEmuPID) { // Допустимая ситуация, когда одновременно во вкладки цепляется // несколько ChildGui. Например, при запуске из bat-файла... hFocus = hWindow; } } #endif if (pOut->AttachGuiApp.hkl) { LONG_PTR hkl = (LONG_PTR)(LONG)pOut->AttachGuiApp.hkl; lbRc = ActivateKeyboardLayout((HKL)hkl, KLF_SETFORPROCESS) != NULL; UNREFERENCED_PARAMETER(lbRc); } //grcAttachGuiClientPos = pOut->AttachGuiApp.rcWindow; ReplaceGuiAppWindow(abStyleHidden); //if (hPreFocus) //{ // SetFocus(hPreFocus); //} UINT nMsgID = RegisterWindowMessageW(CONEMUMSG_RESTORECHILDFOCUS); PostMessageW(ghConEmuWndBack, nMsgID, 0,0); //// !!! OnSetForegroundWindow не подходит - он дергает Cmd. ////SetForegroundWindow(ghConEmuWnd); //#if 0 //wchar_t szClass[64] = {}; GetClassName(hFocus, szClass, countof(szClass)); //MessageBox(NULL, szClass, L"WasFocused", MB_SYSTEMMODAL); //#endif ////if (!(nCurStyle & WS_CHILDWINDOW)) //{ // // Если ставить WS_CHILD - пропадет меню! // //nCurStyle = (nCurStyle | WS_CHILDWINDOW|WS_TABSTOP); // & ~(WS_THICKFRAME/*|WS_CAPTION|WS_MINIMIZEBOX|WS_MAXIMIZEBOX*/); // //SetWindowLongPtr(hWindow, GWL_STYLE, nCurStyle); // if (gnAttachGuiClientFlags & agaf_DotNet) // { // } // else // { // SetParent(hWindow, ghConEmuWndBack); // } //} // //RECT rcGui = grcAttachGuiClientPos = pOut->AttachGuiApp.rcWindow; //if (SetWindowPos(hWindow, HWND_TOP, rcGui.left,rcGui.top, rcGui.right-rcGui.left, rcGui.bottom-rcGui.top, // SWP_DRAWFRAME | /*SWP_FRAMECHANGED |*/ (abStyleHidden ? SWP_SHOWWINDOW : 0))) //{ // if (abStyleHidden) // abStyleHidden = FALSE; //} // //// !!! OnSetForegroundWindow не подходит - он дергает Cmd. //SetForegroundWindow(ghConEmuWnd); ////if (hFocus) ////SetFocus(hFocus ? hFocus : hWindow); // hFocus==NULL, эффекта нет ////OnSetForegroundWindow(hWindow); ////PostMessageW(ghConEmuWnd, WM_NCACTIVATE, TRUE, 0); ////PostMessageW(ghConEmuWnd, WM_NCPAINT, 0, 0); //PostMessageW(hWindow, WM_NCPAINT, 0, 0); } ExecuteFreeResult(pOut); } if (abStyleHidden) { ShowWindow(hWindow, SW_SHOW); } }
#pragma comment(lib,"dwmapi.lib") #pragma comment(lib,"windowscodecs.lib") #pragma comment(lib,"Shell32.lib") #pragma comment(lib,"imm32.lib") #pragma comment(lib,"msimg32.lib") #pragma comment(lib,"comctl32.lib") #pragma comment(lib,"usp10.lib") NAMESPACEMETRO extern MUI::LocaleInfo localeinfo; WCHAR SizeStr[120] = { '0',' ','B','y','t','e','s','\0'};//Background #define DEFAULT_NOTES L"Irreversible behavior(Format),Task running don't remove or insert the device\nSupport: Windows 7 or Later And Corresponding Server OS" std::wstring Notes; static Decompress::SupervisorData SpData = {L"null",L"A:",0}; static ResolveSupervisor::ResolveData reData = { L"null", NULL }; const UINT METRO_MULTITHREAD_MSG = RegisterWindowMessageW(L"METRO_MULTITHREAD_MSG"); const UINT METRO_THREAD_RATESTATUS_MSG = RegisterWindowMessageW(L"METRO_THREAD_RATESTATUS_MSG"); static std::wstring envinfo=L"No Check Environment"; static Metro::PidKillHlp pidkill = { 0, false }; template<class Interface> inline void SafeRelease( Interface **ppInterfaceToRelease ) { if (*ppInterfaceToRelease != NULL) { (*ppInterfaceToRelease)->Release();
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { hWnd_WEMAP = 0; hWnd_cid_gui = 0; hWnd_navitel = 0; hWndEdit = 0; hWnd_self = 0; hWnd_last = 0; fname = "\\Storage Card\\wemap\\wemap_WinMain.txt"; fnamew = "\\Storage Card\\wemap\\Windows.txt"; MSG msg; FILE * pFileTXT; Angle = DMDO_180; pFileTXT = fopen (fname,"a"); UINT MS = RegisterWindowMessageW(L"Private End Route Voice"); fprintf (pFileTXT, "Private End Route Voice - %d\n", MS); MS = RegisterWindowMessageW(L"Private Start Route Voice"); fprintf (pFileTXT, "Private Start Route Voice - %d\n", MS); MS = RegisterWindowMessageW(L"Private Close LCN_Upgrade Process"); fprintf (pFileTXT, "Private Close LCN_Upgrade Process - %d\n", MS); MS = RegisterWindowMessageW(L"Private Trip Info"); fprintf (pFileTXT, "Private Trip Info - %d\n", MS); MS = RegisterWindowMessageW(L"Private Navi Start"); fprintf (pFileTXT, "Private Navi Start - %d\n", MS); MS = RegisterWindowMessageW(L"Private Navi Closed"); fprintf (pFileTXT, "Private Navi Closed - %d\n", MS); MS = RegisterWindowMessageW(L"Private Navi Destroyed"); fprintf (pFileTXT, "Private Navi Destroyed - %d\n", MS); MS = RegisterWindowMessageW(L"Private Navi Exit"); fprintf (pFileTXT, "Private Navi Exit - %d\n", MS); MS = RegisterWindowMessageW(L"Private Navi Volume"); fprintf (pFileTXT, "Private Navi Volume - %d\n", MS); MS = RegisterWindowMessageW(L"Private Navi Button Down"); fprintf (pFileTXT, "Private Navi Button Down - %d\n", MS); MS = RegisterWindowMessageW(L"Private Gps Ver Request"); fprintf (pFileTXT, "Private Gps Ver Request - %d\n", MS); MS = RegisterWindowMessageW(L"Private Gps Ver Reply"); fprintf (pFileTXT, "Private Gps Ver Reply - %d\n", MS); MS = RegisterWindowMessageW(L"Private TPEG Request"); fprintf (pFileTXT, "Private TPEG Request - %d\n", MS); MS = RegisterWindowMessageW(L"Private TPEG Reply"); fprintf (pFileTXT, "Private TPEG Reply - %d\n", MS); MS = RegisterWindowMessageW(L"Private Gps Speed S12"); fprintf (pFileTXT, "Private Gps Speed S12 - %d\n", MS); MS = RegisterWindowMessageW(L"Private Go To Main Dialog"); fprintf (pFileTXT, "Private Go To Main Dialog - %d\n", MS); MS = RegisterWindowMessageW(L"Private Go To Setting Dialog"); fprintf (pFileTXT, "Private Go To Setting Dialog - %d\n", MS); MS = RegisterWindowMessageW(L"Private Request Light Status"); fprintf (pFileTXT, "Private Request Light Status - %d\n", MS); MS = RegisterWindowMessageW(L"UK SA Message Received"); fprintf (pFileTXT, "UK SA Message Received - %d\n", MS); MS = RegisterWindowMessageW(L"UK Abort SA Client"); fprintf (pFileTXT, "UK Abort SA Client - %d\n", MS); PrivateModeChange = RegisterWindowMessageW(L"Private Mode Change"); fprintf (pFileTXT, "Private Mode Change - %d\n", PrivateModeChange); MS = RegisterWindowMessageW(L"Private Light Off"); fprintf (pFileTXT, "Private Light Off - %d\n", MS); MS = RegisterWindowMessageW(L"Private Light On"); fprintf (pFileTXT, "Private Light On - %d\n", MS); fclose (pFileTXT); // Perform application initialization: if (!InitInstance(hInstance, nCmdShow)) { return FALSE; } HACCEL hAccelTable; hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WEMAP)); int ret; int i; i = 0; ret = 1; while (ret) { while (!PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE)) { if (i++>1000) { if ((hWnd_navitel<=0) || (hWnd_WEMAP<=0) || (hWnd_cid_gui<=0)) EnumWindows( enum_proc, (LPARAM)"Ѕлокнот" ); i=0; } } ret = GetMessage(&msg, NULL, NULL, NULL); SYSTEMTIME st; GetLocalTime(&st); pFileTXT = fopen (fname,"a"); fprintf(pFileTXT, "---> Date: [%02d, %02d, %d] Time: [%02d:%02d:%02d] " ,st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond); fprintf (pFileTXT, " wnd(%d) msg(%d) wParam(%d-%d) lParam(%d-%d) \n", msg.hwnd,msg.message,LOWORD(msg.wParam), HIWORD(msg.wParam),LOWORD(msg.lParam), HIWORD(msg.lParam)); fclose (pFileTXT); if( ret != -1 ) { //else { TranslateMessage(&msg); DispatchMessage(&msg); } if (msg.message==PrivateModeChange) { pFileTXT = fopen (fname,"a"); int wmId; wmId = LOWORD(msg.wParam); if (wmId==1) { if (hWnd_navitel>0) { fprintf (pFileTXT, " Show Navitel \n"); ShowWindow(hWnd_navitel,SW_SHOW); SetForegroundWindow(hWnd_navitel); set_rotation(true); UpdateWindow(hWnd_navitel); } else { if (hWnd_WEMAP>0) { fprintf (pFileTXT, " Show WEMAP \n"); set_rotation(true); } } } else { if ((hWnd_navitel>0) || (hWnd_WEMAP>0)) if (wmId!=5) { fprintf (pFileTXT, " Hide Navitel(WEMAP) \n"); set_rotation(false); if (hWnd_navitel>0) ShowWindow(hWnd_navitel,SW_HIDE); else ShowWindow(hWnd_WEMAP,SW_HIDE); ShowWindow(hWnd_cid_gui,SW_SHOW); } } fclose (pFileTXT); } } } return( ret ); }
namespace Mordor { static Logger::ptr g_log = Log::lookup("mordor:eventloop"); static UINT g_tickleMessage = RegisterWindowMessageW(L"MordorEventLoopTickle"); EventLoop::Initializer::Initializer() { WNDCLASSW wndClass; memset(&wndClass, 0, sizeof(wndClass)); wndClass.lpfnWndProc = &EventLoop::wndProc; wndClass.hInstance = GetModuleHandleW(NULL); wndClass.lpszClassName = L"MordorEventLoop"; if (!RegisterClassW(&wndClass)) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("RegisterClassW"); } EventLoop::Initializer::~Initializer() { UnregisterClassW(L"MordorEventLoop", GetModuleHandleW(NULL)); } EventLoop::Initializer EventLoop::g_init; EventLoop::EventLoop() : Scheduler(1, true, 1) { m_messageWindow = NULL; m_messageWindow = CreateWindowW(L"MordorEventLoop", L"Mordor Event Loop", 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, GetModuleHandleW(NULL), this); if (!m_messageWindow) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("CreateWindowW"); m_idleHook = SetWindowsHookExW(WH_FOREGROUNDIDLE, &EventLoop::foregroundIdleProc, NULL, GetCurrentThreadId()); if (!m_idleHook) { DestroyWindow(m_messageWindow); MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("SetWindowsHookEx"); } start(); } EventLoop::~EventLoop() { stop(); DestroyWindow(m_messageWindow); UnhookWindowsHookEx(m_idleHook); } bool EventLoop::stopping() { MSG msg; return Scheduler::stopping() && !PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) && nextTimer() == ~0ull; } void EventLoop::idle() { while (!stopping()) { MORDOR_LOG_DEBUG(g_log) << m_messageWindow << " Starting new message pump"; schedule(boost::bind(&EventLoop::messagePump, this)); Fiber::yield(); } } void EventLoop::tickle() { MORDOR_LOG_TRACE(g_log) << m_messageWindow << " tickling"; if (!PostMessage(m_messageWindow, g_tickleMessage, 0, 0)) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("PostMessage"); } void EventLoop::onTimerInsertedAtFront() { unsigned long long next = nextTimer(); MORDOR_ASSERT(next != ~0ull); UINT uElapse = (UINT)((next / 1000) + 1); uElapse = std::max<UINT>(USER_TIMER_MINIMUM, uElapse); uElapse = std::min<UINT>(USER_TIMER_MAXIMUM, uElapse); if (!SetTimer(m_messageWindow, 1, uElapse, NULL)) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("SetTimer"); } LRESULT CALLBACK EventLoop::wndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { EventLoop *self = (EventLoop *)Scheduler::getThis(); MORDOR_ASSERT(self->m_messageWindow == hWnd || self->m_messageWindow == NULL); if (uMsg == g_tickleMessage) { MORDOR_LOG_TRACE(g_log) << hWnd << " received tickle"; Scheduler::yield(); return 0; } switch (uMsg) { case WM_TIMER: { MORDOR_LOG_TRACE(g_log) << hWnd << " processing timers"; std::vector<boost::function<void ()> > expired = self->processTimers(); if (!expired.empty()) self->schedule(expired.begin(), expired.end()); unsigned long long nextTimer = self->nextTimer(); if (nextTimer != ~0ull) { UINT uElapse = (UINT)((nextTimer / 1000) + 1); uElapse = std::max<UINT>(USER_TIMER_MINIMUM, uElapse); uElapse = std::min<UINT>(USER_TIMER_MAXIMUM, uElapse); if (!SetTimer(hWnd, 1, uElapse, NULL)) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("SetTimer"); } else { if (!KillTimer(hWnd, 1)) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("KillTimer"); } return 0; } default: return DefWindowProcW(hWnd, uMsg, wParam, lParam); } } LRESULT CALLBACK EventLoop::foregroundIdleProc(int nCode, WPARAM wParam, LPARAM lParam) { EventLoop *self = (EventLoop *)Scheduler::getThis(); MORDOR_LOG_TRACE(g_log) << self->m_messageWindow << " message pump idle"; if (self->hasWorkToDo()) self->tickle(); return CallNextHookEx(self->m_idleHook, nCode, wParam, lParam); } void EventLoop::messagePump() { MORDOR_LOG_DEBUG(g_log) << m_messageWindow << " starting message pump"; while (!hasWorkToDo() && !stopping()) { MSG msg; BOOL bRet = GetMessageW(&msg, NULL, 0, 0); if (bRet < 0) MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("GetMessageW"); if (bRet == 0) { stop(); return; } TranslateMessage(&msg); DispatchMessageW(&msg); } MORDOR_LOG_DEBUG(g_log) << m_messageWindow << " exiting message pump"; } }