• Sábado 21 de Septiembre de 2024, 07:27

Mostrar Mensajes

Esta sección te permite ver todos los posts escritos por este usuario. Ten en cuenta que sólo puedes ver los posts escritos en zonas a las que tienes acceso en este momento.


Temas - Radger

Páginas: [1]
1
C/C++ / Problema Winapi
« en: Martes 3 de Agosto de 2010, 16:41 »
Buenas

Tengo un codigo que en teoria deberia cambiar el texto de un boton pero no hay manera, creo que el problema esta en el bhwnd ya que si uso un HWND creado en el procedimiento funciona pero si uso un HWND miembro de la clase no.

Código: C++
  1.  
  2. #include <windows.h>
  3.  
  4. class aaa
  5. {
  6. public:
  7.     aaa()
  8.     {
  9.         MSG  msg ;    
  10.  
  11.         WNDCLASSEX wc = {0};
  12.         wc.cbSize           = sizeof(WNDCLASSEX);
  13.         wc.lpfnWndProc      = aaa::DialogP;
  14.         wc.hInstance        = GetModuleHandle(NULL);
  15.         wc.hbrBackground    = GetSysColorBrush(COLOR_3DFACE);
  16.         wc.lpszClassName    = "DialogClass";
  17.         RegisterClassEx(&wc);
  18.  
  19.         CreateWindowEx(WS_EX_DLGMODALFRAME | WS_EX_TOPMOST, "DialogClass",
  20.             "Dialog Box", WS_VISIBLE | WS_SYSMENU | WS_CAPTION ,
  21.             100, 100, 200, 150, NULL, NULL, GetModuleHandle(NULL),  NULL);
  22.  
  23.         while(GetMessage(&msg, NULL, 0, 0))
  24.         {
  25.             TranslateMessage(&msg);
  26.             DispatchMessage(&msg);
  27.         }
  28.     }
  29.     static LRESULT CALLBACK DialogP( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
  30.     {
  31.         aaa *bb = (aaa*)GetWindowLong(hwnd, GWL_USERDATA);
  32.         return bb->DialogProc(hwnd, msg, wParam, lParam);
  33.     }
  34.     LRESULT CALLBACK DialogProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
  35.     {
  36.         switch(msg)  
  37.         {
  38.         case WM_CREATE:
  39.         {
  40.             bhwnd = CreateWindow("BUTTON", "AAA",    
  41.                 WS_VISIBLE | WS_CHILD ,
  42.                 50, 50, 80, 25,        
  43.                 hwnd, (HMENU) 1, NULL, NULL);  
  44.             SetWindowText(bhwnd, "DDD");
  45.         }
  46.         break;
  47.  
  48.         case WM_COMMAND:
  49.             DestroyWindow(hwnd);
  50.             PostQuitMessage(0);
  51.             break;
  52.  
  53.         case WM_CLOSE:
  54.             DestroyWindow(hwnd);
  55.             PostQuitMessage(0);
  56.             break;      
  57.  
  58.       }
  59.       return DefWindowProc(hwnd, msg, wParam, lParam);
  60.     }
  61. private:
  62.     HWND bhwnd;
  63. };
  64.  
  65. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
  66. {
  67.     aaa *nn = new aaa();
  68.     delete nn;
  69.  
  70.     return 0;
  71. }
  72.  
  73.  

Saludos

Páginas: [1]