AutoHotkey Community

It is currently May 26th, 2012, 8:38 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 70 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
 Post subject:
PostPosted: August 8th, 2009, 12:37 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
I having a little problem that I'm hoping you can help me with. When all of the buttons fit on a single toolbar line, everything looks fine. For example (code block used for the fixed font):

Code:
========================================
|  Icon1  Icon2   Icon3  Icon3  Icon4  |
========================================

However, when the toolbar get resized into multiple lines, the last line of a multi-line toolbar is always oversized. For example:

Code:
========================================
|  Icon1  Icon2   Icon3  Icon3  Icon4  |
|--------------------------------------|
|  Icon5  Icon6                        |
|                                      |
|                                      |
========================================

I tried banging on it, kicking it, stroking it, etc. but nothing seems to work. Any ideas?

Thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 8th, 2009, 1:59 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Yes. I have idea. I hope it will work.

Using the _Test.ahk sample, you can experiment and see when does that happen.

I noticed that if there are not separators, it doesn't happen. It also seems that separator size influence the additional space.

Start to _Test.ahk, press Define, Press Insert several times. You will see your problem. Press Clear, remove all separators, press Insert several times and it should work. To see separator size influnce, just repeat this with various separator sizes. For instance, with "---------" separator the bottom line is OK, but there is lot of empty space between the button bars.

Let me know if you find another explanation or way to fix it.

BTW, I didn't try those "dynamic toolbar" scenarios in my real life scripts. So far I had always fixed toolbars and everything works OK with them. But perhaps using last parameter of Toolbar_Add can be of help here (so you can readjuce the toolbar size after adding buttons). Also, browse the MSDN Reference, maybe there is some important part of the API I skipped or thought it isn't that important at the time of making.

Thanks for your help again. I hope we can make this important module perfect for everyday use. :)

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 9th, 2009, 2:41 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
majkinetor wrote:
I noticed that if there are not separators, it doesn't happen. It also seems that separator size influence the additional space.

Separators. Who woulda thunk?

Thanks for the heads up. I'll take a closer look.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 20th, 2009, 4:04 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
There is one problem with your code jballi. The clicking stops working in some scenarios.

1. I have two toolbars
2. On 2nd toolbar I click button, which brings 2nd gui, i don't move mouse. Then I close the window with ESC
3. Application gets focus and if toolbar is first control cretated it takes the focus and fires "hot" event, setting it to 1
4. Now click doesn't work until you move the mouse and make another hot event fire.



Strange scenario... Problem is with single statics handling different toolbars :).

Something needs to be done... either using storage function to keep different vars for different toolbars or something else that doesn't involve statics .


Check the screen:
Image

You can see on screen that both Toolbars have focus. I clicked last button on 2nd one, and after I released gui it showed, first one got focus by the system (Scheduler button).

_________________
Image


Last edited by majkinetor on August 20th, 2009, 4:27 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 20th, 2009, 4:21 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
v2.14
OK, I hope I fixed the problem by using only statics in onNotify.
Now each toolbar keeps its settings and with single toolbar it doesn't happen (for me at least).

God bless Lexikos for "assume static" :D

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 20th, 2009, 4:55 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
One more bug with the code...

Hot event isn't reported if FLAT style is not present. On some computers FLAT is always set (must be the theme) on some not...

Thats kind of a problem :), unless you want all ur toolbars to be flat.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 20th, 2009, 8:56 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
2jballi
OK, I changed the code in what seems to work and looks much less complex.

Try it, see if it works for you. I tested on above sample and it behaves normally.

Code:
Toolbar_onNotify(Wparam,Lparam,Msg,Hwnd) {
   static MODULEID = 80609, oldNotify="*"
   static NM_CLICK=-2, NM_RCLICK=-5, NM_LDOWN=-20, TBN_DROPDOWN=-710, TBN_HOTITEMCHANGE=-713, TBN_ENDDRAG=-702, TBN_BEGINADJUST=-703, TBN_GETBUTTONINFOA=-700, TBN_QUERYINSERT=-706, TBN_QUERYDELETE=-707, TBN_BEGINADJUST=-703, TBN_ENDADJUST=-704, TBN_RESET=-705, TBN_TOOLBARCHANGE=-708, TB_COMMANDTOINDEX=0x419
   static cnt, cnta, cBTN, inDialog, LDOWN

   
   ; If s_LDOWNPos=0, the left mouse button has not been clicked.  If s_LDOWNPos<>0,            --jballi
   ; the left mouse button has been clicked and the variable contains the button position.
   if ((NumGet(Lparam+4)) != MODULEID){
      ifEqual, oldNotify, *, SetEnv, oldNotify, % Toolbar("OldNotify")       
      ifNotEqual, oldNotify,,return DllCall(oldNotify, "uint", Wparam, "uint", Lparam, "uint", Msg, "uint", Hwnd)       
      return
   }
   
   hw :=  NumGet(Lparam+0), code := NumGet(Lparam+8, 0, "Int"),  handler := Toolbar(hw "Handler")
   ifEqual, handler,, return
   iItem  := (code != TBN_HOTITEMCHANGE) ? NumGet(lparam+12) : NumGet(lparam+16)

   SendMessage, TB_COMMANDTOINDEX,iItem,,,ahk_id %hw%   
   pos:=ErrorLevel+1
   txt := Toolbar_GetButton( hw, pos, "c")

   if (code=NM_LDOWN)
        return  LDOWN := Pos
 
   if (code = NM_CLICK) {
      IfEqual, pos, 4294967296, return
      if (LDOWN) and !InStr(Toolbar_GetButton(hw,pos,"s"),"disabled")
          LDOWN := 0, %handler%(hw, "click", txt, pos, iItem)
    }

   if (code=NM_RCLICK)   {
      ifEqual, pos, 4294967296, return 0
        else  return %handler%(hw,"rclick", txt, pos, iItem)
   }

   if (code = TBN_DROPDOWN)
      return %handler%(hw, "menu", txt, pos, iItem)

 
   if (code = TBN_HOTITEMCHANGE) {
      IfEqual, pos, 4294967296, return 
      %handler%(hw, "hot", txt, pos,  iItem)
      return 0
   }

  ;=================== CUSTOMIZATION NOTIFICATIONS ===========================

   if (code = TBN_BEGINADJUST) {
      cnta := NumGet( Toolbar(hw "aBTN") ) , cnt := Toolbar_getButtonArray(hw, cBTN), inDialog := true
      if (cnt=0) && (cnta=0)
         Msgbox Nothing to customize
      return
   }

   if (code = TBN_GETBUTTONINFOA)   {
      if (iItem = cnt + cnta)               ;iItem is position, not identifier. Win keeps sending incresing numbers until we say "no more" (return 0)
         return 0
       
      TBB := lparam + 16                  ;The OS buffer where to put button structure
      o := (iItem < cnt) ?  cBTN + 20*iItem : Toolbar( hw "aBTN") + 20*(iItem-cnt) + 4
      Toolbar_memcpy( TBB, o, 20) ;copy the compiled item into notification struct
      return 1
   }

    ;Return at least one TRUE in QueryInsert to show the dialog, if the dialog is openinig. When the dialog is open, QueryInsert affects btn addition. QueryDelete affects deletion.
   if (code = TBN_QUERYINSERT) or (code = TBN_QUERYDELETE) {
      if (cnta="" or cnta=0) AND (cnt=0)
         return FALSE
      return TRUE
   }

   if (code=TBN_ENDADJUST) {
      Toolbar_onEndAdjust(hw, cBTN, cnt), inDialog := false
      return %handler%(hw, "adjust", "", "", "")
   }

   ;This will fire when user is dragging buttons around with adjustable style
   if (code = TBN_TOOLBARCHANGE) and !inDialog
      return %handler%(hw, "change", "", "", "")
}


I simply monitored only LDOWN i LUP, if they are unmatched, no click event is fired.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2009, 11:32 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
majkinetor wrote:
OK, I changed the code in what seems to work and looks much less complex.

Try it, see if it works for you. I tested on above sample and it behaves normally.

Per your request, I tried your rewrite of the OnNotify function. I found a couple of problems. One very minor, the other not so minor.

Very minor: If you click down on a button and drag away from the button before releasing the button, the button (correctly) does not click. However, if you double click on the title bar and that same button falls under the mouse cursor, the maximize button click bug rears it's ugly head.

Not so minor: If you click on the dropdown portion of a button, the Menu event fires (good). However, if you click on the same dropdown again, the Click event fires (bad).

Let me know if you need any additional information.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2009, 2:18 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Quote:
If you click down on a button and drag away from the button before releasing the button, the button (correctly) does not click
However, if you double click on the title bar and that same button falls under the mouse cursor, the maximize button click bug rears it's ugly head.

Sounds like a rly tiny issue. Unfortunately it seems unfixable. I tried to use A_TickCount to discard distant in time click up and down but problems are state buttons that change the state when you hold the click too long over them and click isn't reported... I could monitor the mouse release globally tho, by capturing the mouse on click down, but it sounds like a lot of work for something that will probabably never happen.

Quote:
Not so minor: If you click on the dropdown portion of a button, the Menu event fires (good). However, if you click on the same dropdown again, the Click event fires (bad).

Yes, didn't catch that one. This looks like by design of Toolbar. If you do show the menu click will not be fired, I guess

I need redesign of this, Ill come back to it when I find time. In the meantime, use whatever code you find suitable.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 22nd, 2009, 1:47 pm 
Offline

Joined: February 11th, 2007, 4:10 pm
Posts: 185
There's a bug when specifying the style "nodivder" for toolbar_add

line1035: variable name contains an illegal character


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 23rd, 2009, 6:09 pm 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
I missed this post from the first round of messages you sent.

majkinetor wrote:
One more bug with the code...

Hot event isn't reported if FLAT style is not present.

This may not be a bug. According to msdn, "In a flat toolbar, both the toolbar and the buttons are transparent and hot-tracking is enabled." This implies that hot-tracking is not enabled unless the FLAT style is used. One reason (maybe) is because without the FLAT style, all of the buttons are raised and they all appears to be hot/active. Just a thought. I found the hot-tracking reference here:
http://tinyurl.com/nj5scs

majkinetor wrote:
... On some computers FLAT is always set (must be the theme) on some not...

Thats kind of a problem :), unless you want all ur toolbars to be flat.

Interesting. I pulled out the FLAT style to see what would happen. The buttons are still flat but the dropdown portion of the buttons are raised making the entire toolbar look very odd. I must have one of the computers where FLAT is (mostly) always set.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 23rd, 2009, 6:26 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Quote:
This may not be a bug. According to msdn, "In a flat toolbar, both the toolbar and the buttons are transparent and hot-tracking is enabled." This implies that hot-tracking is not enabled unless the FLAT style is used. One reason (maybe) is because without the FLAT style, all of the buttons are raised and they all appears to be hot/active. Just a thought. I found the hot-tracking reference here:

THats not the point. Point is that your code is using hot event to handle clicks, so I was surprised why my toolbars stop working on different system (which didn't have flat style by default).


Anyways, I think I got how clicks should work, Ill implement it soon. The idea is: click is only this sequence of events: 1lup, 1enddrag, 1click. Anything else is not click. Maximization bug is 1click. Other bug is 1lup 2enddrag, 1 click. I think that will work in all cases, including state buttons (and menu state buttons)

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 12:57 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
*** version 2.2 ***
! OnNotify events fixed (hopefully)
! Changed OnNotify redirection to fix problems with AHK native controls

2jballi
I realised this: any valid click will have enddrag & click executing near eachother (so time difference will be 0ms). When you click the mouse offscreen and release it on toolbar button it will not receive enddrag so time will be > 0. Enddrag can happen imediatelly after click only if you pressed lbutton and released it on the same button. If you release it outside toolbar you will get ENDDRAG but no CLICK. In your maximization thing you will only have CLICK without ENDDRAG since you never clicked the button.

hugman wrote:
There's a bug when specifying the style "nodivder" for toolbar_add

line1035: variable name contains an illegal character

Not confirmed. _Corners.ahk use nodivider flag. Post sample as a proof.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 4:42 pm 
Offline

Joined: February 11th, 2007, 4:10 pm
Posts: 185
majkinetor wrote:
*** version 2.2 ***
Not confirmed. _Corners.ahk use nodivider flag. Post sample as a proof.


I commented the line with nodivider flag. You can change it by yourself.

What I want to tell you is another problem:
the same code as below, if GuiEscape event is exists in the script, when you click the second toolbar button, the script will go to the GuiEscape labe automatically. What happens to it?

In fact , the code below is part of my project. If I change the order of gui creating in my project, in some case, the toolbar's event can't be triggled. In other cases, it's normal. But I am not sure how I should arrange the order beacuse of so many child gui.
The project is too large with serveral activex control and dll, and needs server/client to run. So it's not convenient to upload.
Code:
GUI_INDEX_REPORT := 2

@GUI_Report:
   Gui, %GUI_INDEX_REPORT%:Default
   Gui, %GUI_INDEX_REPORT%:+LastFound +LabelGUI_REPORT +Theme
   $hGUI_Report := WinExist()
   GroupAdd, GroupReport, ahk_id %$hGUI_Report%
   Gui, %GUI_INDEX_REPORT%: Margin, 5, 5
   Gui, %GUI_INDEX_REPORT%: Show , w800 h600
   
   Btns =
   (LTrim C
      1, 1, , showtext, 1
      2, 2, , showtext, 2
      -
      3, 3, , , 3
      4, 4, , , 4
      -
      5, 5, , , , 5
      6, 6, , , 6
      -
      7, 7, , , 7
      8, 8, , , 8
      9, 9, , , 9
   )
   $hToolbar := Toolbar_Add($hGUI_Report, "Toolbar_OnEvent", "FLAT TOOLTIPS", "1L")
   ;$hToolbar := Toolbar_Add($hGUI_Report, "Toolbar_OnEvent", "FLAT TOOLTIPS NODIVDER", "1L")
   Toolbar_Insert($hToolbar, Btns)
   Toolbar_SetButtonWidth($hToolbar, 52)   
Return

GUI_REPORTClose:
GUI_REPORTEscape:
   ExitApp
Return


Toolbar_OnEvent($hToolbar, pEvent, pPos, pTxt, pId){
   global
   
   if (pEvent = "click")
   {
      MsgBox % pEvent
      If (pId = 1){   ; 保存
      
      } Else If (pId = 2){   ; 审核
      
      } Else If (pId = 3){   ; 预览
      
      } Else If (pId = 4){   ; 打印
      
      } Else If (pId = 5){   ; 图像
      
      } Else If (pId = 6){   ; 申请单
      
      } Else If (pId = 7){   ; 存为模板
      
      } Else If (pId = 8){   ; 扩展
      
      } Else If (pId = 9){   ; 返回
         Gosub, GUI_REPORTClose
      }
   }
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 5:43 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Quote:
What I want to tell you is another problem:
the same code as below, if GuiEscape event is exists in the script, when you click the second toolbar button, the script will go to the GuiEscape labe automatically. What happens to it?

LOL. I noticed that myself... it seems like ID number 2 is used by the system to close the app :) When you change button id to something else, it will work OK. Ill add this to remarks :)

Quote:
NODIVDER

NODIVIDER



PS: ALways check the return values of module functions. Every module returns error message instead of usual data if it has problems. In your case, executing commented line brings:
Code:
---------------------------
1.ahk
---------------------------
'Toolbar_Add> Some of the styles are invalid.'

---------------------------
OK   
---------------------------

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 70 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: bekihito, Blackholyman, Exabot [Bot] and 12 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group