Recent

Author Topic: API WND (No Taskbar Button) How can I get rid of this button ?  (Read 6833 times)

RAW

  • Hero Member
  • *****
  • Posts: 794
API WND (No Taskbar Button) How can I get rid of this button ?
« on: October 20, 2017, 07:33:01 pm »
Hi,
can anybody give me a hint how to get rid of the taskbar button ?

Code: Pascal  [Select]
  1. PROGRAM project1;
  2.  USES
  3.   Windows;
  4.  
  5.  VAR
  6.   WND: TWndClass;
  7.   MSG: TMSG;
  8.   hWndMain : THandle;
  9.   hWndPopup: THandle;
  10.  
  11.  CONST
  12.   HotKeyShow = 113000;
  13.  
  14.  Function MainProc(hWnd, MSG: LongWord; wPARAM, lPARAM: LongInt): Integer; StdCall;
  15.   Begin
  16.    If (MSG = WM_HOTKEY) And (wPARAM = HotKeyShow)
  17.    Then
  18.     Begin
  19.      ShowWindow(hWndMain, SW_SHOW);
  20.      ShowWindow(hWndPopup, SW_SHOW);
  21.      SetForegroundWindow(hWndMain);
  22.      SetForegroundWindow(hWndPopup);
  23.     End;
  24.  
  25.    Case MSG
  26.    Of
  27.     WM_Close: UnregisterHotKey(hWndMain, HotKeyShow);
  28.  
  29.     WM_DESTROY:
  30.      Begin
  31.       PostQuitMessage(0);
  32.       Exit;
  33.      End;
  34.  
  35.     WM_KEYDOWN:
  36.      Begin
  37.       If (VK_ESCAPE = wPARAM)
  38.       Then
  39.        Begin
  40.         ShowWindow(hWndMain, SW_HIDE);
  41.         ShowWindow(hWndPopup, SW_HIDE);
  42.        End;
  43.      End;
  44.  
  45.     WM_LBUTTONDOWN: MessageBox
  46.                     (hWndMain, PChar('Left Mouse Button'), PChar('MyProgram'), 0);
  47.    End;
  48.    Result:= DefWindowProc(hWnd, MSG, wPARAM, lPARAM);
  49.   End;
  50.  
  51. BEGIN
  52.  WND.lpszClassName:= 'MyWND';
  53.  WND.lpfnWndProc  := @MainProc;
  54.  WND.hInstance    := hInstance;
  55.  WND.hbrBackground:= 5;
  56.  
  57.  RegisterClass(WND);
  58.  
  59.  hWndMain:= CreateWindow
  60.  (WND.lpszClassName,'My API Window', WS_OVERLAPPEDWINDOW Or WS_VISIBLE,
  61.   500, 500, 500, 300, 0, 0, hInstance, Nil);
  62.  
  63.  hWndPopup:= CreateWindow
  64.  (WND.lpszClassName,'My Second Window', WS_EX_TOOLWINDOW Or WS_VISIBLE,
  65.   200, 500, 500, 300, hWndMain, 0, hInstance, Nil);
  66.  
  67.  If Not RegisterHotKey(hWndMain, HotKeyShow, MOD_CONTROL, VK_BACK)
  68.  Then MessageBox(hWndMain, PChar('HotKey Failed'), PChar('MyProgram'), 0);
  69.  
  70.  While GetMessage(MSG, 0, 0, 0)
  71.  Do
  72.   Begin
  73.    TranslateMessage(MSG);
  74.    DispatchMessage (MSG);
  75.   End;
  76. END.
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 2.0.4 FPC 3.0.4 - TRUNK 2.1.0 FPC 3.3.1

RAW

  • Hero Member
  • *****
  • Posts: 794
Re: API WND (No Taskbar Button) How can I get rid of this button ?
« Reply #1 on: October 20, 2017, 07:49:47 pm »
Maybe it's only possible with a hidden window ???

Code: Pascal  [Select]
  1. PROGRAM project1;
  2.  USES
  3.   Windows;
  4.  
  5.  VAR
  6.   WND: TWndClass;
  7.   MSG: TMSG;
  8.   hWndMain,
  9.   hWndPopup,
  10.   hWndHidden: THandle;
  11.  
  12.  CONST
  13.   HotKeyShow = 113000;
  14.  
  15.  Function MainProc(hWnd, MSG: LongWord; wPARAM, lPARAM: LongInt): Integer; StdCall;
  16.   Begin
  17.    If (MSG = WM_HOTKEY) And (wPARAM = HotKeyShow)
  18.    Then
  19.     Begin
  20.      ShowWindow(hWndMain, SW_SHOW);
  21.      ShowWindow(hWndPopup, SW_SHOW);
  22.      SetForegroundWindow(hWndMain);
  23.      SetForegroundWindow(hWndPopup);
  24.     End;
  25.  
  26.    Case MSG
  27.    Of
  28.     WM_Close: UnregisterHotKey(hWndMain, HotKeyShow);
  29.  
  30.     WM_DESTROY:
  31.      Begin
  32.       PostQuitMessage(0);
  33.       Exit;
  34.      End;
  35.  
  36.     WM_KEYDOWN:
  37.      Begin
  38.       If (VK_ESCAPE = wPARAM)
  39.       Then
  40.        Begin
  41.         ShowWindow(hWndMain, SW_HIDE);
  42.         ShowWindow(hWndPopup, SW_HIDE);
  43.        End;
  44.      End;
  45.  
  46.     WM_LBUTTONDOWN: MessageBox
  47.                     (hWndMain, PChar('Left Mouse Button'), PChar('MyProgram'), 0);
  48.    End;
  49.    Result:= DefWindowProc(hWnd, MSG, wPARAM, lPARAM);
  50.   End;
  51.  
  52. BEGIN
  53.  WND.lpszClassName:= 'MyWND';
  54.  WND.lpfnWndProc  := @MainProc;
  55.  WND.hInstance    := hInstance;
  56.  WND.hbrBackground:= 5;
  57.  
  58.  RegisterClass(WND);
  59.  
  60.  hWndHidden:= CreateWindow
  61.  (WND.lpszClassName,'HIDDEN', WS_OVERLAPPEDWINDOW,
  62.   0, 0, 1, 1, 0, 0, hInstance, Nil);
  63.  
  64.  hWndMain:= CreateWindow
  65.  (WND.lpszClassName,'My API Window', WS_EX_TOOLWINDOW Or WS_VISIBLE,
  66.   500, 500, 500, 300, hWndHidden, 0, hInstance, Nil);
  67.  
  68.  hWndPopup:= CreateWindow
  69.  (WND.lpszClassName,'My Second Window', WS_EX_TOOLWINDOW Or WS_VISIBLE,
  70.   200, 500, 500, 300, hWndMain, 0, hInstance, Nil);
  71.  
  72.  If Not RegisterHotKey(hWndMain, HotKeyShow, MOD_CONTROL, VK_BACK)
  73.  Then MessageBox(hWndMain, PChar('HotKey Failed'), PChar('MyProgram'), 0);
  74.  
  75.  While GetMessage(MSG, 0, 0, 0)
  76.  Do
  77.   Begin
  78.    TranslateMessage(MSG);
  79.    DispatchMessage (MSG);
  80.   End;
  81. END.
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 2.0.4 FPC 3.0.4 - TRUNK 2.1.0 FPC 3.3.1

Leledumbo

  • Hero Member
  • *****
  • Posts: 8114
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: API WND (No Taskbar Button) How can I get rid of this button ?
« Reply #2 on: October 20, 2017, 08:30:14 pm »
2 requirements: WS_EX_TOOLWINDOW AND no owner.

ASerge

  • Hero Member
  • *****
  • Posts: 1423
Re: API WND (No Taskbar Button) How can I get rid of this button ?
« Reply #3 on: October 20, 2017, 08:48:38 pm »
2 requirements: WS_EX_TOOLWINDOW AND no owner.
WS_EX_TOOLWINDOW - it does not look like a normal window.
Better hidden WS_EX_TOOLWINDOW, WS_POPUP as parent for main.

ASerge

  • Hero Member
  • *****
  • Posts: 1423
Re: API WND (No Taskbar Button) How can I get rid of this button ?
« Reply #4 on: October 20, 2017, 08:57:51 pm »
Code: Pascal  [Select]
  1. PROGRAM project1;
  2.  USES
  3.   Windows;
  4. ...
Did you read this and this?
Quote
Except for reserved words and directives, which are in all lowercase, all Pascal identifiers should use InfixCaps, which means the first letter should be a capital, and any embedded words in an identifier should be in caps, as well as any acronym that is embedded

RAW

  • Hero Member
  • *****
  • Posts: 794
Re: API WND (No Taskbar Button) How can I get rid of this button ?
« Reply #5 on: October 20, 2017, 11:58:13 pm »
Quote
2 requirements: WS_EX_TOOLWINDOW AND no owner.
Really ?
I don't get it to work without a hidden window...

Quote
WS_EX_TOOLWINDOW - it does not look like a normal window.
Better hidden WS_EX_TOOLWINDOW, WS_POPUP as parent for main.
Yes... a normal window looks better...
I think I'll use this:
Code: Pascal  [Select]
  1.  hWndHidden:= CreateWindow
  2.  (WND.lpszClassName,'HIDDEN', WS_Popup,
  3.   0, 0, 1, 1, 0, 0, hInstance, Nil);
  4.  
  5.  hWndMain:= CreateWindow
  6.  (WND.lpszClassName,'My API Window', WS_OverlappedWindow Or WS_VISIBLE,
  7.   800, 500, 500, 300, hWndHidden, 0, hInstance, Nil);
  8.  
  9.  hWndPopup:= CreateWindow
  10.  (WND.lpszClassName,'My Second Window', WS_EX_AppWindow Or WS_VISIBLE,
  11.   200, 200, 200, 300, hWndMain, 0, hInstance, Nil);

Quote
Did you read this and this?
:D ... No, I don't...
btw: there is something that I like, but also a lot that I don't like...

For example: Why on earth does everybody use FName for a field? I guess it's very easy to see that a field is a field (VAR).  :)
BUT if you send some code via email or post code on the internet or print some code etc... then I don't know what exactly FName is. I mean inside the LAZARUS IDE it's easy but even there I don't like to wait for the hint window.
I like to see it right away: iName = Integer, strName = String, uStrName = UnicodeString, edtName = TEdit, pnlName = TPanel, ptName = TPoint .... etc.
That's a lot better I think... and you cannot do so much mistakes if in a hurry...  :)
btw: T for Type is ok, not perfect, but ok...

Thanks to both of you... 
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 2.0.4 FPC 3.0.4 - TRUNK 2.1.0 FPC 3.3.1

SunyD

  • Guest
Re: API WND (No Taskbar Button) How can I get rid of this button ?
« Reply #6 on: October 21, 2017, 12:47:55 am »
If you want remove taskbar button, when your application is minimized then it is very easy. You can call the function Hide, it hides your form and taskbar button. You must call later the function show to show your form and taskbar button.

Here is one example with trayicon. When you minimize the form then it will be hidden, you must click on its tastbar icon to show again.


taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: API WND (No Taskbar Button) How can I get rid of this button ?
« Reply #7 on: October 21, 2017, 05:08:16 am »
For example: Why on earth does everybody use FName for a field? I guess it's very easy to see that a field is a field (VAR).  :)

two main goals 1) I do not need to remember the name of the variable I just need to type F and the IDE will provide me with a list of variable to choose from and 2) I want to know when the algorithm touches non local things thos places are usually where most of logical bugs appear in my code.

BUT if you send some code via email or post code on the internet or print some code etc... then I don't know what exactly FName is. I mean inside the LAZARUS IDE it's easy but even there I don't like to wait for the hint window.
I like to see it right away: iName = Integer, strName = String, uStrName = UnicodeString, edtName = TEdit, pnlName = TPanel, ptName = TPoint .... etc.
That's a lot better I think... and you cannot do so much mistakes if in a hurry...  :)
I guess that depends on ones habits. For example I have never seen a Name or a phone that is not a string a position might be a tpoint or an integer depending who wrote it but that becomes apparent from the assignment code I'm more interested to be able to find faster what I'm looking for when I type than what it is. I see no value on what it is after the initial definition only on what it represents, that is why the name of the variable is a big deal and I avoid reusing variables. Logic errors are harder to find than data errors usually there are a couple of exceptions that data type will create logical errors in the code but very few.

Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

RAW

  • Hero Member
  • *****
  • Posts: 794
Re: API WND (No Taskbar Button) How can I get rid of this button ?
« Reply #8 on: October 21, 2017, 06:39:37 am »
Quote
Here is one example with trayicon. When you minimize the form then it will be hidden, you must click on its tastbar icon to show again.
Thanks... but right now I don't need the LCL, the target computer hasn't even a standard shell...

Quote
1) I do not need to remember the name of the variable I just need to type F and the IDE will provide me with a list of variable to choose from...
OK, but I do the same... If I need an Integer then I type "i" and see all my integer variables or I type "str" and I see all my String variables, that's even better if the program has really a lot variables or fields...  :)  AND I can directly see what kind of variable this is... especially outside the IDE. (I don't like compromises)
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 2.0.4 FPC 3.0.4 - TRUNK 2.1.0 FPC 3.3.1

ASerge

  • Hero Member
  • *****
  • Posts: 1423
Re: API WND (No Taskbar Button) How can I get rid of this button ?
« Reply #9 on: October 21, 2017, 05:22:13 pm »
:D ... No, I don't...
And in vain.
This is your example, only the types have been changed to compile under Win64 (and other minor fixes), formatted according to conventions, so that other people (and not just you) can read and do not frown every time:
Code: Pascal  [Select]
  1. program project1;
  2.  
  3. uses
  4.   Windows;
  5.  
  6. var
  7.   HWndMain, HWndPopup: HWND;
  8.  
  9. const
  10.   CHotKeyShowId = 113000;
  11.  
  12. function MainProc(Wnd: HWND; Msg: UINT; WParam: WPARAM; LParam: LPARAM): LRESULT; stdcall;
  13. begin
  14.   if (Msg = WM_HOTKEY) and (WParam = CHotKeyShowId) then
  15.   begin
  16.     ShowWindow(HWndMain, SW_SHOW);
  17.     ShowWindow(HWndPopup, SW_SHOW);
  18. //    SetForegroundWindow(HWndMain);
  19.     SetForegroundWindow(HWndPopup);
  20.   end;
  21.   case Msg of
  22.     WM_CLOSE:
  23.       UnregisterHotKey(HWndMain, CHotKeyShowId);
  24.     WM_DESTROY:
  25.       begin
  26.         PostQuitMessage(0);
  27.         Exit;
  28.       end;
  29.     WM_KEYDOWN:
  30.       if VK_ESCAPE = WParam then
  31.       begin
  32.         ShowWindow(HWndMain, SW_HIDE);
  33.         ShowWindow(HWndPopup, SW_HIDE);
  34.       end;
  35.     WM_LBUTTONDOWN:
  36.       MessageBox(HWndMain, PChar('Left Mouse Button'), PChar('MyProgram'), MB_OK);
  37.   end;
  38.   Result := DefWindowProc(Wnd, Msg, WParam, LParam);
  39. end;
  40.  
  41. var
  42.   WndClass: TWndClass;
  43.   Msg: TMSG;
  44.   HWndForHideMainFromTaskBar: HWND;
  45. begin
  46.   WndClass.lpszClassName := 'MyWND';
  47.   WndClass.lpfnWndProc := @MainProc;
  48.   WndClass.hInstance := hInstance;
  49.   WndClass.hbrBackground := COLOR_WINDOW;
  50.   RegisterClass(WndClass);
  51.   HWndForHideMainFromTaskBar := CreateWindow(WndClass.lpszClassName, '', WS_POPUP,
  52.     0, 0, 0, 0, 0, 0, hInstance, nil);
  53.   HWndMain := CreateWindow(WndClass.lpszClassName, 'My API Window',
  54.     WS_OVERLAPPEDWINDOW or WS_VISIBLE, 500, 500, 500, 300, HWndForHideMainFromTaskBar,
  55.     0, hInstance, nil);
  56.   HWndPopup := CreateWindow(WndClass.lpszClassName, 'My Second Window',
  57.     WS_VISIBLE, 200, 500, 500, 300, HWndMain, 0, hInstance, nil);
  58.   if not RegisterHotKey(HWndMain, CHotKeyShowId, MOD_CONTROL, VK_BACK) then
  59.     MessageBox(HWndMain, PChar('HotKey Failed'), PChar('MyProgram'), 0);
  60.   while GetMessage(@Msg, 0, 0, 0) do
  61.   begin
  62.     TranslateMessage(Msg);
  63.     DispatchMessage(Msg);
  64.   end;
  65. end.

RAW

  • Hero Member
  • *****
  • Posts: 794
Re: API WND (No Taskbar Button) How can I get rid of this button ?
« Reply #10 on: October 21, 2017, 11:41:44 pm »
Quote
This is your example, only the types have been changed to compile under Win64 (and other minor fixes), formatted according to conventions,  ...
Nice, thanks, yes right now I'm using an x86-computer and this is only a small test... I need to think about the visual appearance of the program and if I want to use ULW-API or GR32 LIB or GDI+ (..never saw a good looking GDI+ text example so far (like photoshop)... I need something that fits to a photo, so I think transparent text is the best I can do... let's see...).

I would do it at least like this... this way it's easier to see what's going on, especially during a fast scroll...  :)
Code: Pascal  [Select]
  1. begin
  2.   WndClass.lpszClassName:= 'MyWND';
  3.   WndClass.lpfnWndProc  := @MainProc;
  4.   WndClass.hInstance    := hInstance;
  5.   WndClass.hbrBackground:= COLOR_WINDOW;
  6.  
  7.   RegisterClass(WndClass);
  8.  
  9.   HWndForHideMainFromTaskBar:= CreateWindow
  10.   (WndClass.lpszClassName, '', WS_POPUP,
  11.    0, 0, 0, 0, 0, 0, hInstance, nil);
  12.  
  13.   HWndMain:= CreateWindow
  14.   (WndClass.lpszClassName, 'My API Window',
  15.    WS_OVERLAPPEDWINDOW or WS_VISIBLE, 500, 500, 500, 300,
  16.    HWndForHideMainFromTaskBar, 0, hInstance, nil);
  17.  
  18.   HWndPopup:= CreateWindow
  19.   (WndClass.lpszClassName, 'My Second Window',
  20.    WS_VISIBLE, 200, 500, 500, 300, HWndMain, 0, hInstance, nil);
  21.  
  22.   if not RegisterHotKey(HWndMain, CHotKeyShowId, MOD_CONTROL, VK_BACK) then
  23.     MessageBox(HWndMain, PChar('HotKey Failed'), PChar('MyProgram'), 0);
  24.  
  25.   while GetMessage(@Msg, 0, 0, 0) do
  26.   begin
  27.     TranslateMessage(Msg);
  28.     DispatchMessage(Msg);
  29.   end;
  30. end.

btw: I really like the "THEN" and/or the "DO" at the left side, especially if there is a lot of code....... It's not really necessary but just a habit and I don't think my code is hard to read. I saw people writing left-justified code all over the place... everything ranged left... funny...

And are these little differences really a problem?
Version 1:
Code: Pascal  [Select]
  1.   if not RegisterHotKey(HWndMain, CHotKeyShowId, MOD_CONTROL, VK_BACK) then
  2.     MessageBox(HWndMain, PChar('HotKey Failed'), PChar('MyProgram'), 0);
  3.   while GetMessage(@Msg, 0, 0, 0) do
  4.   begin
  5.     TranslateMessage(Msg);
  6.     DispatchMessage(Msg);
  7.   end;
Version 2:
Code: Pascal  [Select]
  1.   if not RegisterHotKey(HWndMain, CHotKeyShowId, MOD_CONTROL, VK_BACK)
  2.   then MessageBox(HWndMain, PChar('HotKey Failed'), PChar('MyProgram'), 0);
  3.  
  4.   while GetMessage(@Msg, 0, 0, 0)
  5.   do
  6.    begin
  7.     TranslateMessage(Msg);
  8.     DispatchMessage(Msg);
  9.    end;

Version 2 is definitely easier to read ...  :P
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 2.0.4 FPC 3.0.4 - TRUNK 2.1.0 FPC 3.3.1

ASerge

  • Hero Member
  • *****
  • Posts: 1423
Re: API WND (No Taskbar Button) How can I get rid of this button ?
« Reply #11 on: October 22, 2017, 11:00:44 am »
Version 2 is definitely easier to read ...  :P
For me, it's terribly uncomfortable.
Generally everyone has his own opinion, but then everyone agrees on one style. Then everyone follows this rule and everything becomes easier. And when someone says that all this is nonsense, but his version is more beautiful, then the rest can only wish that he showed his code less.

RAW

  • Hero Member
  • *****
  • Posts: 794
Re: API WND (No Taskbar Button) How can I get rid of this button ?
« Reply #12 on: October 22, 2017, 06:59:24 pm »
Quote
Generally everyone has his own opinion, but then everyone agrees on one style. Then everyone follows this rule and everything becomes easier. And when someone says that all this is nonsense, but his version is more beautiful, then the rest can only wish that he showed his code less.
I know exactly what you mean, I see this all around me and saw it very intense in school: Dress like everyone else or get beaten up, talk like everyone else or get beaten up, do things like everyone else or get beaten up. Fortunately that was a very long time ago and I'm already outside this slavery-circle. Of course I understand that a team of programmers following the same rules is a good idea, but that doesn't mean every line needs to be identical...

If you do what you like and I do what I like then everything is perfect I guess, so let's keep it this way.  :)
Thanks again...
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 2.0.4 FPC 3.0.4 - TRUNK 2.1.0 FPC 3.3.1

metis

  • Full Member
  • ***
  • Posts: 159
Re: API WND (No Taskbar Button) How can I get rid of this button ?
« Reply #13 on: January 08, 2018, 03:49:23 pm »
@RAW

The easiest Way to hide the TaskbarButton, that I found is this:

Code: [Select]
uses
  Windows, InterfaceBase, Win32Int, ...
...

var
  AppHnd : THandle;
  EXStyle: Long;
...

  AppHnd  := TWin32WidgetSet(WidgetSet).AppHandle; // <- Replace this by Your Handle
  EXStyle := GetWindowLongA(AppHnd, GWL_EXSTYLE);
  SetWindowLongA(AppHnd, GWL_EXSTYLE, EXStyle or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW);

Though this is for LCL under Win32 (it works perfectly on my WinXP 32bit), at least the
Windows-API-Functions and -Parameters should work in a WinConsole, too (didn't try it out).
I know from some of Your former Posts, that You're familiar with these APIs, but:
-> Why don't/can't You use them here ?

BTW:
Of course everybody may write his Code ad libitum, but if You want to share it with others, it's easier to follow common Conventions.  ;)
Life could be so easy, if there weren't those f*** Details.

Thaddy

  • Hero Member
  • *****
  • Posts: 9303
Re: API WND (No Taskbar Button) How can I get rid of this button ?
« Reply #14 on: January 08, 2018, 04:47:17 pm »
If the window has the dialog style it also doesn't show up. For a mainform try fsSplash since fsDialog is sadly missing.... In Lazarus. (BUG)
« Last Edit: January 08, 2018, 04:53:57 pm by Thaddy »
also related to equus asinus.