Tilanne: teen esim. vb6- ohjelman joka 1 sek välein lisää luku-muuttujaa "luku" yhdellä ja antaa luku-muuttujan arvon labeliin.
No, kun sitten tämän ohjelman ajaa ja "unohtaa" sen noin 10 minuutiksi taustalle suorittamaan itseään samalla vaikka surffaten netissä niin sitten tämä vb-ohjelma jumiutuu täysin (lopettaa laskemisen jne).. Missä syy?? onko niin että vb-ohjelmalle varatut muuttujat jotenkin kuormittaa liikaa muistia vai mikä on ?
Tein tällaisen testin, joka toimi moitteettomasti:
Dim luku As Integer
Private Sub Timer1_Timer()
    luku = luku + 1
    Caption = luku
End SubYhden muuttujan käsittely kerran sekunnissa ei varmasti vie niin paljon tehoja, että ohjelma jumiutuisi sen takia. Vika on jossain muualla.
Ok, olet oikeassa, keksin tuon esimerkin mutta tällä koodilla: se jumiutuu (ilmoittaa värin hiiripointerin mukaan):
Private Const SRCCOPY = &HCC0020
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
  Dim dhwnd As Long
  Dim dhdc As Long
  Dim color As Long
  Dim x As Long
  Dim y As Long
  Dim mouseX, mouseY As Long
Dim xy As POINTAPI
Dim wnd As Long, wndc As Long
Private Sub Command1_Click()
Timer1.Interval = 0
Dim xxx, yyy As Long
    xxx = Text1.Text
    yyy = Text2.Text
      wnd = WindowFromPoint(xxx, yyy)
      dhwnd = GetDesktopWindow
      dhdc = GetWindowDC(dhwnd)
    color = GetPixel(dhdc, xxx, yyy)
    Label5 = color
End Sub
Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 40
End Sub
Private Sub Timer1_Timer()
  GetCursorPos xy
  wnd = WindowFromPoint(xy.x, xy.y)
  Label2 = xy.x & ", " & xy.y
    dhwnd = GetDesktopWindow
    dhdc = GetWindowDC(dhwnd)
    color = GetPixel(dhdc, xy.x, xy.y)
    Label1 = color
End Submod.edit: kooditagit
'formille: 4kpl labeleja, 2 textboxia ja commandbutton
MSDN:n mukaan funktion GetWindowDC jälkeen pitää kutsua lopuksi funktiota ReleaseDC. Tämä voi olla ongelman syy.
Aihe on jo aika vanha, joten et voi enää vastata siihen.