//================================================================================================ //--------------------+++--> Initialize Options dialog & customize T-Clock controls as required: static void OnInit(HWND hDlg) //----------------------------------------------------------+++--> { wchar_t path[MAX_PATH]; int controlid; LOGFONT logft; HFONT hftBold; HFONT hftStartup; time_t tt; struct tm tm; SetDlgItemText(hDlg, IDC_ABT_TITLE, ABT_TITLE); SetDlgItemText(hDlg, IDC_ABT_TCLOCK, ABT_TCLOCK); time(&tt); gmtime_r(&tt, &tm); if((tm.tm_mon == 11 && tm.tm_mday >= 18)) { HWND logo = GetDlgItem(hDlg, IDI_ABOUT_LOGO); HICON ico = LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(IDI_STOICJOKER_XMAS), IMAGE_ICON, 0,0, LR_SHARED); Static_SetIcon(logo, ico); SetDlgItemText(hDlg, IDC_ABT_StoicJoker, L"Merry"); SetDlgItemText(hDlg, IDC_ABT_StoicJoker2, L"Xmas"); // SetDlgItemText(hDlg, IDC_ABT_StoicJoker, L"Happy"); // SetDlgItemText(hDlg, IDC_ABT_StoicJoker2, L"Holidays"); } else if(!(tm.tm_sec % 11) && tm.tm_sec) { HWND logo = GetDlgItem(hDlg, IDI_ABOUT_LOGO); HICON ico = LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(IDI_STOICJOKER), IMAGE_ICON, 0,0, LR_SHARED); Static_SetIcon(logo, ico); SetDlgItemText(hDlg, IDC_ABT_StoicJoker, L"Stoic"); SetDlgItemText(hDlg, IDC_ABT_StoicJoker2, L"Joker"); } hftBold = (HFONT)SendMessage(hDlg, WM_GETFONT, 0, 0); GetObject(hftBold, sizeof(logft), &logft); logft.lfWeight = FW_BOLD; hftBold = CreateFontIndirect(&logft); logft.lfHeight = (logft.lfHeight * 140 / 100); hftStartup = CreateFontIndirect(&logft); for(controlid=GROUP_ABT_B_BEGIN; controlid<=GROUP_ABT_B_END; ++controlid){ SendDlgItemMessage(hDlg,controlid,WM_SETFONT,(WPARAM)hftBold,0); } SetUpdateChecks(hDlg, 0); SendDlgItemMessage(hDlg,IDC_STARTUP,WM_SETFONT,(WPARAM)hftStartup,0); LinkControl_Setup(GetDlgItem(hDlg,IDC_ABT_WEBuri), LCF_SIMPLE, NULL); LinkControl_Setup(GetDlgItem(hDlg,IDC_ABT_MAILuri), LCF_NOTIFYONLY, NULL); LinkControl_Setup(GetDlgItem(hDlg,IDC_ABT_FORUMuri), LCF_SIMPLE, NULL); CheckDlgButton(hDlg, IDC_STARTUP, GetStartupFile(hDlg,path)); }
INT_PTR CALLBACK OptionsPageMore::aboutBoxDialogProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { if (uMsg == WM_INITDIALOG) { int iconSize = LOWORD(GetDialogBaseUnits()) * 24 / 4; auto appIcon = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_A), IMAGE_ICON, iconSize, iconSize, LR_DEFAULTCOLOR); Static_SetIcon(GetDlgItem(hwnd, IDC_ABOUT_ICON), appIcon); SetDlgItemText(hwnd, IDC_ABOUT_VERSION, L"Version: " APP_VERSION); SetDlgItemText(hwnd, IDC_ABOUT_DATE, L"Compiled on: " APP_DATE); return TRUE; } if (uMsg == WM_NOTIFY) { auto pHdr = (const PNMLINK) lParam; if (pHdr->hdr.code == NM_CLICK || pHdr->hdr.code == NM_RETURN) { ShellExecute(NULL, L"open", pHdr->item.szUrl, NULL, NULL, SW_SHOW); return TRUE; } else { return FALSE; } } else if (uMsg == WM_COMMAND && HIWORD(wParam) == BN_CLICKED) { DestroyIcon(Static_GetIcon(GetDlgItem(hwnd, IDC_ABOUT_ICON), 0)); EndDialog(hwnd, IDOK); return TRUE; } else { return FALSE; } }
void UpDate_CountryIcon(HWND hCtrl, int countryID) { HICON hIcon = LoadFlagIcon(countryID); HICON hOld = Static_SetIcon(hCtrl, hIcon); ShowWindow(hCtrl, hIcon ? SW_SHOW : SW_HIDE); IcoLib_ReleaseIcon(hOld); }
/* ** Called when tab is displayed. ** */ void CDialogAbout::CTabVersion::Initialize() { m_Initialized = true; HWND item = GetDlgItem(m_Window, IDC_ABOUTVERSION_RAINMETER_ICON); HICON icon = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_RAINMETER), IMAGE_ICON, 32, 32, LR_SHARED); Static_SetIcon(item, icon); item = GetDlgItem(m_Window, IDC_ABOUTVERSION_VERSION_TEXT); WCHAR tmpSz[64]; _snwprintf_s(tmpSz, _TRUNCATE, L"%s%s r%i %s (%s)", APPVERSION, revision_beta ? L" beta" : L"", revision_number, APPBITS, APPDATE); SetWindowText(item, tmpSz); item = GetDlgItem(m_Window, IDC_ABOUTVERSION_PATH_TEXT); std::wstring text = L"Path: " + Rainmeter->GetPath(); SetWindowText(item, text.c_str()); item = GetDlgItem(m_Window, IDC_ABOUTVERSION_INIFILE_TEXT); text = L"IniFile: " + Rainmeter->GetIniFile(); SetWindowText(item, text.c_str()); item = GetDlgItem(m_Window, IDC_ABOUTVERSION_SKINPATH_TEXT); text = L"SkinPath: " + Rainmeter->GetSkinPath(); SetWindowText(item, text.c_str()); }
static BOOL Cls_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam) { PopupParamsStruct *lpPopupParams = (PopupParamsStruct *)lParam; PeripheralIcon periphIcon; DWORD dwSize; TCHAR szBuffer[128]; PopupInfoStruct *lpPopupInfo; if (lpPopupInfo = (PopupInfoStruct *)HP_GLOBAL_ALLOC_DLL(sizeof(PopupInfoStruct))) { lpPopupInfo->helpContext = lpPopupParams->lpPeriphStatus->helpContext; _tcscpy(lpPopupInfo->helpFilename, lpPopupParams->lpPeriphStatus->helpFilename); } SetWindowLong(hwnd, DWL_USER, (LONG)lpPopupInfo); dwSize = sizeof(PeripheralInfo); if (PALGetObject(lpPopupParams->hPeriph, OT_PERIPHERAL_ICON, 0, &periphIcon, &dwSize) == RC_SUCCESS) { HICON hIcon = LoadIcon(periphIcon.hResourceModule, MAKEINTRESOURCE(periphIcon.iconResourceID)); if (hIcon) { Static_SetIcon(GetDlgItem(hwnd, IDD_ALERT_ICON), hIcon); } } wsprintf(szBuffer, TEXT("%s: %s"), (LPCTSTR)lpPopupParams->lpPeriphInfo->smashedName, (LPCTSTR)lpPopupParams->lpszStatus); SetDlgItemText(hwnd, IDD_ALERT_STRING, szBuffer); SetForegroundWindow(hwnd); return TRUE; }
void DialogAbout::TabVersion::Initialize() { HWND item = GetControl(Id_AppIcon); HICON icon = GetIcon(IDI_RAINMETER, true); Static_SetIcon(item, icon); item = GetControl(Id_VersionLabel); WCHAR tmpSz[64]; _snwprintf_s(tmpSz, _TRUNCATE, L"%s%s r%i %s (%s)", APPVERSION, revision_beta ? L" beta" : L"", revision_number, APPBITS, APPDATE); SetWindowText(item, tmpSz); item = GetControl(Id_WinVerLabel); SetWindowText(item, Platform::GetPlatformFriendlyName().c_str()); item = GetControl(Id_PathLabel); std::wstring text = L"Path: " + GetRainmeter().GetPath(); SetWindowText(item, text.c_str()); item = GetControl(Id_IniFileLabel); text = L"IniFile: " + GetRainmeter().GetIniFile(); SetWindowText(item, text.c_str()); item = GetControl(Id_SkinPathLabel); text = L"SkinPath: " + GetRainmeter().GetSkinPath(); SetWindowText(item, text.c_str()); m_Initialized = true; }
//-------------------------------------------------------------------- // Function: Cls_OnTimer // // Description: // // Input: hwnd - // id - // // Modifies: // // Returns: // //-------------------------------------------------------------------- static void Cls_OnTimer(HWND hwnd, UINT id) { HWND hwndChild; WORD percent; if (timerCount < NUM_TICKS) { if (hwndChild = GetDlgItem(hwnd, IDC_CLOCK_ICON)) { Static_SetIcon(hwndChild, hTimers[timerCount % 8]); } if (hwndChild = GetDlgItem(hwnd, IDC_PROGRESS_BAR)) { percent = (WORD)((timerCount * 3) + 7); SetWindowWord(hwndChild, GWW_TRAYLEVEL, percent); InvalidateRect(hwndChild, NULL, FALSE); } timerCount++; } else { EndDialog(hwnd, id); } }
HICON IRA_Dialog::SetIcon(HWND hwnd, BOOL bBigIcon, HICON hicon) { if (!hicon) return FORWARD_WM_SETICON(hwnd, bBigIcon, hicon, PostMessage); return Static_SetIcon(hwnd, hicon); }
INT_PTR CDialogInstall::OnInitDialog(WPARAM wParam, LPARAM lParam) { static const ControlTemplate::Control s_Controls[] = { CT_ICON(Id_HeaderIcon, 0, 10, 10, 24, 24, WS_VISIBLE, 0), CT_LABEL(Id_HeaderTitleLabel, 2, 40, 6, 250, 14, WS_VISIBLE | SS_ENDELLIPSIS | SS_NOPREFIX, 0), CT_LABEL(-1, 3, 40, 20, 250, 9, WS_VISIBLE | SS_ENDELLIPSIS | SS_NOPREFIX, 0), CT_BUTTON(Id_InstallButton, 1, 199, 191, 70, 14, WS_VISIBLE | WS_TABSTOP | BS_DEFPUSHBUTTON, 0), CT_BUTTON(Id_CancelButton, 13, 274, 191, 70, 14, WS_VISIBLE | WS_TABSTOP | BS_DEFPUSHBUTTON, 0), CT_TAB(Id_Tab, 0, -2, 36, 400, 150, WS_VISIBLE | WS_TABSTOP | TCS_FIXEDWIDTH, 0) // Last for correct tab order. }; CreateControls(s_Controls, _countof(s_Controls), m_Font, GetString); m_TabContents.Create(m_Window); m_TabContents.Activate(); SendMessage(m_Window, WM_SETICON, ICON_SMALL, (LPARAM)GetIcon(IDI_APPICON, false)); HWND item = GetControl(Id_HeaderIcon); Static_SetIcon(item, GetIcon(IDI_APPICON, true)); item = GetControl(Id_HeaderTitleLabel); SendMessage(item, WM_SETFONT, (WPARAM)m_FontBold, 0); item = GetControl(Id_InstallButton); SendMessage(m_Window, WM_NEXTDLGCTL, (WPARAM)item, TRUE); if (Platform::IsAtLeastWinVista() && !Util::IsProcessUserAdmin()) { Button_SetElevationRequiredState(item, TRUE); } return TRUE; }
//--------------------------------------------------------------------------- INT_PTR CALLBACK TfrmMain::DlgProc_CaptureWindow(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { // main message handling is done inside TfrmMain::DlgTfrmMain switch (uMsg) { case WM_INITDIALOG: Static_SetIcon(GetDlgItem(hDlg, ID_imgTarget), IcoLib_GetIcon(ICO_PLUG_SSTARGET)); SetDlgItemText(hDlg, ID_edtCaption, TranslateT("Drag&Drop the target on the desired window.")); TranslateDialogDefault(hDlg); break; case WM_CTLCOLOREDIT: //ctrl is NOT read-only or disabled case WM_CTLCOLORSTATIC: //ctrl is read-only or disabled // make the rectangle on the top white switch (GetWindowLongPtr((HWND)lParam, GWL_ID)) { case IDC_WHITERECT: case ID_chkClientArea: case ID_lblDropInfo: case ID_edtCaption: case ID_edtCaptionLabel: case ID_edtSize: case ID_edtSizeLabel: case ID_bvlTarget: case ID_imgTarget: SetBkColor((HDC)wParam,GetSysColor(COLOR_WINDOW)); SetTextColor((HDC)wParam,GetSysColor(COLOR_WINDOWTEXT)); //SetBkMode((HDC)wParam,OPAQUE); //return (INT_PTR)GetSysColorBrush(COLOR_WINDOW); return (LRESULT)GetStockObject(WHITE_BRUSH); default: SetBkMode((HDC)wParam, TRANSPARENT); return (LRESULT)GetStockObject(NULL_BRUSH); } break; //this return false case WM_COMMAND: SendMessage(GetParent(hDlg), uMsg, wParam, lParam); break; case WM_NOTIFY: SendMessage(GetParent(hDlg), uMsg, wParam, lParam); break; case WM_DESTROY: break; } return FALSE; }
//--------------------------------------------------------------------------- INT_PTR CALLBACK TfrmMain::DlgProc_CaptureDesktop(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { // main message handling is done inside TfrmMain::DlgTfrmMain switch (uMsg) { case WM_INITDIALOG: Static_SetIcon(GetDlgItem(hDlg, ID_imgTarget), IcoLib_GetIcon(ICO_PLUG_SSMONITOR)); break; case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: // make the rectangle on the top white switch (GetWindowLongPtr((HWND)lParam, GWL_ID)) { case IDC_WHITERECT: case ID_lblDropInfo: case ID_edtCaption: case ID_edtCaptionLabel: case ID_edtSize: case ID_edtSizeLabel: case ID_bvlTarget: case ID_imgTarget: SetBkColor((HDC)wParam,GetSysColor(COLOR_WINDOW)); SetTextColor((HDC)wParam,GetSysColor(COLOR_WINDOWTEXT)); return (LRESULT)GetStockObject(WHITE_BRUSH); default: SetBkMode((HDC)wParam, TRANSPARENT); return (LRESULT)GetStockObject(NULL_BRUSH); } break; case WM_COMMAND: SendMessage(GetParent(hDlg), uMsg, wParam, lParam); break; case WM_NOTIFY: SendMessage(GetParent(hDlg), uMsg, wParam, lParam); break; case WM_DESTROY: break; } return FALSE; }
BOOL CMainWindow::OnCreate(__in HINSTANCE hInstance) { // window caption SetWindowTextW(m_hDialog, pStrings->Get(IDS_XPI).c_str()); // XPIGUI m_pXPIGUI = new XPIGUI; ZeroMemory(m_pXPIGUI, sizeof(XPIGUI)); // XPIGUI - instance m_pXPIGUI->hInstance = hInstance; // XPIGUI - application icon m_pXPIGUI->hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_XPI)); if (m_pXPIGUI->hIcon != NULL) SendMessageW(m_hDialog, WM_SETICON, ICON_BIG, (LPARAM)m_pXPIGUI->hIcon); #ifdef _DEBUG else pLog->Write(LOG_WF_ERROR | LOG_WF_ECHODEBUG, L"Couldn't load XPI icon, continuing anyway. [LE=0x%08X]", GetLastError()); #endif // XPIGUI - small application icon m_pXPIGUI->hIconSmall = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_XPI_SMALL)); if (m_pXPIGUI->hIconSmall != NULL) SendMessageW(m_hDialog, WM_SETICON, ICON_SMALL, (LPARAM)m_pXPIGUI->hIconSmall); #ifdef _DEBUG else pLog->Write(LOG_WF_ERROR | LOG_WF_ECHODEBUG, L"Couldn't load small XPI icon, continuing anyway. [LE=0x%08X]", GetLastError()); #endif // XPIGUI - load Consolas from resource m_pXPIGUI->hMemFont = AddFontFromResource(GetModuleHandle(NULL), MAKEINTRESOURCEW(IDR_CONSOLAS)); if (m_pXPIGUI->hMemFont == NULL) { } // XPIGUI - Consolas font handle m_pXPIGUI->hFont = CreateFontW(14, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_CHARACTER_PRECIS, CLEARTYPE_QUALITY, FF_DONTCARE, L"Consolas"); if (m_pXPIGUI->hFont == NULL) { #ifdef _DEBUG pLog->Write(LOG_WF_ERROR, L"Couldn't create log font, aborting. [LE=0x%08X]", GetLastError()); #endif NotifyErrorUI(); return FALSE; } // XPIGUI - direction image list do { m_pXPIGUI->hImageList = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 4, 0); ImageList_SetBkColor(m_pXPIGUI->hImageList, CLR_NONE); if (m_pXPIGUI->hImageList != NULL) { HBITMAP hBitmap = LoadBitmapW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDB_DIRECTIONS)); if (hBitmap != NULL) { if (ImageList_AddMasked(m_pXPIGUI->hImageList, hBitmap, RGB(255, 0, 255)) != -1) break; DeleteObject((HGDIOBJ)hBitmap); } } #ifdef _DEBUG pLog->Write(LOG_WF_ERROR, L"Couldn't create packet direction icons image-list, aborting."); #endif NotifyErrorUI(); return FALSE; } while (0); // XPIGUI - injection icons m_pXPIGUI->hInjectOut = (HICON)LoadImageW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDI_INJECT_OUT), IMAGE_ICON, 16, 16, 0); if (m_pXPIGUI->hInjectOut == NULL) { #ifdef _DEBUG pLog->Write(LOG_WF_ERROR, L"Couldn't load inject OUT icon, aborting. [LE=0x%08X]", GetLastError()); #endif NotifyErrorUI(); return FALSE; } m_pXPIGUI->hInjectIn = (HICON)LoadImageW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDI_INJECT_IN), IMAGE_ICON, 16, 16, 0); if (m_pXPIGUI->hInjectIn == NULL) { #ifdef _DEBUG pLog->Write(LOG_WF_ERROR, L"Couldn't load inject IN icon, aborting. [LE=0x%08X]", GetLastError()); #endif NotifyErrorUI(); return FALSE; } // XPIGUI - pause/resume icons m_pXPIGUI->hPauseIcon = (HICON)LoadImageW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDI_PAUSE), IMAGE_ICON, 16, 16, 0); if (m_pXPIGUI->hPauseIcon == NULL) { #ifdef _DEBUG pLog->Write(LOG_WF_ERROR, L"Couldn't load pause icon, aborting. [LE=0x%08X]", GetLastError()); #endif NotifyErrorUI(); return FALSE; } Static_SetIcon(GetDlgItem(m_hDialog, IDC_PAUSELOGGING), m_pXPIGUI->hPauseIcon); m_pXPIGUI->hResumeIcon = (HICON)LoadImageW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDI_RESUME), IMAGE_ICON, 16, 16, 0); if (m_pXPIGUI->hResumeIcon == NULL) { #ifdef _DEBUG pLog->Write(LOG_WF_ERROR, L"Couldn't load resume icon, aborting. [LE=0x%08X]", GetLastError()); #endif NotifyErrorUI(); return FALSE; } RECT rcClient; GetClientRect(m_hDialog, &rcClient); SetWindowPos(GetDlgItem(m_hDialog, IDC_PAUSELOGGING), NULL, rcClient.right - rcClient.left - UI_PAUSE_WIDTH - UI_PAUSE_PADDING, UI_PAUSE_PADDING, UI_PAUSE_WIDTH, UI_PAUSE_HEIGHT, 0); // XPIGUI - clear packets icon m_pXPIGUI->hClearIcon = (HICON)LoadImageW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDI_CLEAR), IMAGE_ICON, 16, 16, 0); if (m_pXPIGUI->hClearIcon == NULL) { #ifdef _DEBUG pLog->Write(LOG_WF_ERROR, L"Couldn't load clear icon, aborting. [LE=0x%08X]", GetLastError()); #endif NotifyErrorUI(); return FALSE; } Static_SetIcon(GetDlgItem(m_hDialog, IDC_CLEAR), m_pXPIGUI->hClearIcon); SetWindowPos(GetDlgItem(m_hDialog, IDC_CLEAR), NULL, rcClient.right - rcClient.left - UI_CLEAR_WIDTH - (UI_CLEAR_PADDING * 2) - UI_PAUSE_WIDTH, UI_CLEAR_PADDING, UI_CLEAR_WIDTH, UI_CLEAR_HEIGHT, 0); // XPIGUI - settings image list do { m_pXPIGUI->hSettingsImageList = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 4, 0); ImageList_SetBkColor(m_pXPIGUI->hSettingsImageList, CLR_NONE); if (m_pXPIGUI->hSettingsImageList != NULL) { HBITMAP hBitmap = LoadBitmapW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDB_PACKET_STATES)); if (hBitmap != NULL) { if (ImageList_AddMasked(m_pXPIGUI->hSettingsImageList, hBitmap, RGB(255, 0, 255)) != -1) break; DeleteObject((HGDIOBJ)hBitmap); } } #ifdef _DEBUG pLog->Write(LOG_WF_ERROR, L"Couldn't create settings image-list, aborting."); #endif NotifyErrorUI(); return FALSE; } while (0); // XPIGUI - color icons for (INT i = 0; i < _countof(m_pXPIGUI->hColorIcon); i++) { HICON hTempIcon = LoadIcon(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(g_XPIColors[i].wIcon)); m_pXPIGUI->hColorIcon[i] = MenuBitmapFromIcon(m_hDialog, hTempIcon, 16, 16); if (m_pXPIGUI->hColorIcon[i] == NULL) { #ifdef _DEBUG pLog->Write(LOG_WF_ERROR, L"Couldn't load color icon #%d, aborting. [LE=0x%08X]", i, GetLastError()); #endif NotifyErrorUI(); return FALSE; } DestroyIcon(hTempIcon); } // XPIGUI - formatted image list do { m_pXPIGUI->hFormattedImageList = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 4, 0); if (m_pXPIGUI->hFormattedImageList != NULL) { ImageList_SetBkColor(m_pXPIGUI->hFormattedImageList, CLR_NONE); HBITMAP hBitmap = LoadBitmapW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDB_FORMATTED_LIST)); if (hBitmap != NULL) { if (ImageList_AddMasked(m_pXPIGUI->hFormattedImageList, hBitmap, RGB(255, 0, 255)) != -1) break; DeleteObject((HGDIOBJ)hBitmap); } } #ifdef _DEBUG pLog->Write(LOG_WF_ERROR, L"Couldn't create formatted image-list, aborting."); #endif NotifyErrorUI(); return FALSE; } while (0); // XPIGUI - stop icon m_pXPIGUI->hStop = (HICON)LoadImageW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDI_STOP), IMAGE_ICON, 16, 16, 0); if (m_pXPIGUI->hStop == NULL) { #ifdef _DEBUG pLog->Write(LOG_WF_ERROR, L"Couldn't load stop icon, aborting. [LE=0x%08X]", GetLastError()); #endif NotifyErrorUI(); return FALSE; } // shell notify icon ZeroMemory(&m_NotifyIconData, sizeof(m_NotifyIconData)); m_NotifyIconData.cbSize = sizeof(m_NotifyIconData); m_NotifyIconData.hWnd = m_hDialog; m_NotifyIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; m_NotifyIconData.hIcon = m_pXPIGUI->hIconSmall; m_NotifyIconData.uCallbackMessage = WM_SHELLNOTIFY; if (FAILED(StringCchCopyW(m_NotifyIconData.szTip, _countof(m_NotifyIconData.szTip), pStrings->Get(IDS_XPI).c_str()))) m_NotifyIconData.uFlags &= ~NIF_TIP; Shell_NotifyIconW(NIM_ADD, &m_NotifyIconData); // tooltips window (for icons) m_hIconTips = CreateWindowEx(0, TOOLTIPS_CLASS, L"", TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, m_hDialog, 0, m_pXPIGUI->hInstance, NULL); SetWindowPos(m_hIconTips, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); TOOLINFO ti; ti.cbSize = sizeof(ti); ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND; ti.hwnd = m_hDialog; std::wstring wstrTemp; wstrTemp = pStrings->Get(IDS_CLEAR_ALL_PACKETS); ti.uId = (UINT_PTR)GetDlgItem(m_hDialog, IDC_CLEAR); ti.lpszText = (LPWSTR)wstrTemp.c_str(); SendMessage(m_hIconTips, TTM_ADDTOOL, 0, (LPARAM)&ti); wstrTemp = pStrings->Get(IDS_PAUSE_LOGGING); ti.uId = (UINT_PTR)GetDlgItem(m_hDialog, IDC_PAUSELOGGING); ti.lpszText = (LPWSTR)wstrTemp.c_str(); SendMessage(m_hIconTips, TTM_ADDTOOL, 0, (LPARAM)&ti); // tabs creation TAB_INFO Tabs[] = { { pStrings->Get(IDS_TAB_PLAIN), MAKEINTRESOURCEW(IDD_PLAINVIEW), CPlainView::DialogProc }, { pStrings->Get(IDS_TAB_FORMATTED), MAKEINTRESOURCEW(IDD_FORMATTEDVIEW), CFormattedView::DialogProc }, { pStrings->Get(IDS_TAB_SETTINGS), MAKEINTRESOURCEW(IDD_SETTINGS), CMainSettings::DialogProc } }; INT iCount = 0; foreach(const TAB_INFO& i, Tabs) { HWND hWnd = CreateDialogParamW(m_pXPIGUI->hInstance, i.lpwszTemplate, m_hDialog, i.DlgProc, (LPARAM)m_pXPIGUI); if (hWnd != NULL) { TCITEMW tci; tci.mask = TCIF_TEXT | TCIF_PARAM; tci.pszText = (LPWSTR)i.wstrCaption.c_str(); tci.lParam = (LPARAM)m_pXPIGUI; if (TabCtrl_InsertItem(GetDlgItem(m_hDialog, IDC_TAB), iCount++, &tci) != -1) { ShowWindow(hWnd, m_vhTabs.empty() ? SW_SHOW : SW_HIDE); m_vhTabs.push_back(hWnd); continue; } } #ifdef _DEBUG pLog->Write(LOG_WF_ERROR, L"Couldn't create tab ID %s, aborting.", i.wstrCaption); #endif NotifyErrorUI(); return FALSE; }
/* * We use our own MessageBox for notifications to have greater control (center, no close button, etc) */ INT_PTR CALLBACK notification_callback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { LRESULT loc; int i; // Prevent resizing static LRESULT disabled[9] = { HTLEFT, HTRIGHT, HTTOP, HTBOTTOM, HTSIZE, HTTOPLEFT, HTTOPRIGHT, HTBOTTOMLEFT, HTBOTTOMRIGHT }; static HBRUSH white_brush, separator_brush; switch (message) { case WM_INITDIALOG: white_brush = CreateSolidBrush(WHITE); separator_brush = CreateSolidBrush(SEPARATOR_GREY); set_title_bar_icon(hDlg); center_dialog(hDlg); // Change the default icon if (Static_SetIcon(GetDlgItem(hDlg, IDC_NOTIFICATION_ICON), hMessageIcon) == 0) { dprintf("Could not set dialog icon\n"); } // Set the dialog title if (szMessageTitle != NULL) { SetWindowTextU(hDlg, szMessageTitle); } // Enable/disable the buttons and set text if (!notification_is_question) { SetWindowTextU(GetDlgItem(hDlg, IDNO), "Close"); } else { ShowWindow(GetDlgItem(hDlg, IDYES), SW_SHOW); } if ((notification_more_info != NULL) && (notification_more_info->callback != NULL)) { ShowWindow(GetDlgItem(hDlg, IDC_MORE_INFO), SW_SHOW); } // Set the control text if (szMessageText != NULL) { SetWindowTextU(GetDlgItem(hDlg, IDC_NOTIFICATION_TEXT), szMessageText); } return (INT_PTR)TRUE; case WM_CTLCOLORSTATIC: // Change the background colour for static text and icon SetBkMode((HDC)wParam, TRANSPARENT); if ((HWND)lParam == GetDlgItem(hDlg, IDC_NOTIFICATION_LINE)) { return (INT_PTR)separator_brush; } return (INT_PTR)white_brush; case WM_NCHITTEST: // Check coordinates to prevent resize actions loc = DefWindowProc(hDlg, message, wParam, lParam); for(i = 0; i < 9; i++) { if (loc == disabled[i]) { return (INT_PTR)TRUE; } } return (INT_PTR)FALSE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: case IDCANCEL: case IDYES: case IDNO: EndDialog(hDlg, LOWORD(wParam)); return (INT_PTR)TRUE; case IDC_MORE_INFO: if (notification_more_info != NULL) DialogBoxW(main_instance, MAKEINTRESOURCEW(notification_more_info->id), hDlg, notification_more_info->callback); break; } break; } return (INT_PTR)FALSE; }
/* * We use our own MessageBox for notifications to have greater control (center, no close button, etc) */ INT_PTR CALLBACK NotificationCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { LRESULT loc; int i; // Prevent resizing static LRESULT disabled[9] = { HTLEFT, HTRIGHT, HTTOP, HTBOTTOM, HTSIZE, HTTOPLEFT, HTTOPRIGHT, HTBOTTOMLEFT, HTBOTTOMRIGHT }; static HBRUSH background_brush, separator_brush; // To use the system message font NONCLIENTMETRICS ncm; HFONT hDlgFont; switch (message) { case WM_INITDIALOG: // Get the system message box font. See http://stackoverflow.com/a/6057761 ncm.cbSize = sizeof(ncm); // If we're compiling with the Vista SDK or later, the NONCLIENTMETRICS struct // will be the wrong size for previous versions, so we need to adjust it. #if defined(_MSC_VER) && (_MSC_VER >= 1500) && (_WIN32_WINNT >= _WIN32_WINNT_VISTA) if (nWindowsVersion >= WINDOWS_VISTA) { // In versions of Windows prior to Vista, the iPaddedBorderWidth member // is not present, so we need to subtract its size from cbSize. ncm.cbSize -= sizeof(ncm.iPaddedBorderWidth); } #endif SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0); hDlgFont = CreateFontIndirect(&(ncm.lfMessageFont)); // Set the dialog to use the system message box font SendMessage(hDlg, WM_SETFONT, (WPARAM)hDlgFont, MAKELPARAM(TRUE, 0)); SendMessage(GetDlgItem(hDlg, IDC_NOTIFICATION_TEXT), WM_SETFONT, (WPARAM)hDlgFont, MAKELPARAM(TRUE, 0)); SendMessage(GetDlgItem(hDlg, IDC_MORE_INFO), WM_SETFONT, (WPARAM)hDlgFont, MAKELPARAM(TRUE, 0)); SendMessage(GetDlgItem(hDlg, IDYES), WM_SETFONT, (WPARAM)hDlgFont, MAKELPARAM(TRUE, 0)); SendMessage(GetDlgItem(hDlg, IDNO), WM_SETFONT, (WPARAM)hDlgFont, MAKELPARAM(TRUE, 0)); apply_localization(IDD_NOTIFICATION, hDlg); background_brush = CreateSolidBrush(GetSysColor(COLOR_3DHILIGHT)); separator_brush = CreateSolidBrush(GetSysColor(COLOR_3DLIGHT)); SetTitleBarIcon(hDlg); CenterDialog(hDlg); // Change the default icon if (Static_SetIcon(GetDlgItem(hDlg, IDC_NOTIFICATION_ICON), hMessageIcon) == 0) { uprintf("Could not set dialog icon\n"); } // Set the dialog title if (szMessageTitle != NULL) { SetWindowTextU(hDlg, szMessageTitle); } // Enable/disable the buttons and set text if (!notification_is_question) { SetWindowTextU(GetDlgItem(hDlg, IDNO), lmprintf(MSG_006)); } else { ShowWindow(GetDlgItem(hDlg, IDYES), SW_SHOW); } if ((notification_more_info != NULL) && (notification_more_info->callback != NULL)) { ShowWindow(GetDlgItem(hDlg, IDC_MORE_INFO), SW_SHOW); } // Set the control text if (szMessageText != NULL) { SetWindowTextU(GetDlgItem(hDlg, IDC_NOTIFICATION_TEXT), szMessageText); } return (INT_PTR)TRUE; case WM_CTLCOLORSTATIC: // Change the background colour for static text and icon SetBkMode((HDC)wParam, TRANSPARENT); if ((HWND)lParam == GetDlgItem(hDlg, IDC_NOTIFICATION_LINE)) { return (INT_PTR)separator_brush; } return (INT_PTR)background_brush; case WM_NCHITTEST: // Check coordinates to prevent resize actions loc = DefWindowProc(hDlg, message, wParam, lParam); for(i = 0; i < 9; i++) { if (loc == disabled[i]) { return (INT_PTR)TRUE; } } return (INT_PTR)FALSE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: case IDCANCEL: case IDYES: case IDNO: EndDialog(hDlg, LOWORD(wParam)); return (INT_PTR)TRUE; case IDC_MORE_INFO: if (notification_more_info != NULL) DialogBoxW(hMainInstance, MAKEINTRESOURCEW(notification_more_info->id), hDlg, notification_more_info->callback); break; } break; } return (INT_PTR)FALSE; }
/* * ClientMsgBoxProc: A substitute implementation of MessageBox's window procedure. * We have 2 OK buttons and 2 Cancel buttons, to account for the case where one * or the other is the default button. We hide the buttons we don't need. */ BOOL CALLBACK ClientMsgBoxProc(HWND hDlg, UINT message, UINT wParam, LONG lParam) { static MsgBoxStruct *s; char *icon = NULL, *temp; int style, button_style, num_lines, yincrease; HICON hIcon; HWND hEdit, hText; HWND hOK, hCancel, hOK2, hCancel2; HFONT hFont; RECT dlg_rect, edit_rect; switch (message) { case WM_ACTIVATE: CenterWindow(hDlg, GetParent(hDlg)); break; case WM_SETFOCUS: case WM_WINDOWPOSCHANGING: SetFocus(hDlg); break; case WM_INITDIALOG: s = (MsgBoxStruct *) lParam; button_style = s->style & MB_TYPEMASK; hText = GetDlgItem(hDlg, IDC_TEXT); hOK = GetDlgItem(hDlg, IDOK); hCancel = GetDlgItem(hDlg, IDCANCEL); hOK2 = GetDlgItem(hDlg, IDOK2); hCancel2 = GetDlgItem(hDlg, IDCANCEL2); // Display text // Put text in invisible edit box to see how much space it will take hEdit = GetDlgItem(hDlg, IDC_EDIT); hFont = GetWindowFont(hText); SetWindowFont(hEdit, hFont, TRUE); SetWindowFont(hOK, hFont, FALSE); SetWindowFont(hCancel, hFont, FALSE); SetWindowFont(hOK2, hFont, FALSE); SetWindowFont(hCancel2, hFont, FALSE); SetWindowText(hEdit, s->text); Edit_GetRect(hEdit, &edit_rect); num_lines = Edit_GetLineCount(hEdit); // Count blank lines separately, since edit box not handling them correctly temp = s->text; do { temp = strstr(temp, "\n\n"); if (temp != NULL) { num_lines++; temp += 2; } } while (temp != NULL); yincrease = GetFontHeight(hFont) * num_lines; // Resize dialog and text area GetWindowRect(hDlg, &dlg_rect); MoveWindow(hDlg, dlg_rect.left, dlg_rect.top, dlg_rect.right - dlg_rect.left, dlg_rect.bottom - dlg_rect.top + yincrease, FALSE); ResizeDialogItem(hDlg, hText, &dlg_rect, RDI_ALL, False); // Move buttons; center OK button if it's the only one if (button_style == MB_OK) { ResizeDialogItem(hDlg, hOK, &dlg_rect, RDI_BOTTOM | RDI_HCENTER, False); ShowWindow(hCancel, SW_HIDE); ShowWindow(hCancel2, SW_HIDE); } else { ResizeDialogItem(hDlg, hOK, &dlg_rect, RDI_BOTTOM, False); ResizeDialogItem(hDlg, hCancel, &dlg_rect, RDI_BOTTOM, False); ResizeDialogItem(hDlg, hOK2, &dlg_rect, RDI_BOTTOM, False); ResizeDialogItem(hDlg, hCancel2, &dlg_rect, RDI_BOTTOM, False); } SetWindowText(hDlg, s->title); SetWindowText(hText, s->text); ShowWindow(hEdit, SW_HIDE); // Set icon to appropriate system icon style = s->style & MB_ICONMASK; if (style == MB_ICONSTOP) icon = IDI_HAND; else if (style == MB_ICONINFORMATION) icon = IDI_ASTERISK; else if (style == MB_ICONEXCLAMATION) icon = IDI_EXCLAMATION; else if (style == MB_ICONQUESTION) icon = IDI_QUESTION; if (icon != NULL) { hIcon = LoadIcon(NULL, icon); Static_SetIcon(GetDlgItem(hDlg, IDC_MSGBOXICON), hIcon); } // Display correct button text switch (button_style) { case MB_YESNO: SetWindowText(hOK, GetString(hInst, IDS_YES)); SetWindowText(hCancel, GetString(hInst, IDS_NO)); SetWindowText(hOK2, GetString(hInst, IDS_YES)); SetWindowText(hCancel2, GetString(hInst, IDS_NO)); break; } // Show correct button as default style = s->style & MB_DEFMASK; switch (style) { case MB_DEFBUTTON1: default: SetFocus(hOK); ShowWindow(hOK2, SW_HIDE); ShowWindow(hCancel, SW_HIDE); break; case MB_DEFBUTTON2: SetFocus(hCancel); ShowWindow(hOK, SW_HIDE); ShowWindow(hCancel2, SW_HIDE); break; } CenterWindow(hDlg, GetParent(hDlg)); return 0; case WM_COMMAND: switch(GET_WM_COMMAND_ID(wParam, lParam)) { case IDOK: case IDOK2: button_style = s->style & MB_TYPEMASK; if (button_style == MB_YESNO) EndDialog(hDlg, IDYES); else EndDialog(hDlg, IDOK); return TRUE; case IDCANCEL: case IDCANCEL2: button_style = s->style & MB_TYPEMASK; if (button_style == MB_YESNO) EndDialog(hDlg, IDNO); else EndDialog(hDlg, IDCANCEL); return TRUE; } break; } return FALSE; }
void InitRunDlg(HWND hDlg, LPRUNDLG_DATA lprd) { HWND hCB; int i; #ifdef WINNT HANDLE hThread = NULL; DWORD dwDummy; #endif if (lprd->lpszTitle) SetWindowText(hDlg, lprd->lpszTitle); if (lprd->lpszPrompt) { SetDlgItemText(hDlg, IDD_PROMPT, lprd->lpszPrompt); } if (lprd->hIcon) { Static_SetIcon(GetDlgItem(hDlg, IDD_ICON), lprd->hIcon); } if (lprd->dwFlags & RFD_NOBROWSE) { HWND hBrowse; hBrowse = GetDlgItem(hDlg, IDD_BROWSE); ExchangeWindowPos(hBrowse, GetDlgItem(hDlg, IDCANCEL)); ExchangeWindowPos(hBrowse, GetDlgItem(hDlg, IDOK)); ShowWindow(hBrowse, SW_HIDE); } if (lprd->dwFlags & RFD_NOSHOWOPEN) { ShowWindow(GetDlgItem(hDlg, IDD_RUNDLGOPENPROMPT), SW_HIDE); } #ifdef SHOWSTATES /* Note that we need to fill this list first so that the SELCHANGE * message sent below will do the right thing. */ hCB = GetDlgItem(hDlg, IDD_STATE); for (i = 0; i < ARRAYSIZE(pnStates); ++i) { if (SendMessage(hCB, CB_ADDSTRING, 0, (LPARAM)(LPTSTR)szStates[i]) < 0) { break; } } SendMessage(hCB, CB_SETCURSEL, 0, 0L); #endif hCB = GetDlgItem(hDlg, IDD_COMMAND); SendMessage(hCB, CB_LIMITTEXT, MAX_PATH-1, 0L); OpenRunDlgMRU(); if (g_hMRURunDlg) { int nMax; TCHAR szCommand[MAX_PATH]; for (nMax=EnumMRUList(g_hMRURunDlg, -1, NULL, 0), i=0; i<nMax; ++i) { if (EnumMRUList(g_hMRURunDlg, i, szCommand, ARRAYSIZE(szCommand)) > 0) { PSTARTINFO pStartInfo; /* Parse the line into the STARTINFO struct */ pStartInfo = ParseIniLine(szCommand); /* The command to run goes in the combobox. */ if (SendMessage(hCB, CB_ADDSTRING, 0, (LPARAM)(LPTSTR)szCommand) != i) { if (pStartInfo) { LocalFree((HLOCAL)pStartInfo); } } else { SendMessage(hCB, CB_SETITEMDATA, i, (LPARAM)(LPSTARTINFO)pStartInfo); } } } } if (!(lprd->dwFlags & RFD_NODEFFILE)) { SendMessage(hCB, CB_SETCURSEL, 0, 0L); } SendMessage(hDlg, WM_COMMAND, MAKEWPARAM(IDD_COMMAND, CBN_SELCHANGE), (LPARAM) hCB); SetWindowLong(hDlg, DWL_USER, (LONG)lprd); // Make sure the OK button is initialized properly EnableOKButton(hDlg, NULL); #ifdef WINNT // // Create the thread that will take care of the // "Run in Separate Memory Space" checkbox in the background. // if (lprd->dwFlags & RFD_NOSEPMEMORY_BOX) { ShowWindow(GetDlgItem(hDlg, IDD_RUNINSEPARATE), SW_HIDE); } else { Assert( g_hCheckNow==NULL ); g_hCheckNow = CreateEvent( NULL, TRUE, FALSE, NULL ); if (g_hCheckNow) { g_bCheckRunInSep = TRUE; hThread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)CheckRunInSeparateThread, (LPVOID)hDlg, 0, &dwDummy ); } if ((g_hCheckNow==NULL) || (!g_bCheckRunInSep) || (hThread==NULL)) { // // We've encountered a problem setting up, so make the user // choose. // CheckDlgButton( hDlg, IDD_RUNINSEPARATE, 1 ); EnableWindow( GetDlgItem( hDlg, IDD_RUNINSEPARATE ), TRUE ); g_bCheckRunInSep = FALSE; } // // These calls will just do nothing if either handle is NULL. // if (hThread) CloseHandle( hThread ); if (g_hCheckNow) SetEvent( g_hCheckNow ); } #endif // WINNT }