01net    Web


Actuellement en ligne : 947 Utilisateurs dont 56 dans Programmation et développement >S'inscrire      >S'identifier      >Recherche      >Aide  
modéré par A.Ouloube, Beno@  
01net > Forum de 01net > Programmation et développement > C/C++
> Application win 32
Auteur
Message
 
<     1       >
Kotton
  
  :-)
      ?   ^   @     Posté le 07/08/2006 16:29:40  
Voter pour ce message
Bonjour,

J'ai pu créer un programme qui fonctionne avec la console de commande et j'aurai amié pouvoir l'untiliser via une application win 32?

J'uilise MS Visual c++.
J'ai donc créer un nouveau projet "Win 32 application" et ensuite jai choisi le type " Typical Hello World application".

Je me retrouve donc avec plusieurs fichier dont le fichier .cpp suivant


#include "stdafx.h"
#include "resource.h"

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text

// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;

// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_CALCULATRICEWIN, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_CALCULATRICEWIN);

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return msg.wParam;
}



//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage is only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_CALCULATRICEWIN);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCSTR)IDC_CALCULATRICEWIN;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

return RegisterClassEx(&wcex);
}

//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;

hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}

ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

return TRUE;
}

//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);

switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}




Mon problème est que je n'arrive pas a inserer correctement mon programme pour le transformer en application windows!

Est-ce simplement possible?Et si oui comment?

Merci d'avance.
Beno@
  
  :-)
      ?   @     Posté le 07/08/2006 19:50:44  
Voter pour ce message
si ton programme marche en console, il suffit de le mettre dans un fichier txt et de le renommer en fichier.bat ;)
icare_olivier
  arriere, band de newbies ^^
  :-)
      ?   @     Posté le 07/08/2006 22:36:38  
Voter pour ce message
.bat ? faudra qu'on me dise quel est le rapport entre le C++ et le batch ??? mdr .....
-->Message édité par icare_olivier le 07/08/2006 22:37:00<--
Beno@
  
  :-)
      ?   @     Posté le 08/08/2006 10:40:59  
Voter pour ce message
pas de rapport entre le c++ mais je crois que son programme est composés de commandes windows nan?

il a pas dit que c'etait un truc en console windows?
Beno@
  
  :-)
      ?   @     Posté le 08/08/2006 10:42:11  
Voter pour ce message
merde je crois que j'ai mal compris, je croyais que c'etait des commandes windows en fait il veut mettre son programme dans une fenetre de style windows XP :S

parce que via une application win32 ca veut pas dire ca :/
icare_olivier
  arriere, band de newbies ^^
  :-)
      ?   @     Posté le 08/08/2006 16:34:39  
Voter pour ce message
Pour répondre a la question de départ, ca dépend ce que fait ton code! il nessesite des entrées clavier??? il a des sorties ??
La procédure wndProc est appelée a chaque fois qu'un évènement arrive à la fenetre que tu aurras créé dans winmain. (entrée clavier, redimensionement, etc ) c'est donc la que tu devras gérer tes inputs et outputs.

Le code du programme, le point d'entrée proprement dit, c'est winmain...

Pour savoir ou insérer ton code, et comment le modifier pour qil marche, encore faudrait il savoir ce qu'il fait ^^
Kotton
  
  :-)
      ?   ^   @     Posté le 08/08/2006 18:47:44  
Voter pour ce message
Mon code est le suivant :



#include <stdio.h>
#include <math.h>

main()


{

long double A1, A2, A0;
int Choix, Again;

Choix=0;
A1=0;
A2=0;
A0=0;
Again=0;

do

{

{

printf("\nQue veux-tu faire\?\n\n 1 Somme\n 2 Soustraction\n 3 Produit\n 4 Division\n\n");
scanf("%d",&Choix);

}

/* Somme */

if (Choix==1)

{

puts("\nPremier nombre\n");
scanf("%lf",&A1);

puts("\nDeuxieme nombre\n");
scanf("%lf",&A2);

A0 = A1 + A2;

printf("\nResultat A= %f\n", A0);
}

/* Soustraction */

else if (Choix==2)

{
puts("\nPremier nombre\n");
scanf("%lf",&A1);

puts("\nDeuxieme nombre\n");
scanf("%lf",&A2);

A0 = A1 - A2;

printf("\nResultat A= %f\n", A0);
}

/* Produit */

else if (Choix==3)

{
puts("\nPremier nombre\n");
scanf("%lf",&A1);

puts("\nDeuxieme nombre\n");
scanf("%lf",&A2);

A0 = A1 * A2;

printf("\nResultat A= %f\n", A0);
}

/* Division*/

else if (Choix==4)

{
puts("\nPremier nombre\n");
scanf("%lf",&A1);

puts("\nDeuxieme nombre\n");
scanf("%lf",&A2);
A0 = A1 / A2;

printf("\nResultat A= %f\n", A0);
}

/* Autre */

else

{
puts("\nPfff t'es vraiment une quiche\n");

}

{


puts("\nHum ca te plait! Tu en veux encore \?\n\n 1 - Oui\n 2 - Non\n");
scanf("%d",&Again);

}

}

while (Again==1);

system("pause");
return 0;
}


Il s'agit d'un programme de calcul (un peu compliqué certes mais fonctionnel je suis en train de chercher a faire le meme a base de switch).

Et comme le dit Beno@ je voudrait l'integrer dans une fenetre de style XP.
icare_olivier
  arriere, band de newbies ^^
  :-)
      ?   @     Posté le 10/08/2006 16:44:35  
Voter pour ce message
heuuuh ... ben faut que tu te mettes à l'api windows ^^
mais ya pas moyen de faire copier coller pour un programme comme ca!
Kotton
  
  :-)
      ?   ^   @     Posté le 11/08/2006 16:15:16  
Voter pour ce message
Ok merci je vais essayer d'en apprendre encore un peu alors. ;)
<     1       >

01net > Forum de 01net > Programmation et développement > C/C++
> Application win 32

Aller à :

Page générée en : 0.203s - X2board 2.2

Nous contacter | Charte de confiance | Voir notice légale

Tous droits réservés © 1999 - 2008 Groupe Tests - 01net.


Sites du réseau 01net Network : 01net - 01men - Rmc.fr - Bfmtv.fr - Radiobfm.com - TousLesPodcasts - Micro Achat

Calendrier
Réalisez de A à Z des calendriers originaux pour partager les grands moments !
Jeux
Nouveauté : Alignez les trophées et gagnez de l’argent à chaque exploit réalisé.