begin process at 2012 05 24 03:36:02
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Api Windows

 > OBTENIR RGB PIXEL

OBTENIR RGB PIXEL


 Information sur la source

Note :
8 / 10 - par 1 personne
8,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Api Windows Niveau :Débutant Date de création :28/12/2004 Vu / téléchargé :4 509 / 236

Auteur : AlexMAN

Ecrire un message privé
Commentaire sur cette source (1)
Ajouter un commentaire et/ou une note

 Description

Cliquez pour voir la capture en taille normale
Bonsoir,

C'est simplement un tooltip qui 'suit' le curseur de la souris et qui indique la couleur, sous la forme RGB, du pixel se trouvant sous le curseur.
Le projet en C est fourni pour que vous puissiez suivre si vous ne comprenez pas tout.

Source

  • .386
  • .model flat, stdcall
  • option casemap:none
  • include \masm32\include\windows.inc
  • include \masm32\include\user32.inc
  • include \masm32\include\kernel32.inc
  • ;include \masm32\include\masm32.inc
  • include \masm32\include\comctl32.inc
  • include \masm32\include\gdi32.inc
  • includelib \masm32\lib\user32.lib
  • includelib \masm32\lib\kernel32.lib
  • ;includelib \masm32\lib\masm32.lib
  • includelib \masm32\lib\comctl32.lib
  • includelib \masm32\lib\gdi32.lib
  • .data
  • hInst dd 0
  • htt dd 0
  • iWidthScreen dd 0
  • TOOLTIPS_CLASS db "tooltips_class32", 0
  • szRGB db 256 dup(0)
  • .code
  • start:
  • call InitCommonControls
  • push 0
  • call GetModuleHandle
  • mov hInst, eax
  • push 512
  • push GPTR
  • call GlobalAlloc
  • push eax ;Param pour GlobalFree
  • mov edx, WS_POPUP
  • or edx, WS_CAPTION
  • or edx, WS_SYSMENU
  • xor ecx, ecx
  • mov [eax], edx ; style
  • mov word ptr[eax + 10], 0 ; x et y
  • mov word ptr[eax + 12], 0
  • mov word ptr[eax + 14], 50 ; cx et cy
  • mov word ptr[eax + 16], 50
  • mov edx, hInst
  • push ecx
  • push offset DlgProc
  • push ecx
  • push eax
  • push edx
  • call DialogBoxIndirectParam
  • call GlobalFree
  • push 0
  • call ExitProcess
  • DlgProc PROC
  • mov eax, [esp + 8]
  • cmp eax, WM_INITDIALOG
  • je onDialog
  • cmp eax, WM_COMMAND
  • je onCmd
  • cmp eax, WM_NOTIFY
  • je onNotify
  • cmp eax, WM_TIMER
  • je onTimer
  • jmp Fin
  • ;ESP => hwnd (HWND) 4 octets
  • ;ESP + 4 => htt (HWND) 4 octets
  • ;ESP + 8 => ti (TOOLINFO) 44 octets
  • onDialog:
  • mov eax, offset szRGB
  • mov dword ptr[eax], 28424752h ;'RGB('
  • mov ecx, [esp + 4] ;hwnd
  • lea eax, [esp - 48]
  • mov esp, eax
  • mov [eax], ecx
  • xor eax, eax
  • push eax
  • mov edx, hInst
  • push edx
  • push eax
  • push ecx
  • push CW_USEDEFAULT
  • push CW_USEDEFAULT
  • push CW_USEDEFAULT
  • push CW_USEDEFAULT
  • mov edx, WS_POPUP
  • or edx, TTS_NOPREFIX
  • or edx, TTS_ALWAYSTIP
  • push edx
  • push eax
  • push offset TOOLTIPS_CLASS
  • push WS_EX_TOPMOST
  • call CreateWindowEx
  • test eax, eax
  • je FinOnDialog
  • mov htt, eax
  • lea ecx, [esp + 4]
  • mov dword ptr[ecx], 44 ;ti.cbSize
  • mov edx, TTF_IDISHWND
  • or edx, TTF_TRACK
  • or edx, TTF_ABSOLUTE
  • mov [ecx + 4], edx ;ti.uFlags
  • mov [ecx + 12], eax ;ti.uID
  • mov edx, hInst
  • mov [ecx + 32], edx ;ti.hInst
  • mov edx, [ecx - 4] ;hwnd (handle de la fenetre)
  • mov [ecx + 8], edx ;ti.hwnd
  • mov dword ptr[ecx + 36], LPSTR_TEXTCALLBACK ;ti.lpsztext
  • push 0
  • push 10
  • push 1712
  • push edx ;SetTimer
  • push ecx
  • push 1
  • push TTM_TRACKACTIVATE
  • push eax ;2eme SendMessage
  • push ecx
  • push 0
  • push TTM_ADDTOOL
  • push eax ;1er SendMessage
  • call SendMessage
  • call SendMessage
  • call SetTimer
  • push SM_CXSCREEN
  • call GetSystemMetrics
  • mov iWidthScreen, eax
  • FinOnDialog:
  • add esp, 48
  • mov eax, 1
  • ret 16
  • ;ESP => hwnd (HWND) 4 octets
  • ;ESP + 4 => pt (POINT) 8 octets
  • ;ESP + 12 => hdcScr (HDC) 4 octets
  • ;ESP + 16 => clrPixel (COLORREF)4 octets
  • ;ESP + 20 => szRGB (char *) 20 octets
  • onTimer:
  • mov eax, [esp + 4]
  • lea ecx, [esp - 40]
  • mov esp, ecx
  • mov [ecx], eax ;sauve hwnd
  • lea eax, [ecx + 4]
  • push eax
  • call GetCursorPos
  • push 0
  • call GetDC
  • lea ecx, [esp + 4]
  • mov [ecx + 8], eax ;sauve hdcScr
  • push [ecx + 4]
  • push [ecx]
  • push eax
  • call GetPixel
  • lea ecx, [esp]
  • mov [ecx + 16], eax ;sauve clrPixel
  • mov edx, [ecx + 12] ;hdcScr
  • mov eax, [ecx] ;hwnd
  • push edx
  • push eax
  • call ReleaseDC
  • ;'Creation' chaine szRGB
  • lea edx, [esp + 16] ;clrPixel
  • movzx eax, byte ptr[edx]; GetRValue
  • mov ecx, offset szRGB
  • add ecx, 4 ;saute 'RGB('
  • call ultoa
  • mov byte ptr[eax], ','
  • add eax, 1
  • lea edx, [esp + 16]
  • mov ecx, eax
  • movzx eax, byte ptr[edx + 1] ;GetGValue
  • call ultoa
  • mov byte ptr[eax], ','
  • add eax, 1
  • lea edx, [esp + 16]
  • mov ecx, eax
  • movzx eax, byte ptr[edx + 2] ;GetBValue
  • call ultoa
  • mov byte ptr[eax], ')'
  • add eax, 1
  • mov byte ptr[eax], 0
  • lea eax, [esp + 4]
  • mov ecx, [eax] ;pt.x
  • mov edx, [eax + 4] ;pt.y
  • add ecx, 110
  • cmp ecx, iWidthScreen
  • jg Sub210
  • sub ecx, 100
  • jmp MakeLParam
  • Sub210:
  • sub ecx, 210
  • MakeLParam:
  • mov eax, edx
  • shl eax, 16
  • or eax, ecx
  • mov edx, htt
  • push eax
  • push 0
  • push TTM_TRACKPOSITION
  • push edx
  • call SendMessage
  • xor eax, eax
  • add esp, 40
  • ret 16
  • onCmd:
  • mov eax, [esp + 12]
  • cmp eax, IDCANCEL
  • jne Fin
  • mov ecx, [esp + 4]
  • push 0
  • push ecx ;hwnd pour EndDialog
  • push 1712
  • push ecx
  • call KillTimer
  • call EndDialog
  • xor eax, eax
  • ret 16
  • onNotify:
  • mov eax, [esp + 16] ; eax == lparam
  • mov ecx, [eax + 8] ; ecx == lparam->code
  • cmp ecx, TTN_GETDISPINFO
  • jne Fin
  • mov [eax + 12], offset szRGB
  • Fin:
  • xor eax, eax
  • ret 16
  • DlgProc ENDP
  • ;FONCTION BRUNEWS
  • ultoa PROC ; IN:EAX=dwNbr, ECX=lpsz
  • test eax, eax
  • jnz short L1
  • lea eax, [ecx+1]
  • mov byte ptr[ecx], 48
  • mov byte ptr[eax], 0
  • ret 0
  • L1:
  • mov [esp-4], edi
  • mov [esp-8], ecx
  • mov edi, ecx
  • mov ecx, eax
  • L2:
  • mov eax, -858993459
  • mul ecx
  • mov eax, edx
  • shr eax, 3
  • mov edx, ecx
  • lea ecx, [eax+eax*8]
  • add ecx, eax
  • sub edx, ecx
  • add dl, 48
  • mov [edi], dl
  • mov ecx, eax
  • inc edi
  • test eax, eax
  • jnz short L2
  • mov [esp-12], edi
  • mov eax, [esp-8]
  • mov byte ptr[edi], 0
  • L3:
  • dec edi
  • mov dl, [eax]
  • mov cl, [edi]
  • mov [edi], dl
  • mov [eax], cl
  • inc eax
  • cmp eax, edi
  • jb short L3
  • mov eax, [esp-12]
  • mov edi, [esp-4]
  • ret 0
  • ultoa ENDP
  • END start
.386
.model flat, stdcall
option casemap:none

include		\masm32\include\windows.inc
include		\masm32\include\user32.inc
include		\masm32\include\kernel32.inc
;include		\masm32\include\masm32.inc
include 	\masm32\include\comctl32.inc
include 	\masm32\include\gdi32.inc
 
includelib	\masm32\lib\user32.lib
includelib	\masm32\lib\kernel32.lib
;includelib	\masm32\lib\masm32.lib
includelib  \masm32\lib\comctl32.lib
includelib  \masm32\lib\gdi32.lib

.data

hInst               dd  0
htt                 dd  0
iWidthScreen        dd  0
TOOLTIPS_CLASS      db  "tooltips_class32", 0
szRGB               db  256 dup(0)

.code

start:
  call  InitCommonControls
  push  0
  call  GetModuleHandle
  mov   hInst, eax
  push  512
  push  GPTR
  call  GlobalAlloc
  push  eax                       ;Param pour GlobalFree
  mov   edx, WS_POPUP 
  or    edx, WS_CAPTION 
  or    edx, WS_SYSMENU
  xor   ecx, ecx
  mov   [eax], edx                    ; style
  mov   word ptr[eax + 10], 0         ; x et y
  mov   word ptr[eax + 12], 0
  mov   word ptr[eax + 14], 50        ; cx et cy
  mov   word ptr[eax + 16], 50
  mov   edx, hInst
  push  ecx
  push  offset DlgProc
  push  ecx
  push  eax
  push  edx
  call  DialogBoxIndirectParam
  call  GlobalFree
  push  0
  call  ExitProcess
  
DlgProc   PROC
  mov   eax, [esp + 8]
  cmp   eax, WM_INITDIALOG
  je    onDialog
  cmp   eax, WM_COMMAND
  je    onCmd
  cmp   eax, WM_NOTIFY
  je    onNotify
  cmp   eax, WM_TIMER
  je    onTimer
  jmp   Fin  
  ;ESP     => hwnd  (HWND)      4  octets
  ;ESP + 4 => htt   (HWND)      4  octets
  ;ESP + 8 => ti    (TOOLINFO)  44 octets
onDialog:
  mov   eax, offset szRGB
  mov   dword ptr[eax], 28424752h ;'RGB('
  mov   ecx, [esp + 4]    ;hwnd
  lea   eax, [esp - 48]
  mov   esp, eax
  mov   [eax], ecx
  xor   eax, eax
  push  eax
  mov   edx, hInst
  push  edx
  push  eax
  push  ecx
  push  CW_USEDEFAULT
  push  CW_USEDEFAULT
  push  CW_USEDEFAULT
  push  CW_USEDEFAULT
  mov   edx, WS_POPUP
  or    edx, TTS_NOPREFIX
  or    edx, TTS_ALWAYSTIP
  push  edx
  push  eax
  push  offset TOOLTIPS_CLASS
  push  WS_EX_TOPMOST
  call  CreateWindowEx
  test  eax, eax
  je    FinOnDialog
  mov   htt, eax
  lea   ecx, [esp + 4]
  mov   dword ptr[ecx], 44    ;ti.cbSize
  mov   edx, TTF_IDISHWND 
  or    edx, TTF_TRACK 
  or    edx, TTF_ABSOLUTE
  mov   [ecx + 4], edx        ;ti.uFlags
  mov   [ecx + 12], eax       ;ti.uID
  mov   edx, hInst      
  mov   [ecx + 32], edx       ;ti.hInst
  mov   edx, [ecx - 4]        ;hwnd (handle de la fenetre)
  mov   [ecx + 8], edx        ;ti.hwnd
  mov   dword ptr[ecx + 36], LPSTR_TEXTCALLBACK ;ti.lpsztext
  push  0
  push  10
  push  1712
  push  edx               ;SetTimer
  push  ecx       
  push  1
  push  TTM_TRACKACTIVATE
  push  eax               ;2eme SendMessage
  push  ecx
  push  0
  push  TTM_ADDTOOL
  push  eax               ;1er SendMessage
  call  SendMessage       
  call  SendMessage
  call  SetTimer
  push  SM_CXSCREEN
  call  GetSystemMetrics
  mov   iWidthScreen, eax
FinOnDialog:
  add   esp, 48
  mov   eax, 1
  ret   16  
  ;ESP      => hwnd     (HWND)    4 octets
  ;ESP + 4  => pt       (POINT)   8 octets
  ;ESP + 12 => hdcScr   (HDC)     4 octets
  ;ESP + 16 => clrPixel (COLORREF)4 octets
  ;ESP + 20 => szRGB    (char *)  20 octets
onTimer:
  mov   eax, [esp + 4]
  lea   ecx, [esp - 40]
  mov   esp, ecx
  mov   [ecx], eax  ;sauve hwnd
  lea   eax, [ecx + 4]
  push  eax
  call  GetCursorPos
  push  0
  call  GetDC
  lea   ecx, [esp + 4]
  mov   [ecx + 8], eax    ;sauve hdcScr
  push  [ecx + 4]
  push  [ecx]
  push  eax
  call  GetPixel
  lea   ecx, [esp]
  mov   [ecx + 16], eax        ;sauve clrPixel
  mov   edx, [ecx + 12]   ;hdcScr
  mov   eax, [ecx]        ;hwnd
  push  edx
  push  eax
  call  ReleaseDC  
  ;'Creation' chaine szRGB
  lea   edx, [esp + 16]   ;clrPixel
  movzx eax, byte ptr[edx]; GetRValue
  mov   ecx, offset szRGB
  add   ecx, 4            ;saute 'RGB('
  call  ultoa
  mov   byte ptr[eax], ','
  add   eax, 1
  lea   edx, [esp + 16]
  mov   ecx, eax
  movzx eax, byte ptr[edx + 1] ;GetGValue
  call  ultoa
  mov   byte ptr[eax], ','
  add   eax, 1
  lea   edx, [esp + 16]
  mov   ecx, eax
  movzx eax, byte ptr[edx + 2] ;GetBValue
  call  ultoa  
  mov   byte ptr[eax], ')'
  add   eax, 1
  mov   byte ptr[eax], 0
  lea   eax, [esp + 4]
  mov   ecx, [eax]        ;pt.x
  mov   edx, [eax + 4]    ;pt.y
  add   ecx, 110
  cmp   ecx, iWidthScreen
  jg    Sub210
  sub   ecx, 100
  jmp   MakeLParam
Sub210:
  sub   ecx, 210
MakeLParam:
  mov   eax, edx
  shl   eax, 16
  or    eax, ecx
  mov   edx, htt
  push  eax
  push  0
  push  TTM_TRACKPOSITION
  push  edx
  call  SendMessage
  xor   eax, eax
  add   esp, 40
  ret   16
onCmd:
  mov   eax, [esp + 12]
  cmp   eax, IDCANCEL
  jne   Fin
  mov   ecx, [esp + 4]
  push  0
  push  ecx        ;hwnd pour EndDialog
  push  1712
  push  ecx
  call  KillTimer
  call  EndDialog
  xor   eax, eax
  ret   16
onNotify:
  mov   eax, [esp + 16]   ; eax == lparam
  mov   ecx, [eax + 8]    ; ecx == lparam->code
  cmp   ecx, TTN_GETDISPINFO
  jne   Fin
  mov   [eax + 12], offset szRGB
Fin:
  xor   eax, eax
  ret   16
DlgProc ENDP
      
;FONCTION BRUNEWS
ultoa PROC ; IN:EAX=dwNbr, ECX=lpsz
  test     eax, eax
	jnz      short L1
	lea      eax, [ecx+1]
	mov      byte ptr[ecx], 48
	mov      byte ptr[eax], 0
	ret      0
L1:
	mov      [esp-4], edi
	mov      [esp-8], ecx
	mov      edi, ecx
	mov      ecx, eax
L2:
 	mov      eax, -858993459
 	mul      ecx
 	mov      eax, edx
 	shr      eax, 3
 	mov      edx, ecx
 	lea      ecx, [eax+eax*8]
 	add      ecx, eax
 	sub      edx, ecx
 	add      dl, 48
 	mov      [edi], dl
 	mov      ecx, eax
 	inc      edi
  test     eax, eax
  jnz      short L2
	mov      [esp-12], edi
  mov      eax, [esp-8]
  mov      byte ptr[edi], 0
L3:
 	dec      edi
 	mov      dl, [eax]
 	mov      cl, [edi]
 	mov      [edi], dl
 	mov      [eax], cl
 	inc      eax
 	cmp      eax, edi
 	jb       short L3
 	mov      eax, [esp-12]
 	mov      edi, [esp-4]
 	ret      0
ultoa ENDP
  
END start
  
  
	

 Conclusion

Je mettrai a jour le code plus tard pour rectifier certains trucs qui ne doivent pas aller.

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
  • GetColor.zipTélécharger ce fichier [Réservé aux membres club]30 015 octets
  • RGB.AsmTélécharger ce fichier [Réservé aux membres club]Voir ce fichier6 325 octets
  • RGB.exeTélécharger ce fichier [Réservé aux membres club]4 096 octets

Télécharger le zip


 Sources de la même categorie

Source avec Zip Source avec une capture BODY_ROTATION BASÉ SUR LE TRAVAIL DE TOM par jose2pepe
Source avec Zip Source avec une capture FROM TOM'S CUBE_ROTATION AND CUBE_5 CUBE COLOR RENDERIZED par jose2pepe
Source avec Zip REUTILISER N'IMPORTE QUEL PROGRAMME EX:WORDPAD par ToutEnMasm
Source avec Zip CRÉER DES TABLEAUX DE DONNÉES DE MANIÈRE DYNAMIQUE par ToutEnMasm
Source avec Zip AFFICHAGE DATE ET HEURE AVEC DES BITMAPS par jejamar

Commentaires et avis

Commentaire de Alain Proviste le 30/12/2004 18:34:39 administrateur CS

ah oui quand même.
je pense que tu vas m'aider.
:D

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,546 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales