by_rabbit_08
Messages postés
109
Date d'inscription
vendredi 8 avril 2005
Statut
Membre
Dernière intervention
15 mai 2007
1
6 sept. 2006 à 18:51
J'ai donc essayé de réaliser ceci, dans un code de base. J'ai simplement pris l'exemple de base d'un fenêtre sans rien, je lui ai rajouté un edit avec CreateWindowEx et j'ai également ajouté un bouton. J'ai ensuite essayé d'adapter mon code sous différentes façons, et j'ai obtenu ceci avec la méthode de Joky, où il y avait un exemple un peu plus concret:
#include <windows.h>
#define EDIT 101
#define BOUTON 102
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";
HWND edit, bouton;
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl))
return 0;
hwnd = CreateWindowEx (
0,
szClassName,
"Windows App",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
544,
375,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
edit = CreateWindowEx (
WS_EX_OVERLAPPEDWINDOW,
"EDIT",
"",
WS_VISIBLE|WS_CHILD|ES_AUTOHSCROLL|ES_NOHIDESEL,
10,
10,
100,
20,
hwnd,
(HMENU)EDIT,
hThisInstance,
NULL
);
bouton = CreateWindowEx (
0,
"BUTTON",
"Valider",
WS_VISIBLE|WS_CHILD,
10,
35,
100,
20,
hwnd,
(HMENU)BOUTON,
hThisInstance,
NULL
);
ShowWindow (hwnd, nFunsterStil);
UpdateWindow(hwnd);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
WNDPROC wOldProc;
LRESULT CALLBACK EditProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
char szTxt[255];
switch(message)
{
case WM_CHAR:
if(lParam == VK_RETURN)
{
GetWindowText(edit, szTxt, 255);
MessageBox(hwnd, szTxt, "szAppName", 0x40);
}
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_CREATE: //WM_INITDIALOG:
wOldProc = (WNDPROC)SetWindowLong(GetDlgItem(hwnd, EDIT), GWL_WNDPROC, (LONG)EditProc);
return 0;
}
return DefWindowProc(hwnd, Msg, wParam, lParam);
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
Malheureusement cela ne marche pas mieu... Est-ce que vous auriez des informations complémentaire? Quelque chose que je devrais modifier dans mon code?
Merci d'avance!
By_rabbit_08