• Jueves 2 de Mayo de 2024, 06:12

Autor Tema:  App. Winapi  (Leído 981 veces)

shakka

  • Miembro HIPER activo
  • ****
  • Mensajes: 679
  • Nacionalidad: cr
    • Ver Perfil
    • http://mbrenes.com
App. Winapi
« en: Domingo 20 de Noviembre de 2005, 21:21 »
0
Quiero hacer una app. que muestre una ventana de presentacion (Splash Screen) solamente, pero por el momento no he podido hacer que al crear la ventana principal "Tabix" me muestre la de presentacion "Splash".

Que puede ser que no me muestre esta segunda ventana?

/*==( Tabix.cpp )=====================================*/
Código: Text
  1.  
  2. #include "tabix.h"
  3.  
  4. int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int);
  5.  
  6. int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
  7. {
  8. HWND hWndTabix;
  9. WNDCLASSEX xCTabix;
  10. WNDCLASSEX xCSplash;
  11. MSG message;
  12.  
  13.   xCTabix.cbSize=sizeof(WNDCLASSEX);
  14.   xCTabix.style=CS_HREDRAW|CS_VREDRAW;
  15.   xCTabix.lpfnWndProc=TabixProc;
  16.   xCTabix.cbClsExtra=0;
  17.   xCTabix.cbWndExtra=0;
  18.   xCTabix.hInstance=hInstance;
  19.  
  20.   xCTabix.hIcon=LoadIcon(NULL,IDI_APPLICATION);
  21.   xCTabix.hCursor=LoadCursor(NULL,IDC_ARROW);
  22.   xCTabix.hbrBackground=(HBRUSH) COLOR_BACKGROUND;
  23.   xCTabix.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
  24.   xCTabix.lpszClassName=szCTabix;
  25.   xCTabix.lpszMenuName=NULL;
  26.  
  27.   if (!RegisterClassEx(&xCTabix))
  28.     return (FALSE);
  29.  
  30.   xCSplash.cbSize=sizeof(WNDCLASSEX);
  31.   xCSplash.style=CS_DBLCLKS;
  32.   xCSplash.lpfnWndProc=SplashProc;
  33.   xCSplash.cbClsExtra=0;
  34.   xCSplash.cbWndExtra=0;
  35.   xCSplash.hInstance=hInstance;
  36.  
  37.   xCSplash.hIcon=LoadIcon(NULL,IDI_APPLICATION);
  38.   xCSplash.hCursor=LoadCursor(NULL,IDC_ARROW);
  39.   xCSplash.hbrBackground=(HBRUSH) COLOR_BACKGROUND;
  40.   xCSplash.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
  41.   xCSplash.lpszClassName=szCSplash;
  42.   xCSplash.lpszMenuName=NULL;
  43.  
  44.   if (!RegisterClassEx(&xCSplash))
  45.     return (FALSE);
  46.  
  47.  hWndTabix=CreateWindowEx(
  48. 0,
  49. szCTabix,
  50. szTabixTitle,
  51. WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX,
  52. CW_USEDEFAULT,
  53. CW_USEDEFAULT,
  54. 512,
  55. 256,
  56. NULL,
  57. NULL,
  58. hInstance,
  59. NULL);
  60.  
  61.   if (!hWndTabix)
  62.     return (FALSE);
  63.  
  64.   ShowWindow(hWndTabix,nCmdShow);
  65.   UpdateWindow(hWndTabix);
  66.  
  67.   while(GetMessage(&message,NULL,0,0))
  68.   {
  69.     TranslateMessage(&message);
  70.     DispatchMessage(&message);
  71.   }
  72.  
  73. return (message.wParam);
  74. }
  75.  
  76.  


/*==( Tabix.h )=====================================*/
Código: Text
  1. #include <windows.h>
  2.  
  3. LRESULT CALLBACK TabixProc(HWND,UINT,WPARAM,LPARAM);
  4. LRESULT CALLBACK SplashProc(HWND,UINT,WPARAM,LPARAM);
  5. void ShowBitmap(HDC,HWND,HBITMAP,int,int);
  6.  
  7. char szCTabix[]="CTabix";
  8. char szCSplash[]="CSplash";
  9. char szTabixTitle[]="Tabix Generador de tablas HTML";
  10. char szSplashTitle[]="Tabix Generador de tablas HTML";
  11.  
  12. LRESULT CALLBACK TabixProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
  13. {
  14. HWND hWndSplash;
  15.  
  16.   switch (message)
  17.   {
  18.     case WM_CREATE:
  19.       hWndSplash=CreateWindowEx(
  20. WS_EX_DLGMODALFRAME,
  21. szCSplash,
  22. szSplashTitle,
  23. WS_POPUP,
  24. CW_USEDEFAULT,
  25. CW_USEDEFAULT,
  26. 400,
  27. 230,
  28. hWnd,
  29. NULL,
  30. GetModuleHandle(NULL),
  31. NULL);
  32.     break;
  33.  
  34.     case WM_CLOSE:
  35.       DestroyWindow(hWnd);
  36.     break;
  37.  
  38.     case WM_DESTROY:
  39.       PostQuitMessage(0);
  40.     break;
  41.  
  42.     default:
  43.       return(DefWindowProc(hWnd,message,wParam,lParam));
  44.   }
  45.  
  46. return (0);
  47. }
  48.  
  49. LRESULT CALLBACK SplashProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
  50. {
  51. HDC hDC;
  52. PAINTSTRUCT ps;
  53. RECT rect;
  54. static HBITMAP hBitmap;
  55.  
  56. char szMessage[120];
  57.  
  58.   switch (message)
  59.   {
  60.     case WM_CREATE:
  61.       GetWindowRect(hWnd,&rect);
  62.       hBitmap=(HBITMAP) LoadImage(NULL,"Tabix.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
  63.       ShowWindow(hWnd,SW_SHOW);
  64.       UpdateWindow(hWnd);
  65.     break;
  66.  
  67.     case WM_PAINT:
  68.       hDC=BeginPaint(hWnd,&ps);
  69.       ShowBitmap(hDC,hWnd,hBitmap,400,255);
  70.       EndPaint(hWnd,&ps);
  71.     break;
  72.  
  73.     case WM_SIZE:
  74.       MoveWindow(hWnd,200,200,400,230,FALSE);
  75.       wsprintf(
  76. szMessage,
  77. "Resolucion: %d x %d, Ventana: left=%i,top=%i,right=%i,bottom=%i",GetSystemMetrics(SM_CXSCREEN),
  78. GetSystemMetrics(SM_CYSCREEN),rect.left,rect.top,rect.right,rect.bottom);
  79.       MessageBox(NULL,szMessage,szSplashTitle,MB_OK);
  80.     break;
  81.  
  82.     case WM_CLOSE:
  83.       SendMessage(hWnd,WM_DESTROY,0,0);
  84.     break;
  85.  
  86.     case WM_DESTROY:
  87.       DeleteObject(hBitmap);
  88.       PostQuitMessage(0);
  89.     break;
  90.   }
  91.  
  92. return 0;
  93. }
  94.  
  95. void ShowBitmap(HDC hDC,HWND hWnd,HBITMAP hBitmap,int iWidth,int iHeight)
  96. {
  97. HDC hBitmapDC;
  98. RECT rect;
  99.  
  100.   hBitmapDC=CreateCompatibleDC(hDC);
  101.   SelectObject(hBitmapDC,hBitmap);
  102.   GetClientRect(hWnd,&rect);
  103.   BitBlt(hDC,0,0,iWidth,iHeight,hBitmapDC,0,0,SRCCOPY);
  104.   DeleteDC(hBitmapDC);          
  105. }
  106.  
  107.