int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow ) { HWND hWnd; MSG msg; WNDCLASSEX wndclass; // Init controls InitCommonControls(); // ... code classique // Creation de la fenetre hWnd = CreateWindow( "REGIONSTEST", "COUCOU", WS_POPUP|WS_CLIPCHILDREN, 0, 0, 640, 470, NULL, NULL, hInstance, NULL ); // Affiche la fenetre ShowWindow( hWnd, SW_SHOW ); UpdateWindow( hWnd ); // Boucle des messages while( GetMessage( &msg, NULL, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } return msg.wParam; }
long FAR PASCAL WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { static UINT s_uTimer, s_uTimerBlink; static HBITMAP s_hBmpCockpit, s_hBmpVolant, s_hBmpRadio, s_hBmpTdb, s_hBmpLight, s_hBmpRight; static int s_Chrono = 0; switch( message ) { case WM_CREATE : { s_TRight = FALSE; break; } // Dessin de la fenetre case WM_PAINT: { int b; int cxTitle, cyTitle; DWORD dwStyle; // On supprime MAX et MIN dwStyle = GetWindowLong( hWnd, GWL_STYLE ); dwStyle &= ~(WS_MINIMIZEBOX | WS_MAXIMIZEBOX); SetWindowLong( hWnd, GWL_STYLE , dwStyle ); // On charge le visage : On recupere les dims de l'img // et on cree une region elliptique s_hBmpCockpit = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_COCKPIT)); GetObject(s_hBmpCockpit, sizeof(s_bm), (LPSTR)&s_bm); cxTitle = GetSystemMetrics(SM_CXFRAME) + 1; cyTitle = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFIXEDFRAME) + 1; hRgnCockpit = BitmapToRegion (s_hBmpCockpit); // On transforme l'image en région s_hBmpTdb = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_TDB)); //à partir de WM_KEYDOWN, je charge le bon bitmap // le sélectionne le volant, la radio et la lumière if (Direction == 55) {s_hBmpVolant = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_VOLANTM50));} else if (Direction == 56) {s_hBmpVolant = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_VOLANTM40));} else if (Direction == 57) {s_hBmpVolant = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_VOLANTM30));} else if (Direction == 58) {s_hBmpVolant = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_VOLANTM20));} else if (Direction == 59) {s_hBmpVolant = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_VOLANTM10));} else if (Direction == 60) {s_hBmpVolant = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_VOLANT0));} else if (Direction == 61) {s_hBmpVolant = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_VOLANT10));} else if (Direction == 62) {s_hBmpVolant = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_VOLANT20));} else if (Direction == 63) {s_hBmpVolant = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_VOLANT30));} else if (Direction == 64) {s_hBmpVolant = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_VOLANT40));} else if (Direction == 65) {s_hBmpVolant = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_VOLANT50));} if (Radio%8 == 0) {s_hBmpRadio = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_RADIOE));} else if (Radio%8 == 1) {s_hBmpRadio = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_RADIO1));} else if (Radio%8 == 2) {s_hBmpRadio = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_RADIO2));} else if (Radio%8 == 3) {s_hBmpRadio = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_RADIO3));} else if (Radio%8 == 4) {s_hBmpRadio = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_RADIO4));} else if (Radio%8 == 5) {s_hBmpRadio = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_RADIO5));} else if (Radio%8 == 6) {s_hBmpRadio = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_RADIO6));} else if (Radio%8 == 7) {s_hBmpRadio = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_RADIO7));} if (Light) {s_hBmpLight = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_LIGHT));} else if (!Light) {s_hBmpLight = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_LIGHTE));} // là cela va faire l'objet de mon prochain post. if(s_TRight) {s_hBmpRight = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_TRIGHT));} else if(!s_TRight) { s_hBmpRight = LoadBitmap( GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_LIGHTE)); } // je transforme les bmp en regions hRgnTdb = CreateRectRgn( 0, 0, 0, 0); hRgnLight = CreateRectRgn( 0, 0, 0, 0); hRgnVolant = CreateRectRgn( 0, 0, 0, 0); hRgnRadio = CreateRectRgn( 0, 0, 0, 0); hRgnRight = CreateRectRgn( 0, 0, 0, 0); hRgnTdb = BitmapToRegion(s_hBmpTdb); hRgnLight = BitmapToRegion(s_hBmpLight); hRgnVolant = BitmapToRegion (s_hBmpVolant); hRgnRadio = BitmapToRegion (s_hBmpRadio); hRgnRight = BitmapToRegion (s_hBmpRight); hRgnTemp = CreateRectRgn( 0, 0, 0, 0); hrgnDest = CreateRectRgn( 0, 0, 0, 0); CombineRgn(hRgnTemp, hRgnTdb, hRgnLight, RGN_OR); // Lumière + TDB CombineRgn(hRgnTemp, hRgnTemp, hRgnCockpit, RGN_OR); // Cockpit + (Lumière + TDB) CombineRgn( hRgnTemp, hRgnTemp, hRgnVolant,RGN_OR ); // Volant + précédent CombineRgn( hrgnDest, hRgnRadio, hRgnTemp,RGN_OR ); // Radio + précédent CombineRgn( hrgnDest, hrgnDest, hRgnRight, RGN_OR); // cligno + précédent //je supprime les regions au fur et à mesure DeleteObject(hRgnTdb); DeleteObject(hRgnLight); DeleteObject(hRgnCockpit); DeleteObject(hRgnVolant); DeleteObject(hRgnRadio); DeleteObject(hRgnRight); DeleteObject(hRgnTemp); // Soit au final : b = SetWindowRgn( hWnd, hrgnDest, TRUE ); HDC hDC, hDCMem; HGDIOBJ hOld; PAINTSTRUCT ps; hDC = BeginPaint( hWnd, &ps ); // on empile les regions les unes sur les autres avec BitBlt hDCMem = CreateCompatibleDC(hDC); hOld = SelectObject( hDCMem, s_hBmpCockpit ); BitBlt( hDC, 0, 0, s_bm.bmWidth, s_bm.bmHeight, hDCMem, 0, 0, SRCCOPY ); hOld = SelectObject( hDCMem, s_hBmpTdb ); BitBlt( hDC, 0, 0, s_bm.bmWidth, s_bm.bmHeight, hDCMem, 0, 0, SRCPAINT ); hOld = SelectObject( hDCMem, s_hBmpLight ); BitBlt( hDC, 0, 0, s_bm.bmWidth, s_bm.bmHeight, hDCMem, 0, 0, SRCPAINT ); hOld = SelectObject( hDCMem, s_hBmpVolant ); BitBlt( hDC, 0, 0, s_bm.bmWidth, s_bm.bmHeight, hDCMem, 0, 0, SRCPAINT ); hOld = SelectObject( hDCMem, s_hBmpRadio ); BitBlt( hDC, 0, 0, s_bm.bmWidth, s_bm.bmHeight, hDCMem, 0, 0, SRCPAINT ); hOld = SelectObject( hDCMem, s_hBmpRight ); BitBlt( hDC, 0, 0, s_bm.bmWidth, s_bm.bmHeight, hDCMem, 0, 0, SRCPAINT ); SelectObject( hDCMem, hOld ); ReleaseDC( hWnd, hDCMem ); EndPaint( hWnd, &ps ); return 0L; } case WM_KEYDOWN: switch(wParam) { case VK_ESCAPE: //je quitte l'appli PostQuitMessage(0); break; case VK_RIGHT: //tourne à droite if (Direction >60){ s_uTimer = SetTimer( hWnd, ID_TIMER_RIGHT, 1000, NULL ); } Direction++; if (Direction >= 65) Direction = 65; break; case VK_LEFT: //tourne à gauche if (Direction < 59){ s_uTimerBlink = SetTimer( hWnd, ID_TIMER_LEFT, 1000, NULL ); } Direction--; if (Direction <= 55) Direction = 55; break; case (0x52): Radio++; break; case (0x4C): // lumière Light = !Light; break; case (0x45): // radio off Radio = 0; break; } InvalidateRect(hWnd, NULL, TRUE); // Gestion des clignotants case WM_TIMER: { switch (wParam) { case ID_TIMER_RIGHT: s_TRight = !s_TRight; InvalidateRect(hWnd, NULL, TRUE); return 0; case ID_TIMER_LEFT: s_TLeft = !s_TLeft; InvalidateRect(hWnd, NULL, TRUE); return 0; } break; } case WM_DESTROY : { // Restons propres KillTimer( hWnd, s_uTimer ); KillTimer(hWnd, s_uTimerBlink); // Fin PostQuitMessage( 0 ); return 0L; } } return DefWindowProc( hWnd, message, wParam, lParam ); }
// efface la région au BeginPaint ::InvalidateRgn( hWnd, hRgnClip, TRUE /*BOOL bErase*/ ); // Force Redraw ::RedrawWindow( hWnd, NULL, hRgnClip, // je ne suis pas sur de cette région par rapport à tn code RDW_INVALIDATE | RDW_UPDATENOW);
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question