Now those are fixed, back to the topic. The reason this is happening is that your application doesn't have the focus when the event happens that fills the clipboard with an image. So we just have to give it the focus before we call the OpenFileRequester and it should be solved. We'll use a hotkey for that:
Code: Select all
;==================================================================== 
; Demo:              Position a Requester 
; Author:            Lloyd Gallant (netmaestro) 
; Date:              January 2, 2008 
; Target OS:         Microsoft Windows All 
; Target Compiler:   PureBasic 4.0 and later 
; Applies to:        Any requester or messagebox of dialog class 
;==================================================================== 
#Form = 1 
#ImagePressePapier = 10 
Global hook 
Global Encodeur 
Global Extension.s 
Procedure CbtProc(nCode, wParam, lParam) 
  Select nCode 
    Case #HCBT_CREATEWND 
      hWnd = wParam 
      *pcbt.CBT_CREATEWND = lParam 
      *pcs.CREATESTRUCT = *pcbt\lpcs 
      If *pcs\lpszClass = 32770    
        w = GetSystemMetrics_(#SM_CXSCREEN) 
        h = GetSystemMetrics_(#SM_CYSCREEN) 
        *pcs\x = w/2 -*pcs\cx /2 
        *pcs\y = h/2 -*pcs\cy /2 
        UnhookWindowsHookEx_(hook) 
      EndIf 
  EndSelect 
  ProcedureReturn CallNextHookEx_(hook, nCode, wParam, lParam) 
 EndProcedure 
Hwnd = OpenWindow(#Form, 1000, 1000, 640, 480, "")
; give ourselves a handle to grab the application by 
wHotkey.w = 593 ; CTRL + Q
SendMessage_(WindowID(#Form), #WM_SETHOTKEY, wHotkey, 0)
Repeat 
  
 WaitWindowEvent(1) 
      
 If GetClipboardImage(#ImagePressePapier) 
 
  ; give this application keyboard focus 
  keybd_event_(#VK_CONTROL, 0,0,0)
  keybd_event_(#VK_Q, 0,0,0)
  keybd_event_(#VK_CONTROL, 0,#KEYEVENTF_KEYUP,0)
  keybd_event_(#VK_Q, 0,#KEYEVENTF_KEYUP,0)
  
  hook = SetWindowsHookEx_(#WH_CBT, @CbtProc(), #Null, GetCurrentThreadId_()) 
  Fichier$ = SaveFileRequester("Please choose file to save", "c:\", "Image Jpg|*.jpg|Image BitMap|*.bmp", 0) 
  ExtensionChoisie = SelectedFilePattern() 
  
  If Trim(Fichier$) <> "" 
    
   Select ExtensionChoisie 
    
    Case 0 
          
     UseJPEGImageEncoder() 
     Encodeur = #PB_ImagePlugin_JPEG 
     Extension = ".jpg" 
          
    Case 1 
    
     Encodeur = #PB_ImagePlugin_BMP 
     Extension = ".bmp" 
            
   EndSelect 
  
   If Right(LCase(Fichier$), 4) <> LCase(Extension) 
    Fichier$ + Extension 
   EndIf 
    
   SaveImage(#ImagePressePapier,Fichier$, Encodeur) 
    
  EndIf 
  
  ClearClipboard() 
  Break 
  
 EndIf 
  
ForEver 
End 


