OVH Cloud OVH Cloud

Console dos

7 réponses
Avatar
ab
Salut a tous,

Une question qu'on a certainement deja du poser, mais je ne retrouve plus
la reponse:

Sous windows:

J'ai un .bat qui contient une ligne de commande du genre

java -jar monJar.jar

Lorsque je double click sur mon batch, celui-ci m'ouvre une console dos.

Or, je ne veut pas que la console apparaisse...

Comment je fais?

(J'ai essaye javaw a la place de java sous XP, mais sans succes).

Par avance merci a tous.

A+

7 réponses

Avatar
Ulrich
Ou tu utilises un petit wrapper existant ou tu le codes toi-même.

Si tu veux, va faire un tour sur fr.comp.os.windows.programmation, j'ai
lancé un thread récent où les gars m'ont aidé à coder un wrapper pour mon
appli. En dernier post, j'ai mis le source. Si tu n'as pas de compilo. C++,
tu peux utiliser "Dev-C++" qui est free. Tu peux même mettre ton icone dans
les params du projet.

Bon code,
Ulrich.


"ab" a écrit dans le message de news:
bme9rk$mka$
Salut a tous,

Une question qu'on a certainement deja du poser, mais je ne retrouve plus
la reponse:

Sous windows:

J'ai un .bat qui contient une ligne de commande du genre

java -jar monJar.jar

Lorsque je double click sur mon batch, celui-ci m'ouvre une console dos.

Or, je ne veut pas que la console apparaisse...

Comment je fais?

(J'ai essaye javaw a la place de java sous XP, mais sans succes).

Par avance merci a tous.

A+



Avatar
Seb X
Pourquoi créer un .bat?

Alors qu'un simple fichier Jar avec un META-INF/MANIFEST.INF résout le
problème

"ab" a écrit dans le message de news:
bme9rk$mka$
Salut a tous,

Une question qu'on a certainement deja du poser, mais je ne retrouve plus
la reponse:

Sous windows:

J'ai un .bat qui contient une ligne de commande du genre

java -jar monJar.jar

Lorsque je double click sur mon batch, celui-ci m'ouvre une console dos.

Or, je ne veut pas que la console apparaisse...

Comment je fais?

(J'ai essaye javaw a la place de java sous XP, mais sans succes).

Par avance merci a tous.

A+



Avatar
fm
Je viens de compiler sans probleme. Par contre, comment l'utilises tu?

A+

-------------------------

Le source en question:


#include <windows.h>

/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */

/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);

/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;

/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);

/* Make the window visible on the screen */
//ShowWindow (hwnd, nFunsterStil);

STARTUPINFO si ;
PROCESS_INFORMATION pi ;

ZeroMemory(&si, sizeof(si)) ;
si.cb = sizeof(si) ;
ZeroMemory(&pi, sizeof(pi)) ;

bool b = CreateProcessA(NULL, "javaw.exe TA_MAIN_CLASS", NULL, NULL, false, CREATE_NO_WINDOW, NULL, NULL, &si, &pi) ;

CloseHandle(pi.hThread) ;
CloseHandle(pi.hProcess) ;

/* Run the message loop. It will run until GetMessage() returns 0 */
//while (GetMessage (&messages, NULL, 0, 0)) {
/* Translate virtual-key messages into character messages */
//TranslateMessage(&messages);
/* Send message to WindowProcedure */
//DispatchMessage(&messages);
//}


/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}


/* This function is called by the Windows function DispatchMessage() */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) /* handle the messages */
{
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}
Avatar
fm
En fait, pour l'instant mon bat ressemble a ca:

@echo off
%JAVA_HOME%jrebinjavaw -classpath %CLASSPATH% myclass --param1 xxx --param2 yyy 2> error.log
exit

Peux tu developper la solution que tu propose? Je ne vois pas vraiment ce que tu veux faire.

Merci.

Seb X wrote:
Pourquoi créer un .bat?

Alors qu'un simple fichier Jar avec un META-INF/MANIFEST.INF résout le
problème

"ab" a écrit dans le message de news:
bme9rk$mka$

Salut a tous,

Une question qu'on a certainement deja du poser, mais je ne retrouve plus
la reponse:

Sous windows:

J'ai un .bat qui contient une ligne de commande du genre

java -jar monJar.jar

Lorsque je double click sur mon batch, celui-ci m'ouvre une console dos.

Or, je ne veut pas que la console apparaisse...

Comment je fais?

(J'ai essaye javaw a la place de java sous XP, mais sans succes).

Par avance merci a tous.

A+








Avatar
Ulrich
Dans le code, tu trouves la ligne :
bool b = CreateProcessA(NULL, "javaw.exe TA_MAIN_CLASS", NULL, NULL, false,
CREATE_NO_WINDOW, NULL, NULL, &si, &pi) ;

et tu modifies selon ton, besoin :
bool b = CreateProcessA(NULL, "javaw.exe myclass --param1 xxx --param2 yyy
2", NULL, NULL, false, CREATE_NO_WINDOW, NULL, NULL, &si, &pi) ;

capito !

Pour répondre à ton thread de dessous. Quand tu fabrique une appli Java, il
est bon de stocker tes classes au sein d'un fichier archive de type JAR.
Dans l'archive tu peux donner un point d'entrée à ton application via un
fichier MANIFEST. Et dans la ligne MAIN tu précises ton main. Regarde des
exemples sur Google.

Bon code,
Ulrich.

PS : Il s'agit de deux solutions de lancement différentes.





"fm" a écrit dans le message de news:
bmee64$pp2$
Je viens de compiler sans probleme. Par contre, comment l'utilises tu?

A+

-------------------------

Le source en question:


#include <windows.h>

/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are
saved */

WNDCLASSEX wincl; /* Data structure for the windowclass */

/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called
by windows */

wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);

/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after
the window class */

wincl.cbWndExtra = 0; /* structure or the window
instance */

/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;

/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen
*/

544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to
desktop */

NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);

/* Make the window visible on the screen */
//ShowWindow (hwnd, nFunsterStil);

STARTUPINFO si ;
PROCESS_INFORMATION pi ;

ZeroMemory(&si, sizeof(si)) ;
si.cb = sizeof(si) ;
ZeroMemory(&pi, sizeof(pi)) ;

bool b = CreateProcessA(NULL, "javaw.exe TA_MAIN_CLASS", NULL, NULL,
false, CREATE_NO_WINDOW, NULL, NULL, &si, &pi) ;


CloseHandle(pi.hThread) ;
CloseHandle(pi.hProcess) ;

/* Run the message loop. It will run until GetMessage() returns 0 */
//while (GetMessage (&messages, NULL, 0, 0)) {
/* Translate virtual-key messages into character messages */
//TranslateMessage(&messages);
/* Send message to WindowProcedure */
//DispatchMessage(&messages);
//}


/* The program return-value is 0 - The value that PostQuitMessage()
gave */

return messages.wParam;
}


/* This function is called by the Windows function DispatchMessage() */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam) {

switch (message) /* handle the messages */
{
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message
queue */

break;
default: /* for messages that we don't deal
with */

return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}




Avatar
Seb X
En fait, pour l'instant mon bat ressemble a ca:
@echo off
%JAVA_HOME%jrebinjavaw -classpath %CLASSPATH% myclass --param1
xxx --param2 yyy 2> error.log

exit
Peux tu developper la solution que tu propose? Je ne vois pas vraiment ce
que tu veux faire.


Si les variables d'environnement java sont correctement configurées (ce qui
semble le cas puisque tu utilises %JAVA_HOME%), le simple fait de mettre un
fichier manifest (dans lequel tu indiques la classe contenant le main) dans
ton Jar te permet de lancer l'application en double cliquant dessus (comme
un exécutable Windows "normal"), sans console dos donc.....

Recherche sur Google "META-INF/MANIFEST.INF"

Avatar
fm
Merci pour tout!



Ulrich wrote:
Dans le code, tu trouves la ligne :
bool b = CreateProcessA(NULL, "javaw.exe TA_MAIN_CLASS", NULL, NULL, false,
CREATE_NO_WINDOW, NULL, NULL, &si, &pi) ;

et tu modifies selon ton, besoin :
bool b = CreateProcessA(NULL, "javaw.exe myclass --param1 xxx --param2 yyy
2", NULL, NULL, false, CREATE_NO_WINDOW, NULL, NULL, &si, &pi) ;

capito !

Pour répondre à ton thread de dessous. Quand tu fabrique une appli Java, il
est bon de stocker tes classes au sein d'un fichier archive de type JAR.
Dans l'archive tu peux donner un point d'entrée à ton application via un
fichier MANIFEST. Et dans la ligne MAIN tu précises ton main. Regarde des
exemples sur Google.

Bon code,
Ulrich.

PS : Il s'agit de deux solutions de lancement différentes.





"fm" a écrit dans le message de news:
bmee64$pp2$

Je viens de compiler sans probleme. Par contre, comment l'utilises tu?

A+

-------------------------

Le source en question:


#include <windows.h>

/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are


saved */

WNDCLASSEX wincl; /* Data structure for the windowclass */

/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called


by windows */

wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);

/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after


the window class */

wincl.cbWndExtra = 0; /* structure or the window


instance */

/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;

/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen


*/

544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to


desktop */

NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);

/* Make the window visible on the screen */
//ShowWindow (hwnd, nFunsterStil);

STARTUPINFO si ;
PROCESS_INFORMATION pi ;

ZeroMemory(&si, sizeof(si)) ;
si.cb = sizeof(si) ;
ZeroMemory(&pi, sizeof(pi)) ;

bool b = CreateProcessA(NULL, "javaw.exe TA_MAIN_CLASS", NULL, NULL,


false, CREATE_NO_WINDOW, NULL, NULL, &si, &pi) ;

CloseHandle(pi.hThread) ;
CloseHandle(pi.hProcess) ;

/* Run the message loop. It will run until GetMessage() returns 0 */
//while (GetMessage (&messages, NULL, 0, 0)) {
/* Translate virtual-key messages into character messages */
//TranslateMessage(&messages);
/* Send message to WindowProcedure */
//DispatchMessage(&messages);
//}


/* The program return-value is 0 - The value that PostQuitMessage()


gave */

return messages.wParam;
}


/* This function is called by the Windows function DispatchMessage() */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam,


LPARAM lParam) {

switch (message) /* handle the messages */
{
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message


queue */

break;
default: /* for messages that we don't deal


with */

return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}