|
Bonjour
Je voudrais coder un programme avec Dev-c++ qui, apres ouverture d'une fenetre, a chaque clic de la souris dessine sur la fenetre un point et unpetit rectangle l'entourant places aux coordonnees du point cliqué.voici mon code:
#include <windows.h> #include <iostream>
using namespace std;
HINSTANCE hinst; POINT pt;
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hwnd; MSG msg; WNDCLASS wc;
hinst = hinstance;
wc.style = 0 ; wc.lpfnWndProc = MainWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = NULL; wc.hIcon = NULL; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = "MaWinClass";
if(!RegisterClass(&wc)) return FALSE;
hwnd = CreateWindow("MaWinClass", "Titre", WS_OVERLAPPEDWINDOW, 100,100, 400, 300, NULL, NULL, hinstance, NULL); if (!hwnd) return FALSE;
ShowWindow(hwnd, nCmdShow);
while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }
/******************************************************************************/
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { static HWND hEdit; static int x,y;
switch (uMsg) {
case WM_PAINT :
{ cout<<"PAINT x = "<<x<<" y = "<<y<<endl;//verification des coordonnees PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); SetPixel(hdc,x,y,RGB(0,0,0)); cout<<"TRACE CENTRE x = "<<x<<" y = "<<y<<endl;//verification trace Rectangle(hdc,x-4,y-4,x+4,y+4); cout<<"FIN TRACE x = "<<x<<" y = "<<y<<endl;//verification trace EndPaint(hwnd,&ps);
return 0; }
case WM_LBUTTONDOWN: { x=(int)LOWORD(lParam); y=(int)HIWORD(lParam); Sleep (500); PostMessage(hwnd,WM_PAINT,wParam, lParam); return 0; } case WM_DESTROY: PostQuitMessage(0); return 0;
default: return DefWindowProc(hwnd, uMsg, wParam, lParam); } }
L'execution me donne la fenetre et 1/4 de rectangle aux coordonnees 0,0. Puis plus rien,comme s'il était impossible de redessiner sur la fenetre apres la premiere execution de WM_PAINT.Pourtant les points de controle que j'ai places donnent de bonx resultats.
Merci de m'aider.
|