Why windows can't be refreshed correctly?

Just starting out? Need help? Post your questions and find answers here.
goomoo
User
User
Posts: 42
Joined: Sun Dec 05, 2004 9:25 am
Location: China
Contact:

Why windows can't be refreshed correctly?

Post by goomoo »

I've just wrote a little program that it can contains two Explorer windows tiled in a ContainerGadget, but the explorer windows always can't be refreshed correctly, I've tried out my all possible ways, but havn't a good solution yet, someone can help me? Thanks a lot!

Codes are here:

Code: Select all

; PureBasic Visual Designer v3.90 build 1360

;- Window Constants
;
Enumeration
  #Window_main
EndEnumeration

;- Gadget Constants
;
Enumeration
  #ButtonImage_TileV
  #Container_main
  #ButtonImage_TileH
  #ButtonImage_Refresh
  #ButtonImage_NewFolder
  #String_0
  #Button_RunDos
EndEnumeration

Procedure Open_Window_main()
  If OpenWindow(#Window_main, 225, 67, 640, 480,  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "2Explorers  曾劲松 2005/4/17 http://goomoo.yeah.net")
    If CreateGadgetList(WindowID())
      ButtonGadget(#ButtonImage_TileV, 3, 3, 36, 36, "TileV") 
      ButtonGadget(#ButtonImage_TileH, 40, 3, 36, 36, "TileH")
      ButtonGadget(#ButtonImage_Refresh, 77, 3, 36, 36, "Refresh")
      ButtonGadget(#ButtonImage_NewFolder, 130, 3, 36, 36, "NewFldr")
      StringGadget(#String_0, 180, 10, 285, 20, "")
      ButtonGadget(#Button_RunDos, 470, 4, 90, 30, "执行DOS命令")
      
      ;-
      ContainerGadget(#Container_main, 0, 40, 639, 439, #PB_Container_Single)
      CloseGadgetList()
      
    EndIf
  EndIf
EndProcedure

Enumeration
  #TileV
  #TileH
EndEnumeration

Dim hExplorer.l(2)
currentStyle=#TileV

Procedure updateWindows()  
  
  InvalidateRect_(hContainer,#Null,true)
  ;Delay(10)
  ;InvalidateRect_(hExplorer(0),#Null,true)
  ;InvalidateRect_(hExplorer(1),#Null,true)
  ;UpdateWindow_(hContainer)
  ;UpdateWindow_(hExplorer(0))
  ;UpdateWindow_(hExplorer(1))
  ShowWindow_(hExplorer(0),#sw_show)
  ShowWindow_(hExplorer(1),#sw_show) 
  
  ; RedrawWindow_(hExplorer(0),#Null,#Null,#RDW_INVALIDATE)
  ; RedrawWindow_(hExplorer(1),#Null,#Null,#RDW_INVALIDATE)
  ; SendMessage_(hExplorer(0),#wm_paint,GetDC_(hExplorer(0)),0)
  ; SendMessage_(hExplorer(1),#wm_paint,GetDC_(hExplorer(1)),0)
EndProcedure

Procedure wndCallBAck(WindowId.l,Message.l,wParam.l,lParam.l)
  Result=#PB_ProcessPureBasicEvents 
  Result=PureRESIZE_CallBack(WindowId,Message,wParam,lParam,Result) 
  
  Select Message
    Case #wm_size
      If IsWindowVisible_(WindowID())
        If currentStyle=#TileV
          ;TileWindows_(hContainer,#MDITILE_VERTICAL,#Null,#Null,#Null) 
        Else
          ;TileWindows_(hContainer,#MDITILE_HORIZONTAL,#Null,#Null,#Null)
        EndIf
      EndIf
    Case #wm_activate
      updateWindows()
    Case #WM_ACTIVATEAPP
      ;updateWindows()
  EndSelect
  
  ProcedureReturn Result 
EndProcedure

RunProgram("explorer.exe")
RunProgram("explorer.exe")
Delay(1000)

Open_Window_main()
hContainer=GadgetID(#Container_main)

containerWindowStyle=GetWindowLong_(hContainer,#gwl_style)
SetWindowLong_(hContainer,#gwl_style,containerWindowStyle|#MDIS_ALLCHILDSTYLES)

PureRESIZE_SetGadgetResize(#Container_main,1,1,1,1)
SetWindowCallback(@wndCallBAck())

Repeat
  hExplorer(0)=FindWindow_("ExploreWClass",#Null)
  Delay(100)
Until hExplorer(0)
;SetParent_(hExplorer(0),hContainer)
wndClass.l=GetWindowLong_(hExplorer(0),#gwl_style)
wndClass=wndClass!#ws_popup
wndClass=wndClass!#ws_popupwindow
;When use style WS_CHILDWINDOW ,the explore's menu not available
wndClass=wndClass|#WS_CHILDWINDOW|#ws_tiledwindow|#ws_child
;SetWindowLong_(hExplorer(0),#gwl_style,wndClass)
wndClassEx=#WS_EX_WINDOWEDGE|#WS_EX_MDICHILD
;SetWindowLong_(hExplorer(0),#gwl_exstyle,wndClassEx)

SetParent_(hExplorer(0),hContainer)

HInstance=GetWindowLong_(WindowID(),#gwl_hInstance)
SetWindowLong_(hExplorer(0),#gwl_hInstance,HInstance)

Repeat
  hExplorer(1)=FindWindow_("ExploreWClass",#Null)
  Delay(100)
Until hExplorer(1) And hExplorer(0)<>hExplorer(1)
;SetParent_(hExplorer(1),hContainer)
;SetWindowLong_(hExplorer(1),#gwl_style,wndClass)
SetWindowLong_(hExplorer(1),#gwl_hInstance,HInstance)
;SetWindowLong_(hExplorer(1),#gwl_exstyle,wndClassEx)
SetParent_(hExplorer(1),hContainer)

ShowWindow_(WindowID(),#sw_maximize)
TileWindows_(hContainer,#MDITILE_VERTICAL,#Null,#Null,#Null)

Repeat
  
  event = WaitWindowEvent()
  
  If event = #PB_EventGadget
    ;updateWindows()
    ;Debug "WindowID: " + Str(EventWindowID())
    
    GadgetID = EventGadgetID()
    
    If GadgetID = #ButtonImage_TileV
      TileWindows_(hContainer,#MDITILE_VERTICAL,#Null,#Null,#Null)
      currentStyle=#TileV
    ElseIf GadgetID = #Container_main 
      
    ElseIf GadgetID = #ButtonImage_TileH
      TileWindows_(hContainer,#MDITILE_HORIZONTAL,#Null,#Null,#Null)
      currentStyle=#TileH
    ElseIf GadgetID = #ButtonImage_Refresh
      updateWindows()
      
    ElseIf GadgetID = #ButtonImage_NewFolder
      Debug "GadgetID: #ButtonImage_NewFolder"
      
    ElseIf GadgetID = #String_0
      Debug "GadgetID: #String_0"
      
    ElseIf GadgetID = #Button_RunDos
      Debug "GadgetID: #Button_RunDos"
      
    EndIf
    
  EndIf
  
Until event = #PB_EventCloseWindow

End
Last edited by goomoo on Mon Apr 18, 2005 10:07 am, edited 1 time in total.
Hello, Everyone.
Thanks for your help.
goomoo
User
User
Posts: 42
Joined: Sun Dec 05, 2004 9:25 am
Location: China
Contact:

Post by goomoo »

<I've simplified the codes.>
Last edited by goomoo on Mon Apr 18, 2005 10:08 am, edited 1 time in total.
Hello, Everyone.
Thanks for your help.
goomoo
User
User
Posts: 42
Joined: Sun Dec 05, 2004 9:25 am
Location: China
Contact:

Post by goomoo »

Can someone give any comment? please.
Hello, Everyone.
Thanks for your help.
doodlemunch
Enthusiast
Enthusiast
Posts: 237
Joined: Tue Apr 05, 2005 11:20 pm

Post by doodlemunch »

You just crashed my explorer, asshole. And I was going to help you...
One word: learn how to programm.
goomoo
User
User
Posts: 42
Joined: Sun Dec 05, 2004 9:25 am
Location: China
Contact:

Post by goomoo »

I have tested on WindowsXP and windows 2003 server, and it doesn't crash explorer. Perhaps your system is unstable, or what's your OS?
Hello, Everyone.
Thanks for your help.
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

doodlemunch wrote:You just crashed my explorer, asshole. And I was going to help you...
One word: learn how to programm.
Please calm down, no one forced you to run his code.
There are always two sides to every story...
Good programmers don't comment their code. It was hard to write, should be hard to read.
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

:lol:
I bet goomoo's code unplugged the rj45 of his modem, turned off his monitor and sent goomoo a pic of him naked as well. but theres a bug there, if you unplug his rj45 and later try to retrieve an image, you will get problems :lol: (sorry couldnt resist and yes I'm making no sense, why?, just bringing some "fun")... Maybe the problem exists by the way (explorers crashing, like those who climbs riffs, if the rope cuts, they'll crash), But I cant tell im not close to any PB compiler here.




offtopic: goomoo, what does your avatar mean / say ?.

Notice: No one forces anyone to compile anything posted in any purebasic forum because anyone thinks that everyone should do what anyone wants to do with out getting forced to do what anyone wants anyone to do. Didnt made any sense? good. Today im nosense But I feel like sharing that.
goomoo
User
User
Posts: 42
Joined: Sun Dec 05, 2004 9:25 am
Location: China
Contact:

Post by goomoo »

:D
Hi,dagcrack.
Sorry for my poor English.I'm not very clear about your words, but I think you are saying a joke to every one,is it? :P

My avatar is a Chinese stone print,there are two seal characters, they mean "old wood" in English and pronounced "goomoo" in Chinse, but in fact I'm a young man. :)
Hello, Everyone.
Thanks for your help.
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

I've always been interested in almost every culture and their language!, thanks for your explaination. And yes, I was joking all the time in my last post

:P
goomoo
User
User
Posts: 42
Joined: Sun Dec 05, 2004 9:25 am
Location: China
Contact:

Post by goomoo »

Thanks for your participance to my post. I'm going to bed now ,goodnight! :)
Hello, Everyone.
Thanks for your help.
filperj
User
User
Posts: 77
Joined: Tue Sep 16, 2003 8:53 pm
Location: Nevers(France)

Post by filperj »

You crashed my explorer too! :lol:
But I'm a proud Windows user, I'm not afraid of crashes. :wink:

When you use SetParent_(), the 2 windows must belong to the same app, maybe it's a part of your problem ?
goomoo
User
User
Posts: 42
Joined: Sun Dec 05, 2004 9:25 am
Location: China
Contact:

Post by goomoo »

filperj wrote:You crashed my explorer too! :lol:
But I'm a proud Windows user, I'm not afraid of crashes. :wink:

When you use SetParent_(), the 2 windows must belong to the same app, maybe it's a part of your problem ?
:?
I say sorry to you. Thank you for your reply. :lol:
But I think this is not the main problem, please see these simple codes below:

Code: Select all

RunProgram("notepad.exe")
hWndNotepad=FindWindow_("Notepad",#Null)
While hWndNotepad=0
  Delay(100)
  hWndNotepad=FindWindow_("Notepad",#Null)
Wend

hwndMain=OpenWindow(1,0,0,640,480,#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget,"Containt Notepad")
If hwndMain=0
  End 
EndIf
CreateGadgetList(hwndMain)
hContainer=ContainerGadget(1,3,3,636,470,#PB_Container_Single)
SetParent_(hWndNotepad,hContainer)
Repeat
  event=WaitWindowEvent()
Until event=#PB_Event_CloseWindow
Hello, Everyone.
Thanks for your help.
filperj
User
User
Posts: 77
Joined: Tue Sep 16, 2003 8:53 pm
Location: Nevers(France)

Post by filperj »

please see these simple codes below:
The NotePad's window is displayed very badly.

Anyway, I don't know a workaround for SetParent_(), sorry. (I would be interested too, if an API Guru knows...)
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

Could also try to change the Repeat .. until (waitwindowevent) or some such to something else. I know that setgadgettext() for textgadgets does not work with one type of event, but works with another. And since that gadget is basically a window ... :)
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

This works a little better for me...

Code: Select all

RunProgram("notepad.exe") 
hWndNotepad=FindWindow_("Notepad",#Null) 
While hWndNotepad=0 
  Delay(100) 
  hWndNotepad=FindWindow_("Notepad",#Null) 
Wend 

hwndMain=OpenWindow(1,0,0,640,480,#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget,"Containt Notepad") 
If hwndMain=0 
  End 
EndIf 
CreateGadgetList(hwndMain) 
hContainer=ContainerGadget(1,3,3,636,470,#PB_Container_Single) 
; --> Add #WS_CLIPCHILDREN to the ContainerGadget
SetWindowLong_(hContainer, #GWL_STYLE, GetWindowLong_(hContainer, #GWL_STYLE) | #WS_CLIPCHILDREN)
; --> Add #WS_CHILD to Notepad
SetWindowLong_(hWndNotepad, #GWL_STYLE, GetWindowLong_(hWndNotepad, #GWL_STYLE) | #WS_CHILD)
; --> Set the ContainerGadget as the parent
SetParent_(hWndNotepad,hContainer) 
; --> Position Notepad
SetWindowPos_(hWndNotepad, 0, 20, 20, 500, 400, 0)

Repeat 
  event=WaitWindowEvent() 
Until event=#PB_Event_CloseWindow
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Post Reply