Jump to content
Tuts 4 You

Subclass problem but why?


LCF-AT

Recommended Posts

Posted

Hi huntingspace,

thanks again for your example code. :)

So now I have some small another problem.Yesterday I did create a small Listview window what only shows actually again in the main app Listview and what gets updated every second.The LV will shown if the mouse is on the icon and keeps so long till I press on the small LV (subclassed).So the problem I wanna talking about is something about how to set the dynamic LV over the tray icon from taskbar so here I have again a lot trouble to calculate the positions to set the LV correctly if the taskbar is at bottom or top or left or right so this I dont get it again as always.I also have same trouble with resizings of dynamic controls at WM_SIZE and now I have the problems too so this is really not my thing.Now the question is how to calc it correctly?

1.) I catch the coursor position with GetCursorPos API and now I have x & y values of mouse

2.) Next I find out the Rect of the tray taskbar via FIndWindow API & GetWIndowRect

3.) I read the entrys of my LV where is something going on so this is dynamic and can show 0 - xy.The window width is always same like 400 dec but the height is dynamic and for one entry I do add 16 bytes to height + 70 bytes for the window itself so that one line will also shown if not action is going on and to have a small height to click on it to close it

Ok now I have all infos so far and now I need to calc....AHHHHHH! :)

So I am really not sure where to sub / add something but I tried it and have something like this...

invoke GetCursorPos,addr LP
invoke FindWindow,chr$("Shell_TrayWnd"),NULL
invoke GetWindowRect,eax,addr rc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;				     


mov eax,rc.bottom	     
mov ecx,rc.top
mov ebx,rc.right
.if rc.left == 0h  &&  eax > rc.top  ; bottom 

mov eax,rc.bottom
mov ecx,rc.top
sub eax, ecx                            ; task breite
sub LP.y,eax
mov eax,LENGHT
sub LP.y,eax


.elseif rc.left == 0h  &&  rc.bottom < ecx
mov eax,rc.top
mov ecx,rc.bottom
sub eax, ecx 
add LP.y,eax
mov eax,LENGHT
add LP.y,eax

.elseif rc.top == 0h  && ebx > rc.left  ;  right
mov eax,rc.right
mov ecx,rc.left
sub eax, ecx                            ; task breite
sub LP.x,eax
mov eax,LENGHT
sub LP.x,eax

.elseif rc.top == 0h  && ebx < rc.left  ;  left
mov eax,rc.left
mov ecx,rc.right
add eax, ecx                            ; task breite
mov eax,LENGHT
add LP.x,eax
.endif		     
		      
		        
invoke MoveWindow,htooltip,LP.x,LP.y,400,LENGHT,FALSE
invoke ShowWindow,htooltip,SW_SHOW

So in the LENGHT variable is the actually height of my LV I wanna show.

Example...of 10 entrys

		xor esi,esi
		.while esi != 10
		inc esi
		invoke SendMessage,edi,LVM_GETITEMCOUNT,0,0
		mov lvi.iItem, eax
		mov lvi.imask, LVIF_TEXT
		lea eax, chr$("43234")
		mov	lvi.pszText,eax
		mov lvi.iSubItem,0
		invoke SendMessage,edi,LVM_INSERTITEM,0,addr lvi
		mov lvi.iSubItem,1
		invoke SendMessage,edi,LVM_SETITEM,0,addr lvi
		.endw 
		
		mov LENGHT, 70 ; = basic height to use
		invoke SendMessage,edi,LVM_GETITEMCOUNT,0,0
		.if eax != 0
		imul eax,16      ; add 16 bytes for one entry
		add LENGHT, eax  ; add to basic height
		.endif

As I said I have all infos so I need but cant calc this right so there I am going crazy.

About showing the LV.So this should be always same I mean the distance from taskbar end till desktop maybe 10 bytes.Problem here is also if the icon is more left or right in taskbar if this is left or right then there must be also something calculated etc you know.


                   ----------
                   |        |
                   |        |
                   ----------
_____________________________
Taskbar bottom >> my icon <<|
-----------------------------




_____________________________
Taskbar top    >> my icon <<|
-----------------------------
                   ----------
                   |        |
                   |        |
                   ----------
--
T|
A|
S|
K|
 |
l|
e|
f|
t|
 |
i| ----------
c| |        | 
o| |        |
n| ----------




           --
           |T
           |A
           |S
           |K
           | 
           |r
           |i
           |g
           |h
           |t
           | 
---------- |i
|        | |c
|        | |o
---------- |n

Can anyone help how to calc it right?

Thank you

Posted

Hi again,

ok I got this now so far..

invoke GetCursorPos,addr LP
invoke FindWindow,chr$("Shell_TrayWnd"),NULL
invoke GetWindowRect,eax,addr rc
				     


mov eax,rc.bottom	     
mov ecx,rc.top
mov ebx,rc.right
.if rc.left == 0h  &&  ebx >  eax  &&  rc.top != 0h   ; bottom

mov ecx,rc.top
sub ecx, 10
sub ecx, LENGHT  ; Height of LV
mov LP.y, ecx

mov ebx,rc.right
sub ebx, 400  ; LV width
sub ebx, 10   ; Distance away from task
mov LP.x, ebx

.elseif rc.left == 0h  &&  rc.top == 0h  && ebx > eax ; top

mov ecx,rc.bottom
add ecx, 10
mov LP.y, ecx

mov ebx,rc.right
sub ebx, 400  ; LV width
sub ebx, 10   ; Distance away from task
mov LP.x, ebx

.elseif rc.top == 0h  &&  rc.left != 0h    ;  right ok
mov eax,rc.right
mov ecx,rc.left
sub eax, ecx  
sub ecx, 10   ; Distance away from task
sub ecx, 400  ; LV width
mov LP.x, ecx

mov eax,rc.bottom
mov ecx, LENGHT  ; Height of LV
sub eax, ecx
sub eax, 10
mov LP.y, eax

.elseif rc.top == 0h  &&  rc.left == 0h && ebx < eax ;  left 
mov eax,rc.left
mov ecx,rc.right
add eax, ecx                        
add ecx, 10   ; Distance away from task
mov LP.x, ecx

mov eax,rc.bottom
mov ecx, LENGHT  ; Height of LV
sub eax, ecx
sub eax, 10   ; Distance away from task
mov LP.y, eax
.endif		     
		     
		     

invoke MoveWindow,htooltip,LP.x,LP.y,400,LENGHT,FALSE
invoke ShowWindow,htooltip,SW_SHOW

...not so perfect but now the window will shown all same (bottom top left right) without to overlap etc.No idea whether I can keep it so or not so maybe you have any better solution.I attach the new example for testing.

Tray Tooltip2.rar

greetz

  • Like 1
Posted (edited)

OK, LCF-AT. 

This is my version of the code:

PositionFlyoutWindow proc uses esi edi htooltip:DWORD
    shiftpos equ 6
    LOCAL rcSysTray:RECT
    LOCAL rcToolTip:RECT
    LOCAL dwWidth,dwHeight:DWORD
    invoke GetWindowRect,htooltip,addr rcToolTip
    mov eax,rcToolTip.right
    mov ecx,rcToolTip.bottom
    sub eax,rcToolTip.left
    sub ecx,rcToolTip.top
    mov dwWidth,eax        ; tooltip width
    mov dwHeight,ecx       ; tooltip height
    invoke GetSystemMetrics,SM_CXSCREEN
    mov esi,eax
    invoke GetSystemMetrics,SM_CYSCREEN
    mov edi,eax
    invoke FindWindow,chr$("Shell_TrayWnd"),NULL
    mov ecx,eax
    invoke GetWindowRect,ecx,addr rcSysTray
    mov eax,rcSysTray.right
    mov ecx,rcSysTray.bottom
    xor edx,edx
    sub eax,rcSysTray.left
    sub ecx,rcSysTray.top
    .if (eax==esi)
        sub esi,dwWidth
        sub esi,shiftpos
        .if (rcSysTray.top==edx)       ; top systray
            mov edi,ecx
            add edi,shiftpos
        .elseif (rcSysTray.bottom==edi); bottom systray
            sub edi,ecx
            sub edi,dwHeight
            sub edi,shiftpos
        .endif
    .elseif (ecx==edi)
        sub edi,dwHeight
        sub edi,shiftpos
        .if (rcSysTray.left==edx)      ; left systray
            mov esi,eax
            add esi,shiftpos
        .elseif (rcSysTray.right==esi) ; right systray
            sub esi,eax
            sub esi,dwWidth
            sub esi,shiftpos
        .endif
    .endif
    invoke MoveWindow,htooltip,esi,edi,dwWidth,dwHeight,FALSE
    invoke ShowWindow,htooltip,SW_SHOW
    ret
PositionFlyoutWindow endp

Bonus. The procedure allows to get a handle of system tray toolbar:

GetSystemTrayToolbarHandle proc
    ; Find System Tray Window
    invoke  FindWindow,chr$("Shell_TrayWnd"),NULL
    .if (eax & eax)
        ; Find Tray Notify Window
        invoke  FindWindowEx,eax,NULL,chr$("TrayNotifyWnd"),NULL
        .if (eax & eax)
            ; Find Tray
            invoke  FindWindowEx,eax,NULL,chr$("SysPager"),NULL
            .if (eax & eax)
                ; Find Toolbar Window
                invoke  FindWindowEx,eax,NULL,chr$("ToolbarWindow32"),NULL
                nop
            .endif
        .endif
    .endif
    ret
GetSystemTrayToolbarHandle endp

 

Edited by huntingspace
  • Like 1
Posted

Hi again and thanks for your example code.Its also working to set the window into right positions & corners.But I still hate this calculations each time so with that I waste the most time. :) Anyway,so I think with this I can live now so far.Will check your pre code about WM_Mouseleave soon so maybe I get this too working anyhow but on the other hand its maybe not so bad to close the window by a click.

PS: If you got more helpfully ideas or other example sources I dont know yet then let me know it. :) If I remember right then I created any other topic asking for how to build a anlog clock so maybe you have something for this too etc.You know just a clock like you can see on any railway station etc something like this.

Thanks again so far.

Posted

Hi,

one other question.So you have maybe any latest windows.inc?So I still have any older version of that file from 2012 version 1.6.Are there any newer versions of this with more structs inside?Maybe you can upload any latest version of this or tell me where I can download it (Link) etc.

Thanks

Posted

Unfortunately but I have no a new windows.inc I'm not sure that it's a latest SDK but you can download here.


I attached to the topic my special include files. How to work: if you want to create a executable or dll file without stub you only need define _NOSTUB_ parameter.

include_files.rar

  • Like 1
Posted

Hi again,

so the windows.inc from masm is also from 2012.So it seems there is no latest version public and people have to do it by them self.Now I tried to get any latest header files from other languages (Dev C++) but there are also not all included.So the thing is I just wanna have any latest header files where are all infos defined so I cant also find all define infos on MSDN description like NIN_BALLOONTIMEOUT  and others etc and on MSDN I dont find any link to download the header file of Shellapi.h.If I would have them then I could check them each time if I need any define infos of any names like above and could also update my windows.inc for me so that I dont need to write any define in my projects anymore etc you know.So I think in that case I need to download any SDK pack but I only need the header files.

greetz

Posted

Hi its me again,

so I got a simple question today.So how can I change the font of my Dialogbox?I did set the style with DS_SETFONT too but I can set any other font into the Dialog title.Just wanna change the title only.Also wanna ask whether its possible to change the text color of the title too?

So if I create a new window via CreateWindowEx API so then I can also enter a lpWindowName / title.So how to change the font / color of this only?Lets say I do create a Listview and does show this only then it also has a window title like in example I did post before.So how to set the font / text color of this only without using the handle I got of this Listview?You know what I mean?

As I said,just talking about the title.By the way,so is there also a paramter / way to set the title into the middle of title bar?Just can read something about left or right align in API description.

Maybe you can tell me something about this issues too.

Thanks again

Posted

For Caption Title only

Quote

"codeguru.com"

 

Try to use SystemParametersInfo function with SPI_GETNONCLIENTMETRICS and SPI_SETNONCLIENTMETRICS.
First obtain NONCLIENTMETRICS structure of the current system,
using SPI_GETNONCLIENTMETRICS. Then change lfCaptionFont
member of NONCLIENTMETRICS and finally set NONCLIENTMETRICS, using SPI_SETNONCLIENTMETRICS.

Note that the caption is changed for all windows present in the system.

 

But is a dirty way the best way is the set the font (think i)

Create a font the set it with WM_SETFONT to the dialog,

invoke RtlZeroMemory, addr lfnt, sizeof LOGFONT		
mov	lfnt.lfHeight, -11
mov	lfnt.lfWeight, FW_NORMAL
invoke lstrcpy, addr lfnt.lfFaceName, addr szFontName
invoke CreateFontIndirect, addr lfnt
mov	hFont, eax

invoke SendMessage, hWeb, WM_SETFONT, hFont, FALSE

For use a other font for other  controls ,create a secont font and send a messages wit WM_SETFONT to this control as you like

Posted

Hi raggy,

I tried your second example code but it dosent work so I get no effect to see.I did set the code at WM_INITDIALOG.Can you post a little more code / example of this?WM_SETFONT is working for all other controls I do create only the Main Dialog I dont get any change.Maybe its any kind of handle issue so I also cant get any handle of my main dialog if I use GetDlgItem API also if I got the handle already in hWnd of my main routine.

greetz

Posted (edited)

Hi, LCF-AT.

To set a font in a dialog for all controls it's simply. See a sample:

SetFontForAllControls proc hWnd:HWND,hInst:hWnd:HWND
	; You can load your font from resourses
	invoke LoadFontFromResource,hInstance,ID_FONT
	; Or you can create a new font
	;invoke CreateFont,16,0,NULL,NULL,FW_NORMAL,FALSE,FALSE,FALSE,\
	;					DEFAULT_CHARSET,OUT_TT_ONLY_PRECIS,CLIP_TT_ALWAYS,\
	;					PROOF_QUALITY,DEFAULT_PITCH,chr$("Tahoma")
	.if (eax & eax)
		invoke EnumChildWindows,hWnd,addr SetControlFonts,0
	.endif
	ret
SetFontForAllControls endp

SetControlFonts proc hWnd:HWND,lParam:LPARAM
	invoke SendMessage,hWnd,WM_SETFONT,hFont,FALSE
	mov eax,TRUE
	ret
SetControlFonts endp

The SetFontForAllControls procudure is invoked when WM_INITDIALOG message is handled.

LoadFontFromResource proc uses esi edi ebx hInst:HINSTANCE,lpNameFontID:LPSTR
	LOCAL nFont:DWORD
	mov nFont,1
	invoke FindResource,hInst,lpNameFontID,RT_FONT
	.if (eax & eax)
		mov esi,eax
		invoke LoadResource,hInst,esi
		.if (eax & eax)
			mov edi,eax
			invoke SizeofResource,hInst,esi
			.if (eax & eax)
				mov ebx,eax
				invoke LockResource,edi
				.if (eax & eax)
					mov edi,eax
					invoke AddFontMemResourceEx,edi,ebx,0,addr nFont
					mov hMemFont,eax
					invoke CreateFont,16,0,NULL,NULL,FW_NORMAL,FALSE,FALSE,FALSE,\
						DEFAULT_CHARSET,OUT_TT_ONLY_PRECIS,CLIP_TT_ALWAYS,\
						PROOF_QUALITY,DEFAULT_PITCH,addr szFontName
					mov hFont,eax
				.endif
			.endif
		.endif
	.endif
	ret
LoadFontFromResource endp

The LoadFontFromResource procedure loads a font in memory from resources.

If you load a font from resources you should also write in RES file following:

#define ID_FONT 100
ID_FONT    FONT "myfont.ttf"

regards.

Edited by huntingspace
Posted

The second example is only for controls!

You add this code in WM_INITDIALOG  and get the control (GetDlgItem ) and send the messeages (WM_SETFON) to this control.

Posted

Hi again,

maybe you did understand me wrong or something so I mean I just wanna change the font of my dialog title itself and not any controls I do add on the dialog etc or also just the lpwindowname I wanna change / set any font style and size etc you know.

greetz

Posted

Hi again,

just wanna ask whether its possible to create icons with custom sizes?So normaly the icons have same sizes of width & height like 16x16 so is it possible to build icons with higher witdh like 32x16 etc?So I would like to create any text icon "Super Star" to show this as icon in my app & tray.On internet I found a site to convert png to ico but it does change the size to equal again.

greetz

Posted

Yes, you can create a custom icon 32x16 but the LoadIcon API will reduce it to 16x16.

icon_32x16.rar

Posted

Hi again,

ah ok.So I see I cant set any custom icon size into my tray.Only can set it for controls via LoadImage API + sizes.So is there any other chance to set any Text into the tray instead a icon?Maybe if I minimize to tray that then my Text "Super Star" will set which then gets handled like a icon?Somehow it should be possible but how is the question.Do you know that maybe?

greetz

Posted

Unfortunately, LCF-AT, I'm not a programmer (it's only my hobby) and I don't know how to set a text instead of an icon in system tray. May be you're better to create animated icon, for example, like a running string or etc. You can see at a sample by link.

  • Like 1
Posted

Hi Spacey,

ah ok and no problem.Just thought you know this maybe etc.Thanks for the another example.Just see one rolling icon in dialog what looks funny. :)

Thanks again so far.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...