Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Performance Tuning
#1
Shocked 
So I have this macro who's main job is to show me the date time and the number of unread messages in my Outlook window.  But, when it's running it forces both QM and Outlook to use 10% and 30% cpu respectively.  

What am I doing wrong here to make it so inefficient?   Any thoughts would be most appreciated.



Function OSD_clock
Code:
Copy      Help
;shows clock in middle of specified monitor
_monitor=0
out
int z hidn clpbd w
str s clpbds value
Acc a
rep
,s.time("%X   %d - %a")
,s.from("  " s " ")
,err-
,w=win("* - kgray@merkleinc.com - Outlook" "rctrl_renwnd32" "" 0x1)
,a.Find(w "OUTLINEITEM" "Inbox*" "class=NetUIHWND" 0x1005)
,value=a.Name
,err+
,,value="Outlook not connected"
,if len(value)>0
,,value.replacerx("[^\d]" "")
,s.from(s "   " value)
,hidn= hid(win("tim4924" "QM_OSD_Class_Rd" "qm"))
,err
,if hidn=0
,,OnScreenDisplay s -1 675 -2 "Copperplate Gothic Bold" 14 0x00ffff 25|0x8000 "tim4924" 0x343434
,0.1
An old blog on QM coding and automation.

The Macro Hook
#2
Finding accessible objects often is slow. In this case, a.Find time 50-100 ms is normal.
The first thing what you can do is wait longer, for example 1 s instead of 0.1.
Next, try to make a.Find faster. Try "Reverse" flag. Try to split into two: at first find the parent OUTLINE object (if possible, before the rep loop), then find the OUTLINEITEM in it.
#3
thanks.

I'm wondering, does anyone know how to get an unread count in the Inbox directly from Outlook? That may solve it in a better way.
An old blog on QM coding and automation.

The Macro Hook
#4
Here's what I'm using for getting the unread count.  powershell + qm

Macro Macro6
Code:
Copy      Help
out
lpstr ps=
;$outlook = new-object -com Outlook.Application
;$session = $outlook.Session
;$session.Logon()
;$inbox = $outlook.session.GetDefaultFolder(6)
;$unreadCount = (%{$inbox.Items | where {$_.UnRead}}).Count
;$unreadCount

PsCmd(ps "" _s)
str a.getl(_s 1)
out a
An old blog on QM coding and automation.

The Macro Hook
#5
Hi Ken,
I based this code on this snippet from: http://www.freevbcode.com/ShowCode.asp?ID=1469

Macro GetUnreadMessagesInInboxVBA
Code:
Copy      Help
typelib Outlook {00062FFF-0000-0000-C000-000000000046} 9
Outlook.Application oOutlook._getactive
Outlook.NameSpace oNS
Outlook.MAPIFolder oFldr
oNS = oOutlook.GetNamespace("MAPI")
oFldr = oNS.GetDefaultFolder(olFolderInbox)
;;;;MAPIFolder  GetDefaultFolder(FolderType)   ;;FolderType: olFolderDeletedItems olFolderOutbox olFolderSentMail olFolderInbox olFolderCalendar olFolderContacts olFolderJournal olFolderNotes olFolderTasks olFolderDrafts olPublicFoldersAllPublicFolders olFolderConflicts olFolderSyncIssues olFolderLocalFailures olFolderServerFailures olFolderJunk olFolderRssFeeds olFolderToDo olFolderManagedEmail olFolderSuggestedContacts
int UnreadMessagesInInbox = oFldr.UnReadItemCount
mes F"UnreadMessagesInInbox = {UnreadMessagesInInbox}"
Hopefully this works for you - I used the TypeLibrary Search to get the declaration.
S
#6
Hey S,

Not sure if this worked for Ken but this definitely worked for me. Great find!
#7
Thanks BJ. Haven't heard from Ken yet  Big Grin but glad it did the trick for you. Kind of opens up a new world doesn't it - having access to all those solutions out there but do-able within QM.
S


Forum Jump:


Users browsing this thread: 2 Guest(s)