func newFontFromLOGFONT(lf *win.LOGFONT, dpi int) (*Font, error) { if lf == nil { return nil, newError("lf cannot be nil") } family := win.UTF16PtrToString(&lf.LfFaceName[0]) pointSize := int(win.MulDiv(lf.LfHeight, 72, int32(dpi))) if pointSize < 0 { pointSize = -pointSize } var style FontStyle if lf.LfWeight > win.FW_NORMAL { style |= FontBold } if lf.LfItalic == win.TRUE { style |= FontItalic } if lf.LfUnderline == win.TRUE { style |= FontUnderline } if lf.LfStrikeOut == win.TRUE { style |= FontStrikeOut } return NewFont(family, pointSize, style) }
func (tt *ToolTip) Text(tool Widget) string { ti := tt.toolInfo(tool) if ti == nil { return "" } return win.UTF16PtrToString(ti.LpszText) }
// Text returns the current text data of the clipboard. func (c *ClipboardService) Text() (text string, err error) { err = c.withOpenClipboard(func() error { hMem := win.HGLOBAL(win.GetClipboardData(win.CF_UNICODETEXT)) if hMem == 0 { return lastError("GetClipboardData") } p := win.GlobalLock(hMem) if p == nil { return lastError("GlobalLock()") } defer win.GlobalUnlock(hMem) text = win.UTF16PtrToString((*uint16)(p)) return nil }) return }
func (m *Win_PerfCounters) Gather(acc telegraf.Accumulator) error { metrics := itemList{} // Both values are empty in normal use. if m.TestName != testObject { // Cleanup any handles before emptying the global variable containing valid queries. m.CleanupTestMode() gItemList = make(map[int]*item) testObject = m.TestName testConfigParsed = true configParsed = false } // We only need to parse the config during the init, it uses the global variable after. if configParsed == false { err := m.ParseConfig(&metrics) if err != nil { return err } } var bufSize uint32 var bufCount uint32 var size uint32 = uint32(unsafe.Sizeof(win.PDH_FMT_COUNTERVALUE_ITEM_DOUBLE{})) var emptyBuf [1]win.PDH_FMT_COUNTERVALUE_ITEM_DOUBLE // need at least 1 addressable null ptr. // For iterate over the known metrics and get the samples. for _, metric := range gItemList { // collect ret := win.PdhCollectQueryData(metric.handle) if ret == win.ERROR_SUCCESS { ret = win.PdhGetFormattedCounterArrayDouble(metric.counterHandle, &bufSize, &bufCount, &emptyBuf[0]) // uses null ptr here according to MSDN. if ret == win.PDH_MORE_DATA { filledBuf := make([]win.PDH_FMT_COUNTERVALUE_ITEM_DOUBLE, bufCount*size) ret = win.PdhGetFormattedCounterArrayDouble(metric.counterHandle, &bufSize, &bufCount, &filledBuf[0]) for i := 0; i < int(bufCount); i++ { c := filledBuf[i] var s string = win.UTF16PtrToString(c.SzName) var add bool if metric.include_total { // If IncludeTotal is set, include all. add = true } else if metric.instance == "*" && !strings.Contains(s, "_Total") { // Catch if set to * and that it is not a '*_Total*' instance. add = true } else if metric.instance == s { // Catch if we set it to total or some form of it add = true } else if metric.instance == "------" { add = true } if add { fields := make(map[string]interface{}) tags := make(map[string]string) if s != "" { tags["instance"] = s } tags["objectname"] = metric.objectName fields[string(metric.counter)] = float32(c.FmtValue.DoubleValue) var measurement string if metric.measurement == "" { measurement = "win_perf_counters" } else { measurement = metric.measurement } acc.AddFields(measurement, fields, tags) } } filledBuf = nil // Need to at least set bufSize to zero, because if not, the function will not // return PDH_MORE_DATA and will not set the bufSize. bufCount = 0 bufSize = 0 } } } return nil }