943,899 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2727
  • C++ RSS
Aug 2nd, 2009
0

Win32 - WM_PAINT and 'Button Windows'

Expand Post »
I cant figure out how make the Button visible proccessing WM_PAINT myself, it just get visible after pressing it..


C++ Syntax (Toggle Plain Text)
  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;

C++ Syntax (Toggle Plain Text)
  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 );

C++ Syntax (Toggle Plain Text)
  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?

C++ Syntax (Toggle Plain Text)
  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 )
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Icebone1000 is offline Offline
50 posts
since Jan 2008
Aug 7th, 2009
0

Re: Win32 - WM_PAINT and 'Button Windows'

Can't imagine why you are using GetDC(), ReleaseDC() in WM_PAINT. That isn't done. There is no reason whatsoever to do that.
Reputation Points: 244
Solved Threads: 31
Posting Whiz
Frederick2 is offline Offline
330 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Execute an Aplication Using C++
Next Thread in C++ Forum Timeline: Need the actual logic of beelow problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC