Jump to content

Again ;-) Small Gui-gdi-problem


Recommended Posts

Hi there :huh2:

I don't know if it is normal or not, maybe a "not-deleting-a-gui-value"-problem.

Please take a look at this code and if you test it out then look into the "GDI-Objects" of the task-manager in NT/2K/XP.

Global $GUI_CHECKED = 1, $check1
GUI1()
While GUIMsg() > 0
   $n = GUIMsg(0)
; the same with $n = GUIRead()
   If $n = $check1 Then
      If GUIRead($check1) = $GUI_CHECKED Then
         GUIDelete()
         msgbox(0,"","check GDI")
         GUI2()
      Else
         GUIDelete()
         msgbox(0,"","check GDI")
         GUI1()
      EndIf
   EndIf
WEnd    

GUIDelete()
msgbox(0,"","check GDI")

Exit

Func GUI1()
   GUICreate("GUI1")
   $check1 = GUISetControl("checkbox","change",50,50,100,20)
   GUISetControlNotify()
   GUIShow()
EndFunc

Func GUI2()
   GUICreate("GUI2")
   $check1 = GUISetControl("checkbox","change",50,50,100,20)
   GUISetControlEx(-1,$GUI_CHECKED)
   GUISetControlNotify()
   GUIShow()
EndFunc

The GDI-object-number will bigger and bigger.

For that sample only 1 step but if you have a lot more controls then the step will be also bigger.

What I want to do is to switch between a small GUI and a GUI with more functions you know.

Ok, I know it's a little problem but maybe there's a solution for it :D

Thanks again, Holger :)

Edited by Holger
Link to comment
Share on other sites

:D Thanks Jon and JPM...BUT...there is still 'a' same problem!!!

I will test it more and tell you where it happens, but for the moment here is the second 'problem-example'.

I added only "GUISetControlFont" and the problem occurs again.

Maybe in a future version it will be solved. :)

Global $GUI_CHECKED = 1, $check1
GUI1()
While GUIMsg() > 0
  $n = GUIMsg(0)
; the same with $n = GUIRead()
  If $n = $check1 Then
     If GUIRead($check1) = $GUI_CHECKED Then
        GUIDelete()
        msgbox(0,"","check GDI")
        GUI2()
     Else
        GUIDelete()
        msgbox(0,"","check GDI")
        GUI1()
     EndIf
  EndIf
WEnd 

GUIDelete()
msgbox(0,"","check GDI")

Exit

Func GUI1()
  GUICreate("GUI1")
  $check1 = GUISetControl("checkbox","change",50,50,100,20)
  GUISetControlNotify()
  GUISetControlFont(-1,11,650)
  GUIShow()
EndFunc

Func GUI2()
  GUICreate("GUI2")
  $check1 = GUISetControl("checkbox","change",50,50,100,20)
  GUISetControlEx(-1,$GUI_CHECKED)
  GUISetControlNotify()
  GUISetControlFont(-1,11,650)
  GUIShow()
EndFunc

At the moment I live with it :huh2:

Link to comment
Share on other sites

:huh2: Thanks Jon and JPM...BUT...there is still 'a' same problem!!!

I will test it more and tell you where it happens, but for the moment here is the second 'problem-example'.

I added only "GUISetControlFont" and the problem occurs again.

Maybe in a future version it will be solved.  :lol:

Global $GUI_CHECKED = 1, $check1
GUI1()
While GUIMsg() > 0
  $n = GUIMsg(0)
; the same with $n = GUIRead()
  If $n = $check1 Then
     If GUIRead($check1) = $GUI_CHECKED Then
        GUIDelete()
        msgbox(0,"","check GDI")
        GUI2()
     Else
        GUIDelete()
        msgbox(0,"","check GDI")
        GUI1()
     EndIf
  EndIf
WEnd 

GUIDelete()
msgbox(0,"","check GDI")

Exit

Func GUI1()
  GUICreate("GUI1")
  $check1 = GUISetControl("checkbox","change",50,50,100,20)
  GUISetControlNotify()
  GUISetControlFont(-1,11,650)
  GUIShow()
EndFunc

Func GUI2()
  GUICreate("GUI2")
  $check1 = GUISetControl("checkbox","change",50,50,100,20)
  GUISetControlEx(-1,$GUI_CHECKED)
  GUISetControlNotify()
  GUISetControlFont(-1,11,650)
  GUIShow()
EndFunc

At the moment I live with it  :)

It was easy to solve the first one because the color are memorized.

It is not true for fonts so I think we will need to live with this one. :D

Link to comment
Share on other sites

@jpm: don't know if it is alright so, but I added a line to 'ChangeFont'-c++-function and it works now!? :D

////////////////////////////////////////////////////////////////////////////////////////////////
//
// ChangeFONT()
//
////////////////////////////////////////////////////////////////////////////////////////////////

void CGuiBox::ChangeFONT(HWND hWnd, char *Font, int Size, int Weight, int nAttribute)
{
    HFONT   hFont;
    HDC  hDC=GetDC(HWND_DESKTOP);
    int  CyPixels=GetDeviceCaps(hDC,LOGPIXELSY);
    ReleaseDC(HWND_DESKTOP,hDC);
    hFont = CreateFont(0-(Size*CyPixels)/72,0,0,0,Weight,
  nAttribute & GUI_FONTITALIC, nAttribute & GUI_FONTUNDER, nAttribute & GUI_FONTSTRIKE,
  DEFAULT_CHARSET,
         OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY ,FF_DONTCARE,Font);

    SendMessage(hWnd,WM_SETFONT,(WPARAM)hFont,(LPARAM)TRUE);
    DeleteObject(hFont); // <- this one I added...hmmm...

} // ChangeFONT()

Edit: Shi... I see that was not correct...hmmm...difficult...

I think I should learn c++ in a workshop...

Regards Holger

Edited by Holger
Link to comment
Share on other sites

@jpm: don't know if it is alright so, but I added a line to 'ChangeFont'-c++-function and it works now!?  :D

////////////////////////////////////////////////////////////////////////////////////////////////
//
// ChangeFONT()
//
////////////////////////////////////////////////////////////////////////////////////////////////

void CGuiBox::ChangeFONT(HWND hWnd, char *Font, int Size, int Weight, int nAttribute)
{
    HFONT   hFont;
    HDC  hDC=GetDC(HWND_DESKTOP);
    int  CyPixels=GetDeviceCaps(hDC,LOGPIXELSY);
    ReleaseDC(HWND_DESKTOP,hDC);
    hFont = CreateFont(0-(Size*CyPixels)/72,0,0,0,Weight,
  nAttribute & GUI_FONTITALIC, nAttribute & GUI_FONTUNDER, nAttribute & GUI_FONTSTRIKE,
  DEFAULT_CHARSET,
         OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY ,FF_DONTCARE,Font);

    SendMessage(hWnd,WM_SETFONT,(WPARAM)hFont,(LPARAM)TRUE);
    DeleteObject(hFont); // <- this one I added...hmmm...

} // ChangeFONT()

Edit: Shi... I see that was not correct...hmmm...difficult...

I think I should learn c++ in a workshop...

Regards Holger

THe best I can do is to have the GuiDefaultFont not having this problem and perhaps the last used GuiSetControlFont. I don't want to memorise all unless it is more than mandatory ... :huh2:
Link to comment
Share on other sites

JP, you can always attach the original font as a property on control.... (SetProps and GetProps I think)

GDI leaks aren't really something you can just safely ignore. The system has a limit (10,000 I think, but I can't remember). Once a program hits that number, it will crash. Even a slow leak will add up given that some people run scripts for extremely long periods of time.

Link to comment
Share on other sites

JP, you can always attach the original font as a property on control.... (SetProps and GetProps I think)

GDI leaks aren't really something you can just safely ignore.  The system has a limit (10,000 I think, but I can't remember).  Once a program hits that number, it will crash.  Even a slow leak will add up given that some people run scripts for extremely long periods of time.

I take a while to reach 10000 switching from one gui to another using different fonts each time. (French joke I am sure you already did)

Nevertheless I was afraid to waste memory by memorizing the font handle. But JON convince already to do it and is ready for 102.24 no more leak on font usage.

If I underdand the Windows API I am realeasing all gdi during GuiDelete.

:D

Link to comment
Share on other sites

@jpm: thanks for trying to solve it  :huh2:

Maybe I will use 2 GUI's and then show one and hide the other... :D

Cool are the new GUI-functions: GUIGetControlState is very good  :lol:

Regards Holger

2 or several gui at the same time is more complicated than releasing the used gdi. Is corrected in 102.24 waiting more bug before release.

I know that some will come. :)

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...