@@ -40,6 +40,14 @@ public enum keyState
4040 EXTENDEDKEY = 1 ,
4141 KEYUP = 2
4242 } ;
43+ private enum ShowWindowEnum
44+ {
45+ Hide = 0 ,
46+ ShowNormal = 1 , ShowMinimized = 2 , ShowMaximized = 3 ,
47+ Maximize = 3 , ShowNormalNoActivate = 4 , Show = 5 ,
48+ Minimize = 6 , ShowMinNoActivate = 7 , ShowNoActivate = 8 ,
49+ Restore = 9 , ShowDefault = 10 , ForceMinimized = 11
50+ } ;
4351
4452 [ DllImport ( "user32.dll" , EntryPoint = "FindWindow" ) ]
4553 private static extern IntPtr FindWindow ( string lpClassName , string lpWindowName ) ;
@@ -71,15 +79,20 @@ public enum keyState
7179 [ DllImport ( "user32.dll" ) ]
7280 public static extern bool UnregisterHotKey ( IntPtr hWnd , int id ) ;
7381
82+ [ DllImport ( "user32.dll" ) ]
83+ private static extern bool IsIconic ( IntPtr hWnd ) ;
84+
85+ [ DllImport ( "user32.dll" ) ]
86+ static extern bool ShowWindow ( IntPtr hWnd , ShowWindowEnum flags ) ;
87+
7488 private const uint WM_LBUTTONDOWN = 513 ;
7589 private const uint WM_LBUTTONUP = 514 ;
7690
7791 private const uint WM_RBUTTONDOWN = 516 ;
7892 private const uint WM_RBUTTONUP = 517 ;
7993
80- public static Rectangle GetWowRectangle ( )
94+ public static Rectangle GetWowRectangle ( IntPtr Wow )
8195 {
82- IntPtr Wow = FindWindow ( "GxWindowClass" , "World Of Warcraft" ) ;
8396 Rect Win32ApiRect = new Rect ( ) ;
8497 GetWindowRect ( Wow , ref Win32ApiRect ) ;
8598 Rectangle myRect = new Rectangle ( ) ;
@@ -90,6 +103,19 @@ public static Rectangle GetWowRectangle()
90103 return myRect ;
91104 }
92105
106+ public static IntPtr FindWowWindow ( )
107+ {
108+ Process [ ] processlist = Process . GetProcesses ( ) ;
109+ foreach ( Process process in processlist )
110+ {
111+ if ( process . MainWindowTitle . ToUpper ( ) . Equals ( "WORLD OF WARCRAFT" ) )
112+ {
113+ return process . MainWindowHandle ;
114+ }
115+ }
116+ return new IntPtr ( ) ;
117+ }
118+
93119 public static Bitmap GetCursorIcon ( CursorInfo actualCursor , int width = 35 , int height = 35 )
94120 {
95121 Bitmap actualCursorIcon = null ;
@@ -106,20 +132,19 @@ public static Bitmap GetCursorIcon(CursorInfo actualCursor, int width = 35, int
106132 return actualCursorIcon ;
107133 }
108134
109- static public void ActivateWow ( )
135+ static public void ActivateWow ( IntPtr Wow )
110136 {
111- ActivateApp ( Properties . Settings . Default . ProcName ) ;
112- ActivateApp ( Properties . Settings . Default . ProcName + "-64" ) ;
113- ActivateApp ( "World Of Warcraft" ) ;
137+ ActivateApp ( Wow ) ;
114138 }
115139
116- static public void ActivateApp ( string processName )
140+ public static void ActivateApp ( IntPtr Wow )
117141 {
118- Process [ ] p = Process . GetProcessesByName ( processName ) ;
119-
120- // Activate the first application we find with this name
121- if ( p . Count ( ) > 0 )
122- SetForegroundWindow ( p [ 0 ] . MainWindowHandle ) ;
142+ SetForegroundWindow ( Wow ) ;
143+ //AllowSetForegroundWindow(Process.GetCurrentProcess().Id);
144+ if ( IsIconic ( Wow ) )
145+ {
146+ ShowWindow ( Wow , ShowWindowEnum . Restore ) ;
147+ }
123148 }
124149
125150 public static void MoveMouse ( int x , int y )
@@ -131,9 +156,9 @@ public static void MoveMouse(int x, int y)
131156 }
132157 }
133158
134- public static CursorInfo GetNoFishCursor ( )
159+ public static CursorInfo GetNoFishCursor ( IntPtr Wow )
135160 {
136- Rectangle WoWRect = Win32 . GetWowRectangle ( ) ;
161+ Rectangle WoWRect = Win32 . GetWowRectangle ( Wow ) ;
137162 Win32 . MoveMouse ( ( WoWRect . X + 10 ) , ( WoWRect . Y + 45 ) ) ;
138163 LastRectX = WoWRect . X ;
139164 LastRectY = WoWRect . Y ;
@@ -167,7 +192,7 @@ public static void SendKey(string sKeys)
167192
168193 public static void SendMouseClick ( )
169194 {
170- IntPtr Wow = FindWindow ( "GxWindowClass" , "World Of Warcraft" ) ;
195+ IntPtr Wow = FindWowWindow ( ) ;
171196 long dWord = MakeDWord ( ( LastX - LastRectX ) , ( LastY - LastRectY ) ) ;
172197
173198 if ( Properties . Settings . Default . ShiftLoot )
@@ -181,6 +206,34 @@ public static void SendMouseClick()
181206 SendKeyboardAction ( 16 , keyState . KEYUP ) ;
182207 }
183208
209+ public static void SendMouseClick ( IntPtr Wow )
210+ {
211+ long dWord = MakeDWord ( ( LastX - LastRectX ) , ( LastY - LastRectY ) ) ;
212+
213+ if ( Properties . Settings . Default . ShiftLoot )
214+ SendKeyboardAction ( 16 , keyState . KEYDOWN ) ;
215+
216+ SendNotifyMessage ( Wow , WM_RBUTTONDOWN , ( UIntPtr ) 1 , ( IntPtr ) dWord ) ;
217+ Thread . Sleep ( 100 ) ;
218+ SendNotifyMessage ( Wow , WM_RBUTTONUP , ( UIntPtr ) 1 , ( IntPtr ) dWord ) ;
219+
220+ if ( Properties . Settings . Default . ShiftLoot )
221+ SendKeyboardAction ( 16 , keyState . KEYUP ) ;
222+ }
223+ public static void SendMouseDblRightClick ( IntPtr Wow )
224+ {
225+ //long dWord = MakeDWord((LastX - LastRectX), (LastY - LastRectY));
226+ Rectangle wowRect = Win32 . GetWowRectangle ( Wow ) ;
227+ long dWord = MakeDWord ( ( wowRect . Width / 2 ) , ( wowRect . Height / 2 ) ) ;
228+ SendNotifyMessage ( Wow , WM_RBUTTONDOWN , ( UIntPtr ) 1 , ( IntPtr ) dWord ) ;
229+ Thread . Sleep ( 100 ) ;
230+ SendNotifyMessage ( Wow , WM_RBUTTONUP , ( UIntPtr ) 1 , ( IntPtr ) dWord ) ;
231+ Thread . Sleep ( 100 ) ;
232+ SendNotifyMessage ( Wow , WM_RBUTTONDOWN , ( UIntPtr ) 1 , ( IntPtr ) dWord ) ;
233+ Thread . Sleep ( 100 ) ;
234+ SendNotifyMessage ( Wow , WM_RBUTTONUP , ( UIntPtr ) 1 , ( IntPtr ) dWord ) ;
235+ }
236+
184237 public static bool SendKeyboardAction ( Keys key , keyState state )
185238 {
186239 return SendKeyboardAction ( ( byte ) key . GetHashCode ( ) , state ) ;
@@ -196,10 +249,10 @@ private static long MakeDWord(int LoWord, int HiWord)
196249 return ( HiWord << 16 ) | ( LoWord & 0xFFFF ) ;
197250 }
198251
199- static private int LastRectX ;
200- static private int LastRectY ;
252+ private static int LastRectX ;
253+ private static int LastRectY ;
201254
202- static private int LastX ;
203- static private int LastY ;
255+ private static int LastX ;
256+ private static int LastY ;
204257 }
205258}
0 commit comments