Author Topic: Take control of your window code  (Read 10476 times)

0 Members and 1 Guest are viewing this topic.

Offline Eros Olmi

  • Sr. Member
  • ****
  • Posts: 268
    • thinBasic
Take control of your window code
« on: August 07, 2007, 11:35:13 PM »
Patrice,

thanks a lot for this fantastic learning code at http://www.jose.it-berater.org/smfforum/index.php?topic=1180.0
Really a big source of learning and thinking on how to make things on UI side.

A little note: on my box (WinXP Sp2) when I minimixe and than maximixe again, there is a graphic gap un upper left side, like a graphic repetition of part of the button graphic. Can it be?

Thanks again.
Eros
« Last Edit: August 10, 2011, 06:25:16 PM by Patrice Terrier »
thinBasic Script Interpreter - www.thinbasic.com | www.thinbasic.com/community
Win7Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

Offline Petr Schreiber

  • Sr. Member
  • ****
  • Posts: 254
Re: Take control of your window code
« Reply #1 on: August 08, 2007, 09:18:24 AM »
Hi,

I'd like to thank too for the sample, it is simply amazing.
I can confirm this redraw problem when minimize-maximize too. But when I click to "Restore" it is again correct..

Bye,
Petr
AMD Sempron 3400+ | 1GB RAM @ 533MHz | GeForce 6200 / GeForce 9500GT | 32bit Windows XP SP3

psch.thinbasic.com

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2022
    • www.zapsolution.com
Re: Take control of your window code
« Reply #2 on: August 08, 2007, 10:34:03 AM »
I don't see this problem on my computer(s)

But this is typically a Windows animation behavior occuring while the form is maximized, because at the time the AnchorEnum callback is being used, the new button location (in our case %ANCHOR_CENTER) the pr RECT structure has not been yet updated.

There are several solutions to this problem, either use a small ApiSLEEP or use MoveWindow instead of CALL ShowWindow(hWnd, %SW_MAXIMIZE).

In any case the change must be done there:

Code: [Select]
'// We process our custom system buttons command there.
FUNCTION zButtonSysCommand (BYVAL hWnd AS LONG, BYVAL wParam AS LONG) AS LONG
    LOCAL Done AS LONG
    Done = 0
    SELECT CASE LONG CINT(LOWRD(wParam))
    CASE %ID_CLOSE
         CALL SendMessage(hWnd, %WM_CLOSE, 0, 0)
         Done = -1
    CASE %ID_MAXIMIZE
         CALL ShowWindow(GetDlgItem(hWnd, %ID_RESTORE), %SW_SHOW)
         CALL ShowWindow(GetDlgItem(hWnd, %ID_MAXIMIZE), %SW_HIDE)
         CALL zUpdateWindow(GetDlgItem(hWnd, %ID_RESTORE), 0)
         CALL ShowWindow(hWnd, %SW_MAXIMIZE)

'------
         CALL zDrawBackground()
         CALL EnumChildWindows(hWnd, CODEPTR(AnchorEnum), 0) ' <-------
'------
         
         Done = -1
    CASE %ID_RESTORE
         CALL ShowWindow(GetDlgItem(hWnd, %ID_MAXIMIZE), %SW_SHOW)
         CALL ShowWindow(GetDlgItem(hWnd, %ID_RESTORE), %SW_HIDE)
         CALL zUpdateWindow(GetDlgItem(hWnd, %ID_MAXIMIZE), 0)
         CALL ShowWindow(hWnd, %SW_RESTORE)

         CALL zDrawBackground()
         CALL EnumChildWindows(hWnd, CODEPTR(AnchorEnum), 0)

         Done = -1
    CASE %ID_MINIMIZE
         CALL ShowWindow(hWnd, %SW_MINIMIZE)
         Done = -1
    END SELECT
    FUNCTION = Done
END FUNCTION

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2022
    • www.zapsolution.com
Re: Take control of your window code
« Reply #3 on: August 08, 2007, 10:52:42 AM »
Please, could you try this, and tell me if it solves the problem?

In zButtonSyscomand change CASE %ID_MAXIMIZE to this:

Code: [Select]
    CASE %ID_MAXIMIZE
         CALL ShowWindow(hWnd, %SW_MAXIMIZE)
         CALL ShowWindow(GetDlgItem(hWnd, %ID_RESTORE), %SW_SHOW)
         CALL ShowWindow(GetDlgItem(hWnd, %ID_MAXIMIZE), %SW_HIDE)

         CALL zDrawBackground()
         CALL EnumChildWindows(hWnd, CODEPTR(AnchorEnum), 0)
         
         Done = -1

Thank you

Patrice Terrier
www.zapsolution.com
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Eros Olmi

  • Sr. Member
  • ****
  • Posts: 268
    • thinBasic
Re: Take control of your window code
« Reply #4 on: August 08, 2007, 11:19:44 AM »
Sorry Patrice but problem still there.

In the upper left corner of the window is is showed to lower right image of the button. It seems like when restoring the window, the middle scren button is first drawn partially in the upper left side of the window and than moved in the center of the window. Can it be?

Regards
Eros
thinBasic Script Interpreter - www.thinbasic.com | www.thinbasic.com/community
Win7Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2022
    • www.zapsolution.com
Re: Take control of your window code
« Reply #5 on: August 08, 2007, 11:43:46 AM »
Ok, I see it now, I did not understood first how to reproduce the behavior.
But now that I am able to reproduce it myself, consider it as solved ;)
« Last Edit: August 10, 2011, 02:51:53 PM by Patrice Terrier »
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2022
    • www.zapsolution.com
Here is the solution
« Reply #6 on: August 08, 2007, 11:57:56 AM »
To fix the problem.

In AnchorEnum add
IF IsIconic(zMainWindow(0)) THEN FUNCTION = %FALSE: EXIT FUNCTION like this:
Code: [Select]
'// Anchor enum callback functio.n
FUNCTION AnchorEnum (BYVAL hWnd AS LONG, BYVAL lParam AS LONG) AS LONG

    IF IsIconic(zMainWindow(0)) THEN FUNCTION = %FALSE: EXIT FUNCTION

    'LOCAL zChildClass AS ASCIIZ * 32
    LOCAL pr AS RECT, rc AS RECT, pZP AS LONG
    LOCAL x, y, xW, yH AS LONG

In zDrawBackground add
IF IsIconic(hMain) THEN EXIT SUB like this :
Code: [Select]
'// Draw our custom background there
SUB zDrawBackground()
    LOCAL hMain AS LONG, hIC AS LONG, hDCmem AS LONG, rc AS RECT
    hMain = zMainWindow(0)
    IF IsIconic(hMain) THEN EXIT SUB
    CALL GetClientRect(hMain, rc)

Please let me know?
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Eros Olmi

  • Sr. Member
  • ****
  • Posts: 268
    • thinBasic
Re: Take control of your window code
« Reply #7 on: August 08, 2007, 12:25:22 PM »
Got it, perfect  ;)

Thanks a lot
Eros
thinBasic Script Interpreter - www.thinbasic.com | www.thinbasic.com/community
Win7Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2022
    • www.zapsolution.com
Re: Take control of your window code
« Reply #8 on: August 10, 2011, 06:25:53 PM »
The corrupted JPEG file attached to the first post of this thread has been removed (because of the "Server Collapse").

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com