Advertisement
TELunus

Starty

Jan 21st, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.80 KB | None | 0 0
  1. #ifndef _WIN32_IE           // Allow use of features specific to IE 6.0 or later.
  2. #define _WIN32_IE 0x0600
  3. #endif
  4.  
  5. #ifndef _WIN32_WINNT            // Allow use of features specific to IE 6.0 or later.
  6. #define _WIN32_WINNT 0x0600
  7. #endif
  8.  
  9. #include <iostream>
  10. #include <windows.h>
  11. #include <Windowsx.h>
  12. #include <Commctrl.h>
  13. #include <Shellapi.h>
  14. #include <Shlwapi.h>
  15. void IconDealing(HWND hwnd);
  16.  
  17. DWORD FindCbSize();
  18.  
  19.  
  20. void IconDealing(HWND hwnd)
  21. {
  22.     NOTIFYICONDATA StartyIcon = {0};
  23.     StartyIcon.cbSize = FindCbSize();//FindCbSize();
  24.     StartyIcon.hWnd = hwnd;
  25.     StartyIcon.uID = 1;
  26.     StartyIcon.uFlags = NIF_TIP|NIF_STATE|NIF_ICON;
  27.     StartyIcon.uCallbackMessage = 100;
  28.     //HICON *StartyConPtr;
  29.     //std::cout<<((LoadIconMetric(NULL,"StartyCon.ico",GetSystemMetrics(11),StartyConPtr) == S_OK),"it worked","oops")<<std::endl;
  30.     //StartyIcon.hIcon = *StartyConPtr;
  31.     StartyIcon.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  32.     strcpy(StartyIcon.szTip, "Starty: click to start using starty");
  33.     StartyIcon.dwState = 0;
  34.     StartyIcon.dwStateMask = 0;
  35.     strcpy(StartyIcon.szInfo, "This is Starty's balooon!");
  36.     StartyIcon.uVersion = NOTIFYICON_VERSION_4;
  37.     strcpy(StartyIcon.szInfoTitle, "HEY you!");
  38.     StartyIcon.dwInfoFlags = NIIF_INFO;
  39.     //StartyIcon.guidItem = 0;
  40.     StartyIcon.hBalloonIcon = NULL;
  41.  
  42.  
  43.     PNOTIFYICONDATA StartyIconPtr = &StartyIcon;
  44.     std::cout<<Shell_NotifyIcon(NIM_ADD,StartyIconPtr)<<std::endl;
  45. }
  46.  
  47. DWORD FindCbSize()
  48. {
  49.     DWORD Result;
  50.     Result = sizeof(NOTIFYICONDATA);//was sizeof(_NOTIFYICONDATAA)
  51.     return Result;
  52. }
  53.  
  54.  
  55. /*  Declare Windows procedure  */
  56. LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
  57.  
  58. /*  Make the class name into a global variable  */
  59. char szClassName[ ] = "CodeBlocksWindowsApp";
  60.  
  61.  
  62.  
  63. int WINAPI WinMain (HINSTANCE hThisInstance,
  64.                      HINSTANCE hPrevInstance,
  65.                      LPSTR lpszArgument,
  66.                      int nCmdShow)
  67. {
  68.     HWND hwnd;               /* This is the handle for our window */
  69.     MSG messages;            /* Here messages to the application are saved */
  70.     WNDCLASSEX wincl;        /* Data structure for the windowclass */
  71.  
  72.     /* The Window structure */
  73.     wincl.hInstance = hThisInstance;
  74.     wincl.lpszClassName = szClassName;
  75.     wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
  76.     wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
  77.     wincl.cbSize = sizeof (WNDCLASSEX);
  78.  
  79.     /* Use default icon and mouse-pointer */
  80.     wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  81.     wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
  82.     wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
  83.     wincl.lpszMenuName = NULL;                 /* No menu */
  84.     wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
  85.     wincl.cbWndExtra = 0;                      /* structure or the window instance */
  86.     /* Use Windows's default colour as the background of the window */
  87.     wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
  88.  
  89.  
  90.  
  91.  
  92.  
  93.     /* Register the window class, and if it fails quit the program */
  94.     if (!RegisterClassEx (&wincl))
  95.         return 0;
  96.  
  97.     /* The class is registered, let's create the program*/
  98.     hwnd = CreateWindowEx (
  99.            0,                   /* Extended possibilites for variation */
  100.            szClassName,         /* Classname */
  101.            "Code::Blocks Template Windows App",       /* Title Text */
  102.            WS_OVERLAPPEDWINDOW, /* default window */
  103.            CW_USEDEFAULT,       /* Windows decides the position */
  104.            CW_USEDEFAULT,       /* where the window ends up on the screen */
  105.            544,                 /* The programs width */
  106.            375,                 /* and height in pixels */
  107.            HWND_DESKTOP,        /* The window is a child-window to desktop */
  108.            NULL,                /* No menu */
  109.            hThisInstance,       /* Program Instance handler */
  110.            NULL                 /* No Window Creation data */
  111.            );
  112.  
  113.         //the starty icon
  114.         IconDealing(hwnd);
  115.         HMENU myMenu = CreatePopupMenu();
  116.         if (myMenu == NULL)
  117.         {
  118.             std::cout<<"Hey!"<<std::endl;
  119.         }
  120.         else
  121.         {
  122.             std::cout<<"pointer good"<<std::endl;
  123.         }
  124.         MENUITEMINFO myMenuItem = {0};
  125.         myMenuItem.cbSize = sizeof(myMenuItem);
  126.         myMenuItem.fMask = MIIM_STRING|MIIM_TYPE|MIIM_ID;
  127.         myMenuItem.wID = 1;
  128.         myMenuItem.cch = 64;
  129.         char myItemText[64] = "It's a menu item!";
  130.         myMenuItem.dwTypeData = myItemText;
  131.         InsertMenuItem(myMenu, 0, TRUE, &myMenuItem);
  132.         SetMenuItemInfo(myMenu, 0, TRUE, &myMenuItem);
  133.         RECT uselessArg = {0};
  134.         std::cout<<((TrackPopupMenu(myMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON, 100, 100, 0, hwnd, &uselessArg))?"it worked!":"nope")<<std::endl;
  135.  
  136.  
  137.     /* Make the window visible on the screen */
  138.     ShowWindow (hwnd, nCmdShow);
  139.  
  140.     /* Run the message loop. It will run until GetMessage() returns 0 */
  141.     while (GetMessage (&messages, NULL, 0, 0))
  142.     {
  143.         /* Translate virtual-key messages into character messages */
  144.         TranslateMessage(&messages);
  145.         /* Send message to WindowProcedure */
  146.         DispatchMessage(&messages);
  147.     }
  148.  
  149.     /* The program return-value is 0 - The value that PostQuitMessage() gave */
  150.     return messages.wParam;
  151. }
  152.  
  153.  
  154. /*  This function is called by the Windows function DispatchMessage()  */
  155.  
  156. LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  157. {
  158.     switch (message)                  /* handle the messages */
  159.     {
  160.         case WM_DESTROY:
  161.             PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
  162.             break;
  163.         default:                      /* for messages that we don't deal with */
  164.             return DefWindowProc (hwnd, message, wParam, lParam);
  165.     }
  166.  
  167.     return 0;
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement