March 05, 2021, 06:31:16 AM

Author Topic: [bmx] Task Icon in Windows by Eikon [ 1+ years ago ]  (Read 566 times)

Offline BlitzBot

[bmx] Task Icon in Windows by Eikon [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : Task Icon in Windows
Author : Eikon
Posted : 1+ years ago

Description : Thanks goes to Sarge for helping me sort this out. This also includes code to give your window a title and start it centered at any desktop resolution.

Code :
Code: BlitzMax
  1. Import "-lshell32"
  2.  
  3. Extern "win32"
  4.         Function LoadIcon(hWnd, file$z, index) = "ExtractIconA@12"
  5.         Function GetActiveWindow()
  6.         Function GetDesktopWindow()
  7.         Function GetWindowRect(hWnd, lpRect:Byte Ptr)
  8.         Function SetWindowText(hWnd, lpString$z) = "SetWindowTextA@8"
  9.         Function SetWindowPos(hWnd, after, x, y, w, h, flags)
  10.         Function GetWindowLong(hwnd, nIndex) = "GetWindowLongA@8"
  11.         Function SetWindowLong(hwnd, index, nIndex) = "SetWindowLongA@12"
  12.         Function SetClassLong(hWnd, nIndex, dwNewLong) = "SetClassLongA@12"
  13.         Function GetSystemMenu(hWnd, revert)
  14.         Function GetMenuItemCount(hMenu)
  15.         Function RemoveMenu(hMenu, position, flags)
  16. End Extern
  17.  
  18. Type lpRECT
  19.         Field l, t, r, b
  20. End Type
  21.  
  22. Const GFX_WIDTH = 320, GFX_HEIGHT = 200
  23.  
  24. Graphics GFX_WIDTH, GFX_HEIGHT, 0, -1
  25. Local hWnd% = GetActiveWindow() ' Get Window Handle
  26.  
  27. Local style = GetWindowLong(hWnd, -16)           ' Add system menu to window style
  28. SetWindowLong hWnd, -16, style + $80000 + $20000 ' so that it supports a task icon
  29.  
  30. Local hMenu = GetSystemMenu(hWnd, 0)      ' Remove close from the system
  31. Local iMenu = GetMenuItemCount(hMenu)     ' menu to disable the non-working
  32. RemoveMenu hMenu, iMenu - 1, $1000 + $400 ' close button
  33. RemoveMenu hMenu, iMenu - 2, $1000 + $400
  34.  
  35. SetWindowText hWnd, "My BlitzMax App"      ' Give it a title
  36. Local icon = LoadIcon(hWnd, "icon.ico", 0) ' Assign it an icon
  37. SetClassLong hWnd, -14, icon
  38.  
  39. Local desk_hWnd% = GetDesktopWindow(), l:lpRect = New lpRECT
  40. GetWindowRect desk_hWnd, l:lpRECT
  41.  
  42. ' Center it on-screen
  43. SetWindowPos hWnd, -2, (l.r / 2) - (GFX_WIDTH / 2), (l.b / 2) - (GFX_HEIGHT / 2), 0, 0, 1
  44. l:lpRECT = Null
  45.  
  46. Repeat; Flip; Until KeyDown(KEY_ESCAPE)


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal