Rendre un JFrame transparente JNI C

ocbslim Messages postés 5 Date d'inscription dimanche 14 novembre 2004 Statut Membre Dernière intervention 21 mai 2007 - 19 avril 2007 à 20:38
ocbslim Messages postés 5 Date d'inscription dimanche 14 novembre 2004 Statut Membre Dernière intervention 21 mai 2007 - 22 avril 2007 à 23:46
ocbslim

Bonjour,


Je developpe actuellement (personnel) une application avec une JFrame.
Je doit rendre cette derniere transparente. J'utilise JNI, enfin
j'essaie. Le probleme c'est que le C c'est pas ma tase de T . J'ai donc créé une JFrame test voici le code :

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.rmi.RemoteException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class FrameTransparente extends JFrame implements ActionListener{
   
    static {
        System.loadLibrary("FrameTranspaJNI");
            }
   
    //instaciation des composants
    JPanel jpFond;
    JTextField jtfNbTranspa;
    JButton jbVal;
   
    public FrameTransparente(){
       
        //création des composants
        jtfNbTranspa = new JTextField(20);
        jbVal = new JButton("Valider");
        jbVal.addActionListener(this);
        jpFond = new JPanel();
        jpFond.add(jbVal);
        jpFond.add(jtfNbTranspa);
        addWindowListener(new WindowAdapter(){
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }   
        });
        getContentPane().add(jpFond);
        setSize(500, 500);
        setVisible(true);
    }
   
    public native void setAlpha(int vAlpha);
   
public void actionPerformed(ActionEvent ae) {
       
        if(ae.getSource() == jbVal){
            setAlpha(Integer.valueOf((jtfNbTranspa.getText())));
        }
       
}   
    public static void main(String [] arg){
        new FrameTransparente();
    }
}

Je le compile, cree le .h avec javah, créé le code C, et la attention on ne se moque pas

#include <jni.h>
#include <stdio.h>
#include "FrameTransparente.h"

JNIEXPORT void JNICALL Java_FrameTransparente_setAlpha
  (JNIEnv *, jobject frame, jint iOpacity)

  // E:pourcentage d'opacité (0=invisible à 100=opaque=totalement visible)
                 // S:true=ok false=non réalisé (OS incompatible ou outil non trouvé)
{
   // --- Vérifier que l'on tourne sous Win2K
   OSVERSIONINFO Version = {sizeof(OSVERSIONINFO)};
   GetVersionEx(&Version);   bool bWin2K (Version.dwPlatformId VER_PLATFORM_WIN32_NT && Version.dwMajorVersion >= 5);
   if (! bWin2K) return false; // OS incompatible

   // --- Pointer la fonction utilisée dans la DLL "USER32.DLL"
   HMODULE hUser32 = GetModuleHandle("USER32.DLL");
   if (hUser32 == NULL) return false; // DLL non trouvée
   lpfnSetLayeredWindowAttributes SetLayeredWindowAttributes =
      (lpfnSetLayeredWindowAttributes)GetProcAddress(hUser32,"SetLayeredWindowAttributes");
   if (SetLayeredWindowAttributes == NULL) return false; // fonction non trouvée

   // --- Ajouter le style nécessaire à la fenêtre
   SetWindowLong(frame,GWL_EXSTYLE,GetWindowLong(frame,GWL_EXSTYLE) | WS_EX_LAYERED);

   // --- Assurer que le pourcentage d'opacité soit entre 0 et 100
   iOpacity = iOpacity < 0 ? 0 : (iOpacity > 100 ? 100 : iOpacity);

   // --- Régler l'opacité
  //SetLayeredWindowAttributes(hWnd,0,(BYTE)(iOpacity * 255 / 100),LWA_ALPHA);
  SetLayeredWindowAttributes(frame,0,(BYTE)(iOpacity * 255 / 100),LWA_ALPHA);
   return ;
}

J'ai récupéré un bout sur un forum (Merci) mais le probleme c que le C JE N'Y COMPREND RIEN
Donc lorsque je compile avec GCC, voici ce que j'obtient:

FrameTransparente.c: In function `Java_FrameTransparente_setAlpha':
FrameTransparente.c:6: parameter name omitted
FrameTransparente.c:12: `OSVERSIONINFO' undeclared (first use in this function)
FrameTransparente.c:12: (Each undeclared identifier is reported only once
FrameTransparente.c:12: for each function it appears in.)
FrameTransparente.c:12: parse error before "Version"
FrameTransparente.c: At top level:
FrameTransparente.c:13: parse error before '&' token
FrameTransparente.c:13: warning: data definition has no type or storage class
FrameTransparente.c:14: parse error before "bWin2K"
FrameTransparente.c:14: `Version' undeclared here (not in a function)
FrameTransparente.c:14: `VER_PLATFORM_WIN32_NT' undeclared here (not in a functi
on)
FrameTransparente.c:14: `Version' undeclared here (not in a function)
FrameTransparente.c:14: warning: data definition has no type or storage class
FrameTransparente.c:15: parse error before "if"
FrameTransparente.c:18: initializer element is not constant
FrameTransparente.c:18: warning: data definition has no type or storage class
FrameTransparente.c:19: parse error before "if"
FrameTransparente.c:21: `lpfnSetLayeredWindowAttributes' undeclared here (not in
 a function)
FrameTransparente.c:21: parse error before "GetProcAddress"
FrameTransparente.c:25: parse error before '(' token
FrameTransparente.c:28: initializer element is not constant
FrameTransparente.c:28: warning: data definition has no type or storage class
FrameTransparente.c:32: parse error before numeric constant
FrameTransparente.c:32: parse error before '*' token
FrameTransparente.c:32: `SetLayeredWindowAttributes' declared as function return
ing a function
FrameTransparente.c:32: `SetLayeredWindowAttributes' redeclared as different kin
d of symbol
FrameTransparente.c:20: previous declaration of `SetLayeredWindowAttributes'
FrameTransparente.c:32: parse error before ')' token

Voila donc de quoi s'araché les cheveux...
Donc si quelqu'un pourait me venir en aide...

MERCI D'AVANCE
A voir également:

3 réponses

Ombitious_Developper Messages postés 2333 Date d'inscription samedi 28 février 2004 Statut Membre Dernière intervention 26 juillet 2013 38
19 avril 2007 à 21:11
Salut:

Ce bout de code doit être compilé avec Visual C++, DevC++, ou tout autre compilateur de l'environnement Windows, tout simplement pour pouvoir inclure le fichier d'entête <windows.h>


________________________________________________________________________________
A.B. : 
"Dieu nous donne des mains, mais il ne bâtit pas les ponts"
0
Twinuts Messages postés 5375 Date d'inscription dimanche 4 mai 2003 Statut Modérateur Dernière intervention 14 juin 2023 111
19 avril 2007 à 21:17
Salut,

tu compile avec gcc sous windows ? mingw ? cygwin ? parce que si tu veux compiler un code windows sous linux c'est impossible surtout si celui-ci utilise les api windows comme celui présenté ci-dessus... de plus si tu veux faire de la vrai transparence sous linux je te conseil de voir ce sujet ICI (surtout mon dernier poste (en gros je te donne la solution pour faire de la transparence sous linux) )

------------------------------------
"On n'est pas au resto : ici on ne fait pas dans les plats tout cuits ..."

WORA
0
ocbslim Messages postés 5 Date d'inscription dimanche 14 novembre 2004 Statut Membre Dernière intervention 21 mai 2007
22 avril 2007 à 23:46
ocbslim

Ba en fait j'utilise minGW sous windows. J'ai récupéré ce code qui fonctionne tres bien seul mais je souhaite juste l'adapter avec jni pour l'utiliser en fait avec une appli java. Mais ce code C hou...  bon vous voyer ce que je veux dire alors si quelqu'un maitrise le C et JNI. J'ai  deja suivi un tut qui fait la fameuse application "HelloWorld" avec jni  ca fonctionnait trés bien mais une fois que le code C se complique ca devient dure.
0
Rejoignez-nous