Advertisement
Guest User

wine (1.5.26) bug example program

a guest
Mar 17th, 2013
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.74 KB | None | 0 0
  1.  
  2.  
  3. #define UNICODE
  4. #include <windows.h>
  5. #include <Commctrl.h>
  6.  
  7. #include <stdio.h>
  8. #include <stdint.h>
  9.  
  10. // winProc headers
  11. LRESULT CALLBACK WINSEM_Window_WindowProc_Create(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  12. LRESULT CALLBACK WINSEM_Window_WindowProc_Run(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  13.  
  14. // store struct
  15. struct sTab_Example
  16. {
  17.   HWND hWin;
  18.   HWND hTab;
  19. };
  20.  
  21. BOOL Tab_Example(struct sTab_Example *ps_example, LPCTSTR lpWindowName, HINSTANCE hThisInstance, HWND hParent, uintptr_t u0_id);
  22.  
  23.  
  24. int WINAPI WinMain (HINSTANCE hThisInstance,
  25.                     HINSTANCE hPrevInstance,
  26.                     LPSTR lpszArgument,
  27.                     int nFunsterStil)
  28.  
  29. {
  30.   struct sTab_Example s_tabA;
  31.   struct sTab_Example s_tabB;
  32.   DWORD dErr;
  33.  
  34.   // register class
  35.   {
  36.     WNDCLASSEX wcx;
  37.    
  38.     // Fill in the window class structure with parameters
  39.     // that describe the main window.
  40.    
  41.     wcx.cbSize = sizeof(WNDCLASSEX);          // size of structure
  42.     wcx.style = CS_DBLCLKS;                    // redraw if size changes
  43.     wcx.lpfnWndProc = WINSEM_Window_WindowProc_Create;     // points to window procedure
  44.     wcx.cbClsExtra = 0;                // no extra class memory
  45.     wcx.cbWndExtra = 0;                // no extra window memory
  46.     wcx.hInstance = hThisInstance;         // handle to instance
  47.     wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);              // predefined app. icon
  48.     wcx.hCursor = LoadCursor(NULL, IDC_ARROW);                    // predefined arrow
  49.     wcx.hbrBackground = GetStockObject(LTGRAY_BRUSH);                  // white background brush
  50.     wcx.lpszMenuName =  NULL;    // name of menu resource
  51.     wcx.lpszClassName = L"WINSEMClass";  // name of window class
  52.     wcx.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
  53.    
  54.     // Register the window class.
  55.    
  56.     if (RegisterClassExW(&wcx)==0)
  57.     {
  58.       dErr = GetLastError();
  59.       if (dErr!=0)
  60.       {
  61.         printf("WIN Error:%u\n", dErr);
  62.       }
  63.       return -1;
  64.     }
  65.   }
  66.  
  67.   // create windows with tabs
  68.   {
  69.     if (Tab_Example(&s_tabA, L"WINSEM tab A", hThisInstance, NULL, 101)==FALSE)
  70.     {
  71.       return -1;
  72.     }
  73.     if (Tab_Example(&s_tabB, L"WINSEM tab B", hThisInstance, HWND_MESSAGE, 102)==FALSE)
  74.     {
  75.       return -1;
  76.     }
  77.    
  78.     // THIS PROBABLY WORK BAD
  79.     SetParent(s_tabB.hTab, s_tabB.hWin);
  80.   }
  81.  
  82.   // show windows
  83.   ShowWindow(s_tabA.hWin, SW_SHOW);
  84.   ShowWindow(s_tabB.hWin, SW_SHOW);
  85.  
  86.   // message loop
  87.   {
  88.     MSG msg;
  89.     BOOL bRet;
  90.    
  91.     while (1)
  92.     {
  93.    
  94.       bRet = PeekMessage( &msg, NULL, 0, 0, PM_REMOVE);
  95.      
  96.       if (bRet==FALSE)
  97.       {
  98.         // no messages received
  99.       }
  100.       else
  101.       {
  102.         TranslateMessage(&msg);
  103.         DispatchMessage(&msg);
  104.        
  105.         if (msg.message==WM_QUIT)
  106.         {
  107.           break;
  108.         }
  109.       }
  110.     }
  111.    
  112.     return msg.wParam;
  113.   }
  114. }
  115.  
  116. BOOL Tab_Example(struct sTab_Example *ps_example, LPCTSTR lpWindowName, HINSTANCE hThisInstance, HWND hParent, uintptr_t u0_id)
  117. {
  118.   DWORD dErr;
  119.  
  120.   // create window
  121.   {
  122.     ps_example->hWin = CreateWindowEx(0,                      // no extended styles          
  123.                                       L"WINSEMClass",          // class name                  
  124.                                       lpWindowName,               // window name                  
  125.                                       WS_OVERLAPPEDWINDOW,  // overlapped window            
  126.                                       CW_USEDEFAULT,          // default horizontal position  
  127.                                       CW_USEDEFAULT,          // default vertical position    
  128.                                       300,          // default width                
  129.                                       300,          // default height              
  130.                                       HWND_DESKTOP,            // no parent or owner window    
  131.                                       (HMENU) NULL,           // class menu used              
  132.                                       hThisInstance,// instance handle              
  133.                                       (LPVOID)ps_example);          // no window creation data
  134.  
  135.     if (ps_example->hWin==NULL)
  136.     {
  137.       dErr = GetLastError();
  138.       if (dErr!=0)
  139.       {
  140.         printf("WIN Error:%u\n", dErr);
  141.       }
  142.       return FALSE;
  143.     }
  144.   }
  145.  
  146.   if (hParent==NULL) hParent = ps_example->hWin;
  147.  
  148.   // create tab
  149.   {
  150.     TCITEM tie;
  151.     INITCOMMONCONTROLSEX icex;
  152.    
  153.     // Initialize common controls.
  154.     icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
  155.     icex.dwICC = ICC_TAB_CLASSES;
  156.     InitCommonControlsEx(&icex);
  157.      
  158.     ps_example->hTab = CreateWindowExW(0,                      // no extended styles          
  159.                                        WC_TABCONTROL,          // class name                  
  160.                                        L"",               // default text                  
  161.                                        WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,  // overlapped window            
  162.                                        CW_USEDEFAULT,          // default horizontal position  
  163.                                        CW_USEDEFAULT,          // default vertical position    
  164.                                        300,          // default width                
  165.                                        300,          // default height              
  166.                                        hParent,            // no parent or owner window    
  167.                                        (HMENU)u0_id,           // class menu used              
  168.                                        hThisInstance,// instance handle              
  169.                                        (LPVOID)ps_example);  
  170.     if (ps_example->hTab == NULL)
  171.     {
  172.       dErr = GetLastError();
  173.       if (dErr!=0)
  174.       {
  175.         printf("WIN Error:%u\n", dErr);
  176.       }
  177.       return FALSE;
  178.     }
  179.    
  180.     // Add tabs for each day of the week.
  181.     tie.mask = TCIF_TEXT;
  182.    
  183.     tie.pszText = L"TAB 0";
  184.     if (TabCtrl_InsertItem(ps_example->hTab, 0, &tie) == -1)
  185.     {
  186.       dErr = GetLastError();
  187.       if (dErr!=0)
  188.       {
  189.         printf("WIN Error:%u\n", dErr);
  190.       }
  191.       DestroyWindow(ps_example->hTab);
  192.       return FALSE;
  193.     }
  194.    
  195.     tie.pszText = L"TAB 1";
  196.     if (TabCtrl_InsertItem(ps_example->hTab, 1, &tie) == -1)
  197.     {
  198.       dErr = GetLastError();
  199.       if (dErr!=0)
  200.       {
  201.         printf("WIN Error:%u\n", dErr);
  202.       }
  203.       DestroyWindow(ps_example->hTab);
  204.       return FALSE;
  205.     }
  206.   }
  207.  
  208.   return TRUE;
  209. }
  210.  
  211. // winProc
  212. LRESULT CALLBACK WINSEM_Window_WindowProc_Create(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  213. {
  214.   {
  215.     if (uMsg==WM_CREATE)
  216.     {
  217.       // special code for creation
  218.       LPCREATESTRUCT pd_create;
  219.       struct sTab_Example *ps_example;
  220.       DWORD dErr;
  221.      
  222.       pd_create = (LPCREATESTRUCT)lParam;
  223.       ps_example = (struct sTab_Example *)pd_create->lpCreateParams;
  224.      
  225.       while (1)
  226.       {
  227.         SetLastError(0);
  228.         if (SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)ps_example)==0)
  229.         {
  230.           dErr = GetLastError();
  231.           if (dErr!=0)
  232.           {
  233.             printf("WIN Error:%u\n", dErr);
  234.             break;
  235.           }
  236.         }
  237.        
  238.         if (SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)WINSEM_Window_WindowProc_Run)==0)
  239.         {
  240.           dErr = GetLastError();
  241.           if (dErr!=0)
  242.           {
  243.             printf("WIN Error:%u\n", dErr);
  244.             break;
  245.           }
  246.         }    
  247.        
  248.         return 0;
  249.       }
  250.       return -1;
  251.     }
  252.   }
  253.  
  254.   // error
  255.   return DefWindowProc(hwnd, uMsg, wParam, lParam);
  256. }
  257. LRESULT CALLBACK WINSEM_Window_WindowProc_Run(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  258. {
  259.   if (uMsg==WM_COMMAND)
  260.   {
  261.     //WORD wID;
  262.     WORD wNotification;
  263.     // command from other object
  264.     //wID = LOWORD(wParam);
  265.     wNotification = LOWORD(wParam);
  266.    
  267.     if (wNotification>0)
  268.     {
  269.       HWND hWin;
  270.      
  271.       hWin = (HWND)lParam;
  272.      
  273.       printf("WM_COMMAND: win: %p code: %u\n", hWin, HIWORD(wParam));
  274.      
  275.       return FALSE;
  276.     }
  277.   }
  278.   else if (uMsg==WM_NOTIFY)
  279.   {
  280.     LPNMHDR dInfo;
  281.    
  282.     dInfo = (LPNMHDR)lParam;
  283.    
  284.     printf("WM_NOTIFY: win: %p code: %u\n", dInfo->hwndFrom, dInfo->code);
  285.    
  286.     return FALSE;
  287.   }
  288.   else
  289.   {
  290.     // look for message in array
  291.    
  292.     printf("%u: win: %p wParam: %u lParam: %u\n", uMsg, hwnd, (unsigned int)wParam, (unsigned int)lParam);
  293.    
  294.     if (uMsg==WM_DESTROY)
  295.     {
  296.       printf("QUIT\n");
  297.       PostQuitMessage(0);
  298.      
  299.       return FALSE;
  300.     }
  301.     //return FALSE;
  302.   }
  303.  
  304.   return DefWindowProc(hwnd, uMsg, wParam, lParam);
  305. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement