Advertisement
Ham62

CreateWindow

Mar 10th, 2025
147
0
8 hours
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.16 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #include "..\include\httpasync.h"
  6. #include "..\include\subsonic.h"
  7. #include "..\include\jsmn.h"
  8.  
  9. #define MAX_LOADSTRING 100
  10.  
  11. HINSTANCE hInst;
  12.  
  13. char szTitle[MAX_LOADSTRING];
  14. char *pszWndClass = "Sub32";
  15.  
  16. HTTP *pConnection = NULL;
  17.  
  18. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  19.  
  20. //int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
  21. int main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
  22.     HWND       hWnd;
  23.     MSG        msg;
  24.     WNDCLASSEX wcls;
  25.     HMENU hMenu;
  26.    
  27.     HTTP_RESPONSE *pResponse;
  28.  
  29.     hInst = hInstance;
  30.  
  31.     wcls.cbSize        = sizeof(WNDCLASSEX);
  32.     wcls.style         = CS_HREDRAW | CS_VREDRAW;
  33.     wcls.lpfnWndProc   = (WNDPROC)WndProc;
  34.     wcls.cbClsExtra    = 0;
  35.     wcls.cbWndExtra    = 0;
  36.     wcls.hInstance     = hInstance;
  37.     wcls.hIcon         = LoadIcon(hInstance, "SUB32_ICON");
  38.     wcls.hCursor       = LoadCursor(NULL, IDC_ARROW);
  39.     wcls.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
  40.     wcls.lpszMenuName  = NULL;
  41.     wcls.lpszClassName = pszWndClass;
  42.     wcls.hIconSm       = LoadIcon(hInstance, "SUB32_ICON");
  43.  
  44.     if (RegisterClassEx(&wcls) == FALSE) {
  45.         MessageBox(NULL, "Failed to register Window class!", "Error!", MB_OK | MB_ICONERROR);
  46.         return -1;
  47.     }
  48.  
  49.  
  50.     hMenu = CreateMenu();
  51.     InsertMenu(hMenu, 0, MF_STRING, 1, "Server");
  52.     InsertMenu(hMenu, 0, MF_STRING, 1, "Options");
  53.     InsertMenu(hMenu, 0, MF_STRING, 1, "About");
  54.  
  55.     hWnd = CreateWindow(pszWndClass,
  56.                         szTitle,
  57.                         WS_OVERLAPPEDWINDOW,
  58.                         CW_USEDEFAULT,
  59.                         CW_USEDEFAULT,
  60.                         320, 200, NULL, hMenu,
  61.                         hInstance, NULL);
  62.     if (hWnd == NULL) {
  63.         MessageBox(NULL, "Failed to create main window!", "Error!", MB_OK | MB_ICONERROR);
  64.         return -1;
  65.     }
  66.  
  67.     ShowWindow(hWnd, nCmdShow);
  68.     UpdateWindow(hWnd);
  69.  
  70.     while (GetMessage(&msg, NULL, 0, 0)) {
  71.         TranslateMessage(&msg);
  72.         DispatchMessage(&msg);
  73.        
  74.         if (pConnection != NULL) {
  75.             pResponse = http_read_async(pConnection);
  76.             if (pResponse) {
  77.                 http_disconnect(pConnection);
  78.                 pConnection = NULL;
  79.                
  80.                 printf("%s\n-----\n", pResponse->pszHeader);
  81.                 printf("%s\r\n", pResponse->pData);
  82.             }
  83.         }
  84.     }
  85.  
  86.     // Resource cleanup
  87.     if (wcls.hIcon) DestroyIcon(wcls.hIcon);
  88.     if (wcls.hIconSm) DestroyIcon(wcls.hIconSm);
  89.     if (wcls.hCursor) DestroyIcon(wcls.hCursor);
  90.  
  91.     DestroyWindow(hWnd);
  92.     DestroyMenu(hMenu);
  93.     UnregisterClass(pszWndClass, hInstance);
  94.  
  95.     return msg.wParam;
  96. }
  97.  
  98. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
  99.     PAINTSTRUCT ps;
  100.     HDC hdc;
  101.     RECT rt;
  102.     static HWND handle;
  103.  
  104.     switch (message) {
  105.         case WM_CREATE:
  106.             handle = CreateWindowEx(0,
  107.                            "BUTTON",
  108.                            "Hello C-L",
  109.                            WS_VISIBLE | WS_CHILD,
  110.                            20, 40,  // Position
  111.                            40, 20,  // Size
  112.                            hWnd, NULL, hInst, NULL);
  113.             printf("Handle: %d\r\n", handle);
  114.                            
  115.             break;
  116.         case WM_COMMAND:
  117.             printf("wParam: %d\r\nlPAram: %d\r\n", wParam, lParam);
  118.             switch (LOWORD(wParam)) {
  119.                 default:
  120.                     http_connectPort(pszDomain, iPort, &pConnection);
  121.                     http_sendGet(pConnection, "/index.html");
  122.                     break;
  123.             }
  124.         case WM_PAINT:
  125.             hdc = BeginPaint(hWnd, &ps);
  126.             GetClientRect(hWnd, &rt);
  127.             DrawText(hdc, "Hello", strlen("Hello"), &rt, DT_CENTER);
  128.             EndPaint(hWnd, &ps);
  129.             break;
  130.         case WM_DESTROY:
  131.             PostQuitMessage(0);
  132.             break;
  133.         default:
  134.             return DefWindowProc(hWnd, message, wParam, lParam);
  135.     }
  136.     return FALSE;
  137. }
  138.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement