Advertisement
SilverTES

Study Win32 API

Apr 25th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #if defined(UNICODE) && !defined(_UNICODE)
  2. #define _UNICODE
  3. #elif defined(_UNICODE) && !defined(UNICODE)
  4. #define UNICODE
  5. #endif
  6.  
  7. //#define _WIN32_WINNT 0x0600
  8. //#define _WIN32_IE 0x0900
  9.  
  10. #define _WIN32_WINNT  0x0501
  11. #define  WINVER       0x0501
  12. #define _WIN32_IE     0x0600
  13.  
  14. #include <tchar.h>
  15. #include <windows.h>
  16. #include <commctrl.h>
  17.  
  18. #define ID_DEFAULT 42
  19. #define ID_BUTTON0 0
  20. #define ID_QUIT 99
  21.  
  22. /*  Declare Windows procedure  */
  23. LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
  24.  
  25. /*  Make the class name into a global variable  */
  26. TCHAR szClassName[ ] = _T("CodeBlocksWindowsApp");
  27.  
  28. int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow)
  29. {
  30.  
  31.     INITCOMMONCONTROLSEX icex;
  32.     icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
  33.     icex.dwICC = ICC_STANDARD_CLASSES;
  34.     InitCommonControlsEx(&icex);
  35.  
  36.     //MessageBoxW(NULL, lpszArgument, L"Title", MB_OK);
  37.  
  38.     HWND hwnd;               /* This is the handle for our window */
  39.     MSG messages;            /* Here messages to the application are saved */
  40.     WNDCLASSEX wincl;        /* Data structure for the windowclass */
  41.  
  42.     static HWND buttons[1] = {NULL};
  43.     HMENU menu, sousMenu;
  44.  
  45.     /* The Window structure */
  46.     wincl.hInstance = hThisInstance;
  47.     wincl.lpszClassName = szClassName;
  48.     wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
  49.     wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
  50.     wincl.cbSize = sizeof (WNDCLASSEX);
  51.  
  52.     /* Use default icon and mouse-pointer */
  53.     wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  54.     wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
  55.     wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
  56.     wincl.lpszMenuName = NULL;                 /* No menu */
  57.     wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
  58.     wincl.cbWndExtra = 0;                      /* structure or the window instance */
  59.     /* Use Windows's default colour as the background of the window */
  60.     wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
  61.  
  62.     /* Register the window class, and if it fails quit the program */
  63.     if (!RegisterClassEx (&wincl))
  64.         return 0;
  65.  
  66.  
  67.     sousMenu = CreateMenu();
  68.     AppendMenu(sousMenu, MF_STRING, ID_DEFAULT, "New..");
  69.     AppendMenu(sousMenu, MF_SEPARATOR, (UINT)NULL, "");
  70.     AppendMenu(sousMenu, MF_STRING, ID_DEFAULT, "Open..");
  71.     AppendMenu(sousMenu, MF_SEPARATOR, (UINT)NULL, "");
  72.     AppendMenu(sousMenu, MF_STRING, ID_DEFAULT, "Save..");
  73.     AppendMenu(sousMenu, MF_STRING, ID_DEFAULT, "Save As..");
  74.     AppendMenu(sousMenu, MF_SEPARATOR, (UINT)NULL, "");
  75.     AppendMenu(sousMenu, MF_STRING, ID_QUIT, "Quitter");
  76.  
  77.  
  78.  
  79.     menu = CreateMenu();
  80.     AppendMenu(menu, MF_POPUP, (UINT)sousMenu, "File");
  81.     AppendMenu(menu, MF_POPUP, (UINT)sousMenu, "Edit");
  82.     AppendMenu(menu, MF_POPUP, (UINT)sousMenu, "View");
  83.  
  84.  
  85.     /* The class is registered, let's create the program*/
  86.     hwnd = CreateWindowEx (
  87.                0,                   /* Extended possibilites for variation */
  88.                szClassName,         /* Classname */
  89.                _T("Mugen Sprite Editor"),       /* Title Text */
  90.                WS_OVERLAPPEDWINDOW, /* default window */
  91.                CW_USEDEFAULT,       /* Windows decides the position */
  92.                CW_USEDEFAULT,       /* where the window ends up on the screen */
  93.                800,                 /* The programs width */
  94.                600,                 /* and height in pixels */
  95.                HWND_DESKTOP,        /* The window is a child-window to desktop */
  96.                NULL,                /* No menu */
  97.                hThisInstance,       /* Program Instance handler */
  98.                NULL                 /* No Window Creation data */
  99.            );
  100.  
  101.  
  102.     buttons[0] = CreateWindow("BUTTON", "Mugen", WS_CHILD | WS_VISIBLE, 5, 5, 80, 24, hwnd, ID_BUTTON0, hThisInstance, NULL);
  103.     buttons[1] = CreateWindow("BUTTON", "Animation", WS_CHILD | WS_VISIBLE, 90, 5, 80, 24, hwnd, ID_BUTTON0, hThisInstance, NULL);
  104.  
  105.     SetMenu(hwnd, menu); // add menu bar
  106.  
  107.  
  108.  
  109.  
  110.     HWND hEdit=CreateWindow(
  111.                         "EDIT",
  112.                         "Modifiez le texte SVP",
  113.                          WS_VISIBLE|WS_CHILD|WS_BORDER|ES_MULTILINE|ES_AUTOHSCROLL|ES_AUTOVSCROLL,
  114.                          8,32,500,200,hwnd,NULL,hThisInstance,NULL);
  115.  
  116.     HFONT myFont = CreateFont(16, 0, 0, 0, 0, FALSE, 0, 0, 0, 0, 0, 0, 0, "gohufont");
  117.     SendMessage(hEdit, WM_SETFONT, WPARAM(myFont), TRUE);
  118.  
  119.     /* Make the window visible on the screen */
  120.     ShowWindow (hwnd, nCmdShow);
  121.  
  122.     /* Run the message loop. It will run until GetMessage() returns 0 */
  123.     while (GetMessage (&messages, NULL, 0, 0))
  124.     {
  125.         /* Translate virtual-key messages into character messages */
  126.         TranslateMessage(&messages);
  127.         /* Send message to WindowProcedure */
  128.         DispatchMessage(&messages);
  129.     }
  130.  
  131.     /* The program return-value is 0 - The value that PostQuitMessage() gave */
  132.     return messages.wParam;
  133. }
  134.  
  135.  
  136. /*  This function is called by the Windows function DispatchMessage()  */
  137.  
  138. LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  139. {
  140.  
  141.     switch (message)                  /* handle the messages */
  142.     {
  143.  
  144.     case WM_CREATE:
  145.  
  146.         break;
  147.     case WM_COMMAND:
  148.         switch(LOWORD(wParam))
  149.         {
  150.         case ID_QUIT:
  151.             PostQuitMessage(0);
  152.             break;
  153.         }
  154.         return 0;
  155.     case WM_DESTROY:
  156.         PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
  157.         break;
  158.     case WM_KEYDOWN:
  159.         if (wParam == VK_ESCAPE)
  160.         {
  161.             PostQuitMessage(0);
  162.         }
  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