Accueil > > > FENETRE NON RECTANGULAIRE (WIN32)
FENETRE NON RECTANGULAIRE (WIN32)
Information sur la source
Description
Façon la plus simple de créer une fenêtre non rectangulaire à l'aide d'un bmp et de la transparence. Le prog tourne uniquement sur windows 2000 ou supérieur! C'est testé au lancement (merci BruNews). Touche Echap pour quitter. Codé en C/WIN32, compilé sous VS.NET 2003, testé sous XP.
Source
- #define _WIN32_WINNT 0x0500
- #include <windows.h>
- #include "resource.h"
-
- HBITMAP hBmp = 0;
- HINSTANCE hInst = 0;
- SIZE SizeBmp = {128, 128};
- char szAppName[] = "BmpPerso";
-
- LRESULT CALLBACK AppWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- switch(uMsg) {
- case WM_CREATE:
- hBmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BMP));
- SetLayeredWindowAttributes(hWnd, RGB(255, 0, 255), 0, LWA_COLORKEY);
- return 0;
- case WM_ERASEBKGND: {
- HDC hDC, hMemDC;
- HBITMAP hOldBmp;
- hDC = (HDC)wParam;
- if(hBmp) {
- hMemDC = CreateCompatibleDC(hDC);
- hOldBmp = (HBITMAP)SelectObject(hMemDC, hBmp);
- BitBlt(hDC, 0, 0, SizeBmp.cx, SizeBmp.cy, hMemDC, 0, 0, SRCCOPY);
- SelectObject(hMemDC, hOldBmp);
- DeleteDC(hMemDC);
- }
- }
- return 1;
- case WM_NCHITTEST:
- return HTCAPTION;
- case WM_KEYDOWN:
- if(wParam == VK_ESCAPE) PostMessage(hWnd, WM_CLOSE, 0, 0);
- return 0;
- case WM_DESTROY:
- DeleteObject(hBmp);
- PostQuitMessage(0);
- return 0;
- }
- return DefWindowProc(hWnd, uMsg, wParam, lParam);
- }
-
- int InitInstance()
- {
- WNDCLASSEX wclsx;
- wclsx.cbSize = sizeof(WNDCLASSEX);
- wclsx.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
- wclsx.lpfnWndProc = AppWndProc;
- wclsx.cbClsExtra = 0;
- wclsx.cbWndExtra = 0;
- wclsx.hInstance = hInst;
- wclsx.hIcon = 0;
- wclsx.hCursor = LoadCursor(NULL, IDC_ARROW);
- wclsx.hbrBackground = 0;
- wclsx.lpszMenuName = 0;
- wclsx.lpszClassName = szAppName;
- wclsx.hIconSm = 0;
- return RegisterClassEx(&wclsx);
- }
-
- DWORD VerifWin2KMini()
- {
- OSVERSIONINFO osvi;
- osvi.dwPlatformId = osvi.dwMajorVersion = 0;
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- GetVersionEx(&osvi);
- if(osvi.dwPlatformId != VER_PLATFORM_WIN32_NT) return 0;
- return (osvi.dwMajorVersion >= 5);
- }
-
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, int)
- {
- MSG msg;
- if(!VerifWin2KMini()) return 0;
- hInst = hInstance;
- if(!InitInstance()) return 0;
- HWND hWnd = CreateWindowEx(WS_EX_LAYERED, szAppName, szAppName,
- WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS,
- CW_USEDEFAULT, CW_USEDEFAULT, SizeBmp.cx, SizeBmp.cy,
- 0, 0, hInst, 0);
- ShowWindow(hWnd, SW_SHOW); UpdateWindow(hWnd);
- while(GetMessage(&msg, NULL, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return msg.wParam;
- }
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include "resource.h"
HBITMAP hBmp = 0;
HINSTANCE hInst = 0;
SIZE SizeBmp = {128, 128};
char szAppName[] = "BmpPerso";
LRESULT CALLBACK AppWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) {
case WM_CREATE:
hBmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BMP));
SetLayeredWindowAttributes(hWnd, RGB(255, 0, 255), 0, LWA_COLORKEY);
return 0;
case WM_ERASEBKGND: {
HDC hDC, hMemDC;
HBITMAP hOldBmp;
hDC = (HDC)wParam;
if(hBmp) {
hMemDC = CreateCompatibleDC(hDC);
hOldBmp = (HBITMAP)SelectObject(hMemDC, hBmp);
BitBlt(hDC, 0, 0, SizeBmp.cx, SizeBmp.cy, hMemDC, 0, 0, SRCCOPY);
SelectObject(hMemDC, hOldBmp);
DeleteDC(hMemDC);
}
}
return 1;
case WM_NCHITTEST:
return HTCAPTION;
case WM_KEYDOWN:
if(wParam == VK_ESCAPE) PostMessage(hWnd, WM_CLOSE, 0, 0);
return 0;
case WM_DESTROY:
DeleteObject(hBmp);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
int InitInstance()
{
WNDCLASSEX wclsx;
wclsx.cbSize = sizeof(WNDCLASSEX);
wclsx.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wclsx.lpfnWndProc = AppWndProc;
wclsx.cbClsExtra = 0;
wclsx.cbWndExtra = 0;
wclsx.hInstance = hInst;
wclsx.hIcon = 0;
wclsx.hCursor = LoadCursor(NULL, IDC_ARROW);
wclsx.hbrBackground = 0;
wclsx.lpszMenuName = 0;
wclsx.lpszClassName = szAppName;
wclsx.hIconSm = 0;
return RegisterClassEx(&wclsx);
}
DWORD VerifWin2KMini()
{
OSVERSIONINFO osvi;
osvi.dwPlatformId = osvi.dwMajorVersion = 0;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
if(osvi.dwPlatformId != VER_PLATFORM_WIN32_NT) return 0;
return (osvi.dwMajorVersion >= 5);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, int)
{
MSG msg;
if(!VerifWin2KMini()) return 0;
hInst = hInstance;
if(!InitInstance()) return 0;
HWND hWnd = CreateWindowEx(WS_EX_LAYERED, szAppName, szAppName,
WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS,
CW_USEDEFAULT, CW_USEDEFAULT, SizeBmp.cx, SizeBmp.cy,
0, 0, hInst, 0);
ShowWindow(hWnd, SW_SHOW); UpdateWindow(hWnd);
while(GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
Historique
- 27 février 2005 16:30:18 :
- - Modification mineure grâce au commentaire de Boing (merci à lui).
- 07 mars 2005 22:51:21 :
- - Dernière mise à jour (voir le commentaire de Boing pour les détails).
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
[HTML5] AUTOUR DU W3C : NOUVEAUX STANDARDS ET WEB MOBILE (LILLE)[HTML5] AUTOUR DU W3C : NOUVEAUX STANDARDS ET WEB MOBILE (LILLE) par Gio
Je m'y prends un peu tard je sais, mais bon je suis développeur web et donc hyper fainéant ! Toujours dans le cadre des technologies émergentes, ici HTML5, parce qu'on aime HTML5 chez Wyg , nous seront présent, le vieux ( Aurélien V.) et moi, pour pr...
Cliquez pour lire la suite de l'article par Gio [WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier
Logiciels
Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning
|