/**************************************************************** RegisterPopUpDialog() is used to fill in the dialogPtr field of a PopTable entry and to set the user item procs of that dialog's popup items once you have loaded the dialog and have the dialog pointer. ****************************************************************/ void RegisterPopUpDialog(long dialogID, DialogPtr theDialog) { short i; #ifndef IBM short theType; Handle itemHandle; Rect itemBox; #endif for ( i = 0 ; i < sa_numPopUps ; i++ ) if (sa_popTable[i].dialogID == dialogID) { sa_popTable[i].dialogPtr = theDialog; #ifndef IBM GetDialogItem(theDialog, sa_popTable[i].popupItemNum, &theType, &itemHandle, &itemBox); SetDialogItem(theDialog, sa_popTable[i].popupItemNum, userItem, nil, &itemBox); SetDialogItemHandle(theDialog, sa_popTable[i].popupItemNum, (Handle)PopDraw); #else PopDraw(theDialog, sa_popTable[i].popupItemNum); LoadPopupMenu(theDialog, sa_popTable[i].menuID, sa_popTable[i].popupItemNum); #endif } }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { g_hInstance = hInstance; LogString( "vmpi_service_ui startup.\n" ); // Don't run multiple instances. HANDLE hMutex = CreateMutex( NULL, FALSE, "vmpi_service_ui_mutex" ); if ( hMutex && GetLastError() == ERROR_ALREADY_EXISTS ) return 1; // Hook spew output. SpewOutputFunc( MySpewOutputFunc ); InitConsoleWindow(); LogString( "Setup console window.\n" ); LoadStateFromRegistry(); // Setup the popup menu. if( !LoadPopupMenu() ) { return false; } UpdatePopupMenuState(); // Setup the tray icon. Msg( "Waiting for jobs...\n" ); if ( !g_ShellIconMgr.Init( &g_ShellIconMgrHelper, g_pIconTooltip, MYWM_NOTIFYICON, IDI_WAITING_ICON ) ) { return false; } // Connect to the VMPI service. g_ConnMgr.InitClient(); LogString( "Entering main loop.\n" ); while ( 1 ) { MSG msg; msg.message = !WM_QUIT; // So it doesn't accidentally exit. while ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { if ( msg.message == WM_QUIT ) break; TranslateMessage( &msg ); DispatchMessage( &msg ); } if ( msg.message == WM_QUIT ) break; g_ConnMgr.Update(); if ( !g_ConnMgr.IsConnected() ) { g_ShellIconMgr.ChangeIcon( IDI_UNCONNECTED ); } Sleep( 30 ); } // Important that we call this instead of letting the destructor do it because it deletes its // socket and it needs to cleanup some threads. g_ConnMgr.Term(); g_ShellIconMgr.Term(); return 0; }
virtual HRESULT STDMETHODCALLTYPE AppendMenu( OUT HMENU* phMenu) { HMENU hMenu, hSettingsMenu; DWORD dwLogoff; BOOL bWantLogoff; UINT uLastItemsCount = 5; /* 5 menu items below the last separator */ WCHAR szUser[128]; TRACE("ITrayPriv::AppendMenu\n"); hMenu = LoadPopupMenu(hExplorerInstance, MAKEINTRESOURCE(IDM_STARTMENU)); *phMenu = hMenu; if (hMenu == NULL) return E_FAIL; /* Remove menu items that don't apply */ dwLogoff = SHRestricted(REST_STARTMENULOGOFF); bWantLogoff = (dwLogoff == 2 || SHRestricted(REST_FORCESTARTMENULOGOFF) || GetExplorerRegValueSet(HKEY_CURRENT_USER, TEXT("Advanced"), TEXT("StartMenuLogoff"))); /* Favorites */ if (!GetExplorerRegValueSet(HKEY_CURRENT_USER, TEXT("Advanced"), TEXT("StartMenuFavorites"))) { DeleteMenu(hMenu, IDM_FAVORITES, MF_BYCOMMAND); } /* Documents */ if (SHRestricted(REST_NORECENTDOCSMENU)) { DeleteMenu(hMenu, IDM_DOCUMENTS, MF_BYCOMMAND); } /* Settings */ hSettingsMenu = FindSubMenu(hMenu, IDM_SETTINGS, FALSE); if (hSettingsMenu != NULL) { if (SHRestricted(REST_NOSETFOLDERS)) { /* Control Panel */ if (SHRestricted(REST_NOCONTROLPANEL)) { DeleteMenu(hSettingsMenu, IDM_CONTROLPANEL, MF_BYCOMMAND); /* Delete the separator below it */ DeleteMenu(hSettingsMenu, 0, MF_BYPOSITION); } /* Network Connections */ if (SHRestricted(REST_NONETWORKCONNECTIONS)) { DeleteMenu(hSettingsMenu, IDM_NETWORKCONNECTIONS, MF_BYCOMMAND); } /* Printers and Faxes */ DeleteMenu(hSettingsMenu, IDM_PRINTERSANDFAXES, MF_BYCOMMAND); } /* Security */ if (GetSystemMetrics(SM_REMOTECONTROL) == 0 || SHRestricted(REST_NOSECURITY)) { DeleteMenu(hSettingsMenu, IDM_SECURITY, MF_BYCOMMAND); } if (GetMenuItemCount(hSettingsMenu) == 0) { DeleteMenu(hMenu, IDM_SETTINGS, MF_BYCOMMAND); } } /* Search */ /* FIXME: Enable after implementing */ /* if (SHRestricted(REST_NOFIND)) */ { DeleteMenu(hMenu, IDM_SEARCH, MF_BYCOMMAND); } /* FIXME: Help */ /* Run */ if (SHRestricted(REST_NORUN)) { DeleteMenu(hMenu, IDM_RUN, MF_BYCOMMAND); } /* Synchronize */ if (!ShowSynchronizeMenuItem()) { DeleteMenu(hMenu, IDM_SYNCHRONIZE, MF_BYCOMMAND); uLastItemsCount--; } /* Log off */ if (dwLogoff != 1 && bWantLogoff) { /* FIXME: We need a more sophisticated way to determine whether to show or hide it, it might be hidden in too many cases!!! */ /* Update Log Off menu item */ if (!GetCurrentLoggedOnUserName(szUser, sizeof(szUser) / sizeof(szUser[0]))) { szUser[0] = _T('\0'); } if (!FormatMenuString(hMenu, IDM_LOGOFF, MF_BYCOMMAND, szUser)) { /* We couldn't update the menu item, delete it... */ DeleteMenu(hMenu, IDM_LOGOFF, MF_BYCOMMAND); } } else { DeleteMenu(hMenu, IDM_LOGOFF, MF_BYCOMMAND); uLastItemsCount--; } /* Disconnect */ if (GetSystemMetrics(SM_REMOTECONTROL) == 0) { DeleteMenu(hMenu, IDM_DISCONNECT, MF_BYCOMMAND); uLastItemsCount--; } /* Undock computer */ if (!ShowUndockMenuItem()) { DeleteMenu(hMenu, IDM_UNDOCKCOMPUTER, MF_BYCOMMAND); uLastItemsCount--; } /* Shut down */ if (SHRestricted(REST_NOCLOSE)) { DeleteMenu(hMenu, IDM_SHUTDOWN, MF_BYCOMMAND); uLastItemsCount--; } if (uLastItemsCount == 0) { /* Remove the separator at the end of the menu */ DeleteMenu(hMenu, IDM_LASTSTARTMENU_SEPARATOR, MF_BYCOMMAND); } return S_OK; }
/* Property page dialog callback */ INT_PTR CALLBACK SettingsPageProc(IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam) { PDATA pData; TCHAR Message[1024], Title[256]; pData = (PDATA)GetWindowLongPtr(hwndDlg, DWLP_USER); switch(uMsg) { case WM_INITDIALOG: { OnInitDialog(hwndDlg); break; } case WM_DRAWITEM: { LPDRAWITEMSTRUCT lpDrawItem; lpDrawItem = (LPDRAWITEMSTRUCT) lParam; if (lpDrawItem->CtlID == IDC_SETTINGS_SPECTRUM) ShowColorSpectrum(lpDrawItem->hDC, &lpDrawItem->rcItem, pData->CurrentDisplayDevice->CurrentSettings->dmBitsPerPel, pData); break; } case WM_COMMAND: { DWORD controlId = LOWORD(wParam); DWORD command = HIWORD(wParam); if (controlId == IDC_SETTINGS_ADVANCED && command == BN_CLICKED) DisplayAdvancedSettings(hwndDlg, pData->CurrentDisplayDevice); else if (controlId == IDC_SETTINGS_BPP && command == CBN_SELCHANGE) OnBPPChanged(hwndDlg, pData); break; } case WM_HSCROLL: { switch (LOWORD(wParam)) { case TB_LINEUP: case TB_LINEDOWN: case TB_PAGEUP: case TB_PAGEDOWN: case TB_TOP: case TB_BOTTOM: case TB_ENDTRACK: { DWORD newPosition = (DWORD) SendDlgItemMessage(hwndDlg, IDC_SETTINGS_RESOLUTION, TBM_GETPOS, 0, 0); OnResolutionChanged(hwndDlg, pData, newPosition, TRUE); break; } case TB_THUMBTRACK: OnResolutionChanged(hwndDlg, pData, HIWORD(wParam), FALSE); break; } break; } case WM_NOTIFY: { LPNMHDR lpnm = (LPNMHDR)lParam; if (lpnm->code == (UINT)PSN_APPLY) { if (pData->CurrentDisplayDevice->CurrentSettings->dmPelsWidth != pData->CurrentDisplayDevice->InitialSettings.dmPelsWidth || pData->CurrentDisplayDevice->CurrentSettings->dmPelsHeight != pData->CurrentDisplayDevice->InitialSettings.dmPelsHeight || pData->CurrentDisplayDevice->CurrentSettings->dmBitsPerPel != pData->CurrentDisplayDevice->InitialSettings.dmBitsPerPel) { /* FIXME: Need to test changes */ /* Apply new settings */ LONG rc; DEVMODE devmode; RtlZeroMemory(&devmode, sizeof(DEVMODE)); devmode.dmSize = (WORD)sizeof(DEVMODE); devmode.dmPelsWidth = pData->CurrentDisplayDevice->CurrentSettings->dmPelsWidth; devmode.dmPelsHeight = pData->CurrentDisplayDevice->CurrentSettings->dmPelsHeight; devmode.dmBitsPerPel = pData->CurrentDisplayDevice->CurrentSettings->dmBitsPerPel; devmode.dmDisplayFrequency = pData->CurrentDisplayDevice->CurrentSettings->dmDisplayFrequency; devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY; rc = ChangeDisplaySettingsEx( pData->CurrentDisplayDevice->DeviceName, &devmode, NULL, CDS_UPDATEREGISTRY, NULL); switch (rc) { case DISP_CHANGE_SUCCESSFUL: pData->CurrentDisplayDevice->InitialSettings.dmPelsWidth = pData->CurrentDisplayDevice->CurrentSettings->dmPelsWidth; pData->CurrentDisplayDevice->InitialSettings.dmPelsHeight = pData->CurrentDisplayDevice->CurrentSettings->dmPelsHeight; pData->CurrentDisplayDevice->InitialSettings.dmBitsPerPel = pData->CurrentDisplayDevice->CurrentSettings->dmBitsPerPel; break; case DISP_CHANGE_RESTART: LoadString(hApplet, IDS_DISPLAY_SETTINGS, Title, sizeof(Title) / sizeof(TCHAR)); LoadString(hApplet, IDS_APPLY_NEEDS_RESTART, Message, sizeof(Message) / sizeof (TCHAR)); MessageBox(hwndDlg, Message, Title, MB_OK | MB_ICONINFORMATION); break; case DISP_CHANGE_FAILED: default: LoadString(hApplet, IDS_DISPLAY_SETTINGS, Title, sizeof(Title) / sizeof(TCHAR)); LoadString(hApplet, IDS_APPLY_FAILED, Message, sizeof(Message) / sizeof (TCHAR)); MessageBox(hwndDlg, Message, Title, MB_OK | MB_ICONSTOP); break; } } } break; } case WM_CONTEXTMENU: { HWND hwndMonSel; HMENU hPopup; UINT uiCmd; POINT pt, ptClient; INT Index; pt.x = (SHORT)LOWORD(lParam); pt.y = (SHORT)HIWORD(lParam); hwndMonSel = GetDlgItem(hwndDlg, IDC_SETTINGS_MONSEL); if ((HWND)wParam == hwndMonSel) { if (pt.x == -1 && pt.y == -1) { RECT rcMon; Index = (INT)SendMessage(hwndMonSel, MSLM_GETCURSEL, 0, 0); if (Index >= 0 && (INT)SendMessage(hwndMonSel, MSLM_GETMONITORRECT, Index, (LPARAM)&rcMon) > 0) { pt.x = rcMon.left + ((rcMon.right - rcMon.left) / 2); pt.y = rcMon.top + ((rcMon.bottom - rcMon.top) / 2); } else pt.x = pt.y = 0; MapWindowPoints(hwndMonSel, NULL, &pt, 1); } else { ptClient = pt; MapWindowPoints(NULL, hwndMonSel, &ptClient, 1); Index = (INT)SendMessage(hwndMonSel, MSLM_HITTEST, (WPARAM)&ptClient, 0); } if (Index >= 0) { hPopup = LoadPopupMenu(hApplet, MAKEINTRESOURCE(IDM_MONITOR_MENU)); if (hPopup != NULL) { /* FIXME: Enable/Disable menu items */ EnableMenuItem(hPopup, ID_MENU_ATTACHED, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); EnableMenuItem(hPopup, ID_MENU_PRIMARY, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); EnableMenuItem(hPopup, ID_MENU_IDENTIFY, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); EnableMenuItem(hPopup, ID_MENU_PROPERTIES, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); uiCmd = (UINT)TrackPopupMenu(hPopup, TPM_RETURNCMD | TPM_RIGHTBUTTON, pt.x, pt.y, 0, hwndDlg, NULL); switch (uiCmd) { case ID_MENU_ATTACHED: case ID_MENU_PRIMARY: case ID_MENU_IDENTIFY: case ID_MENU_PROPERTIES: /* FIXME: Implement */ break; } DestroyMenu(hPopup); } } } break; } case WM_DESTROY: { DWORD i; PDISPLAY_DEVICE_ENTRY Current = pData->DisplayDeviceList; while (Current != NULL) { PDISPLAY_DEVICE_ENTRY Next = Current->Flink; PSETTINGS_ENTRY CurrentSettings = Current->Settings; while (CurrentSettings != NULL) { PSETTINGS_ENTRY NextSettings = CurrentSettings->Flink; HeapFree(GetProcessHeap(), 0, CurrentSettings); CurrentSettings = NextSettings; } HeapFree(GetProcessHeap(), 0, Current); Current = Next; } for (i = 0; i < NUM_SPECTRUM_BITMAPS; i++) { if (pData->hSpectrumBitmaps[i]) DeleteObject(pData->hSpectrumBitmaps[i]); } HeapFree(GetProcessHeap(), 0, pData); } } return FALSE; }