Win32 - WM_PAINT and 'Button Windows'

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2008
Posts: 45
Reputation: Icebone1000 is an unknown quantity at this point 
Solved Threads: 0
Icebone1000's Avatar
Icebone1000 Icebone1000 is offline Offline
Light Poster

Win32 - WM_PAINT and 'Button Windows'

 
0
  #1
Aug 2nd, 2009
I cant figure out how make the Button visible proccessing WM_PAINT myself, it just get visible after pressing it..


  1.  
  2. //THE WM_PAINT message:
  3.  
  4. case WM_PAINT:{
  5.  
  6. RECT myrect;
  7.  
  8.  
  9.  
  10. //get the device contest for the current window-------------------
  11. gsp_hdc = GetDC( hWnd );
  12.  
  13. if( !gsp_hdc ){
  14.  
  15. MessageBox( NULL, TEXT(" Error Getting DC!"), TEXT(" error"), MB_ICONEXCLAMATION | MB_OK );
  16.  
  17. gsp_error_id = GetLastError();
  18. return 0;
  19. }
  20. //--------------------------------------------------------------
  21.  
  22.  
  23. //paint---------------------------------------------------------
  24. gsp_old_txtcolor = SetTextColor( gsp_hdc, RGB( 255, 0, 0 ) );
  25. //gsp_old_bgcolor = SetBkColor( gsp_hdc, RGB( 0, 0, 0 ) );
  26. SetBkMode( gsp_hdc, TRANSPARENT );
  27. /* all the functions above returns
  28. the not more current value, so
  29. you can save it for backup */
  30.  
  31. TextOut( gsp_hdc, 0, 0, TEXT(" My text "), 9 );
  32. DrawText( gsp_hdc, TEXT(" My other balacodation text,\r\nwith lots and lots of words...\r\njust to see what happens... "),
  33. (int)strlen (" My other balacodation text,\r\nwith lots and lots of words...\r\njust to see what happens... "),
  34. &gsp_textrect, DT_LEFT );
  35. /* strlen counts the numbers of characters on a string */
  36.  
  37. //---------------------------------------------------------------
  38.  
  39.  
  40. ReleaseDC( hWnd, gsp_hdc ); //cada GetDC precisa de um ReleaseDC
  41.  
  42. GetClientRect( hWnd, &myrect );
  43.  
  44. ValidateRect( hWnd, &myrect );//WM_PAINT donne! ( NULL apaga tudo )
  45.  
  46.  
  47.  
  48.  
  49.  
  50. }break;

  1.  
  2. //THE BUTTON CREATION:
  3.  
  4. HWND gsp_button1;
  5. gsp_button1 = CreateWindow( TEXT("Button"), TEXT("My Button"),
  6. WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
  7. 300, 300, 150, 50,
  8. gsp_hmainwnd,(HMENU) 100, hInstance, NULL );

  1. //THE MAIN WINDOW(parent):
  2.  
  3.  
  4. HWND gsp_hmainwnd; //the window handle
  5.  
  6. gsp_hmainwnd = CreateWindowEx( WS_EX_APPWINDOW | WS_EX_OVERLAPPEDWINDOW/* | WS_EX_TOPMOST*/, //EX style
  7. TEXT("GSP Main Windows Class"), TEXT("GSP Main Window"), //Name Classe, Name Window
  8. WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SYSMENU | WS_CAPTION | WS_SIZEBOX, //style
  9. CW_USEDEFAULT, NULL, //x, y
  10. CW_USEDEFAULT, CW_USEDEFAULT, //w, h
  11. NULL, NULL, //pai, menu
  12. hInstance, NULL ); //instance module, value?

  1. //THE WINDOW CLASS STRUCTURE RESGISTERED:
  2.  
  3. WNDCLASSEX gsp_wc;//the window class structure
  4.  
  5. gsp_wc.cbSize = sizeof( WNDCLASSEX ); //tamanho da estrutura(em bytes)
  6. gsp_wc.style = CS_HREDRAW | CS_VREDRAW; //estilo da classe( varias opçoes CS_..)
  7. gsp_wc.lpfnWndProc = gsp_MainWndProc; //pointer pro 'wndproc'
  8. gsp_wc.cbClsExtra = 0; //class extra bytes
  9. gsp_wc.cbWndExtra = 0; //window extra bytes
  10. gsp_wc.hInstance = hInstance; //instance q tem o 'wndproc'
  11.  
  12. gsp_wc.hIcon = (HICON)LoadImage( NULL, TEXT("gsp_TsmIcon.ico"), IMAGE_ICON, 16, 16, LR_LOADFROMFILE|LR_SHARED);//LoadIcon( NULL, IDI_APPLICATION ); //large icon( ALT+TAB )TEM q ser NULL a hInstance..
  13. gsp_wc.hCursor = LoadCursor( NULL, IDC_ARROW ); //cursor
  14. gsp_wc.hIconSm = (HICON)LoadImage( NULL, TEXT("gsp_TsmIcon.ico"), IMAGE_ICON, 16, 16, LR_LOADFROMFILE|LR_SHARED);//small icon(caption, barr..)
  15.  
  16. gsp_wc.hbrBackground = (HBRUSH) COLOR_BACKGROUND + 1; //cor de fundo//pode ser: (HBRUSH) GetStockObject( BLACK_BRUSH );
  17. gsp_wc.lpszMenuName = TEXT("RC_GSP_MAINMENU"); //nome do menu
  18.  
  19. gsp_wc.lpszClassName = TEXT("GSP Main Windows Class"); //nome da classe( identificador)
  20. //--------------------------------------------------------------


I dont get whats going on, since WS_VISIBLE is set...( I dont know what WS_VISIBLE is at all, I tried create my main window with WS_VISIBLE, but I STILL need to call ShowWindow, or notting is displaied )..

Not handling WM_PAINT myself solve the problem.
Using BeginPaint / EndPaint at the WM_PAINT solve the problem too.

So, what I have to do ?( I want proccess WM_PAINT myself, using GetDC / Release DC instead of Begin / EndPaint )
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 167
Reputation: Frederick2 has a spectacular aura about Frederick2 has a spectacular aura about Frederick2 has a spectacular aura about 
Solved Threads: 19
Frederick2 Frederick2 is offline Offline
Junior Poster

Re: Win32 - WM_PAINT and 'Button Windows'

 
0
  #2
Aug 7th, 2009
Can't imagine why you are using GetDC(), ReleaseDC() in WM_PAINT. That isn't done. There is no reason whatsoever to do that.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum


Views: 721 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC