On 13 November 2013 10:25, Bernat Romagosa
<tibabenfortlapala...@gmail.com>wrote:

> Hi list,
>
> I made some progress but I'm still a bit lost here.
>
> I managed to get Pharo to be headless in Win32, by hiding the window via
> NB as Igor suggested, plus suspending the UI process (UIManager default
> uiProcess suspend), which was the cause for the window to show up again
> after a fraction of a second, because of the refresh interval.
>
> However, now I can only close Pharo by killing the process manually, which
> is not very nice for the end user. So I figured I'd try to add an icon to
> the system tray with a single context menu entry for closing Pharo.
>
> This is what I'm doing, taken from 
> MSDN<http://msdn.microsoft.com/en-us/library/windows/desktop/bb762159(v=vs.85).aspx>
> :
>
> NBWin32Shell >> shellNotifyIcon: lpdata dwMessage: dwMessage
>
> <primitive: #primitiveNativeCall module: #NativeBoostPlugin>
>
> ^ self nbCall: #(bool Shell_NotifyIcon(
>
>   DWORD dwMessage,
>
>   PNOTIFYICONDATA lpdata
>
> )) module: #shell32
>
> dwMessage is just a 0 (flag to create a tray icon), but lpdata needs to be a
> pointer to a struct of this 
> form<http://msdn.microsoft.com/en-us/library/windows/desktop/bb773352(v=vs.85).aspx>
> :
>
> typedef struct _NOTIFYICONDATA {
>   DWORD cbSize;
>   HWND  hWnd;
>   UINT  uID;
>   UINT  uFlags;
>   UINT  uCallbackMessage;
>   HICON hIcon;
>   TCHAR szTip[64];
>   DWORD dwState;
>   DWORD dwStateMask;
>   TCHAR szInfo[256];
>   union {
>     UINT uTimeout;
>     UINT uVersion;
>   };
>   TCHAR szInfoTitle[64];
>   DWORD dwInfoFlags;
>   GUID  guidItem;
>   HICON hBalloonIcon;
> } NOTIFYICONDATA, *PNOTIFYICONDATA;
>
>
> So, my question is: how do I translate this into NB code? How does one
> define a struct and then pass its pointer to a function in NativeBoost?
>
>
This is easy. Just make a subclass of NBExternalStructure,
define its fields in #fieldsDesc method (see example subclass).
Create it using #new, or #externalNew depending if structure should be
non-moving in memory for the rest of its life (but i think its needed only
at the moment of call, so #new should work),
fill it with proper values, and then pass it to that function. Just make
sure
that argument type PNOTIFYICONDATA changed to class name of your
structure in function signature.

Also, note that there is two Shell_NotifyIcon functions under the hood:

Shell_NotifyIconA
Shell_NotifyIconW

the 'A' stands for 'ascii',
and 'W' stands for 'wide',
this is how windows manages strings and characters/unicode.

For 'A' functions TCHAR == char (1byte)
for 'W' functions TCHAR == unsigned short (2bytes)

that means the definition and size of PNOTIFYICONDATA is different
depending on what function you going to be using.

Thanks a lot for your help, I'm getting closer :)
>
> Bernat.
>
> p.s. Could the Windows API be any more convoluted and dev-unfriendly in
> any possible sense?
>

hehe.. this is a typical for everything in windows: many, even basic things
require passing and filling various structures with many different fields,
and you may find that to initialize fields of one structure, you often need
to create another one and initialize it first :)



>
>
> 2013/11/4 Bernat Romagosa <tibabenfortlapala...@gmail.com>
>
>> Hi!
>>
>> Thanks Igor, that kinda worked! Pharo hides, but comes back after half a
>> second or so. I'll keep digging, thanks! :)
>>
>>
>> 2013/11/1 p...@highoctane.be <p...@highoctane.be>
>>
>> Well, this should rather be:
>>>
>>> handle :=NativeBoostWin32 squeakWindowHandle.
>>> window := NBWin32Window new value: handle; yourself.
>>> window hide.
>>>
>>> or
>>>
>>> window setWindowText: 'im a main window blablabla'.
>>>
>>> Phil
>>>
>>>
>>> On Thu, Oct 31, 2013 at 10:03 PM, Igor Stasenko <siguc...@gmail.com>wrote:
>>>
>>>> You can try something like this:
>>>>
>>>> | handle window |
>>>>
>>>> handle := NativeBoost forCurrentPlatform squeakWindowHandle.
>>>> window := NBWin32Window new value: handle; yourself.
>>>> window hide.
>>>>
>>>> or
>>>>
>>>> window setWindowText: 'im a main window blablabla'.
>>>>
>>>> :)
>>>>
>>>> i didn't tested it since its been implemented, but i think it should
>>>> work.
>>>>
>>>>
>>>>
>>>> On 30 October 2013 11:20, Bernat Romagosa <
>>>> tibabenfortlapala...@gmail.com> wrote:
>>>>
>>>>> In this direction, I'm trying to call a function in the shell32.dll
>>>>> lib that apparently should let you minimize an app to the system tray, but
>>>>> I'm not having much luck... I guess I don't really understand what am I
>>>>> exactly doing.
>>>>>
>>>>> This is what I found in the 
>>>>> MSDN<http://msdn.microsoft.com/en-us/library/bb762159%28VS.85%29.aspx>
>>>>> :
>>>>>
>>>>>  BOOL Shell_NotifyIcon(
>>>>>   _In_  DWORD dwMessage,
>>>>>   _In_  PNOTIFYICONDATA lpdata
>>>>> );
>>>>>
>>>>>
>>>>> So, I tried to translate this into Pharo as:
>>>>>
>>>>> MyClass >> minimizeToTray: dwMessage data: lpData
>>>>>
>>>>>   <apicall: bool 'Shell_NotifyIcon' (dword PNOTIFYICONDATA) module:
>>>>> 'shell32.dll'>
>>>>>
>>>>>
>>>>> But it won't let me save the method, reporting it's expecting an
>>>>> argument before PNOTIFYICONDATA.
>>>>>
>>>>> I realize PNOTIFYICONDATA is not a primitive type, but I just don't
>>>>> know how to handle it... :(
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Best regards,
>>>> Igor Stasenko.
>>>>
>>>
>>>
>>
>>
>> --
>> Bernat Romagosa.
>>
>
>
>
> --
> Bernat Romagosa.
>



-- 
Best regards,
Igor Stasenko.

Reply via email to