Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <stdio.h>
- #include <string.h>
- #include "..\include\httpasync.h"
- #include "..\include\subsonic.h"
- #include "..\include\jsmn.h"
- #define MAX_LOADSTRING 100
- HINSTANCE hInst;
- char szTitle[MAX_LOADSTRING];
- char *pszWndClass = "Sub32";
- HTTP *pConnection = NULL;
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- //int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
- int main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
- HWND hWnd;
- MSG msg;
- WNDCLASSEX wcls;
- HMENU hMenu;
- HTTP_RESPONSE *pResponse;
- hInst = hInstance;
- wcls.cbSize = sizeof(WNDCLASSEX);
- wcls.style = CS_HREDRAW | CS_VREDRAW;
- wcls.lpfnWndProc = (WNDPROC)WndProc;
- wcls.cbClsExtra = 0;
- wcls.cbWndExtra = 0;
- wcls.hInstance = hInstance;
- wcls.hIcon = LoadIcon(hInstance, "SUB32_ICON");
- wcls.hCursor = LoadCursor(NULL, IDC_ARROW);
- wcls.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
- wcls.lpszMenuName = NULL;
- wcls.lpszClassName = pszWndClass;
- wcls.hIconSm = LoadIcon(hInstance, "SUB32_ICON");
- if (RegisterClassEx(&wcls) == FALSE) {
- MessageBox(NULL, "Failed to register Window class!", "Error!", MB_OK | MB_ICONERROR);
- return -1;
- }
- hMenu = CreateMenu();
- InsertMenu(hMenu, 0, MF_STRING, 1, "Server");
- InsertMenu(hMenu, 0, MF_STRING, 1, "Options");
- InsertMenu(hMenu, 0, MF_STRING, 1, "About");
- hWnd = CreateWindow(pszWndClass,
- szTitle,
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- 320, 200, NULL, hMenu,
- hInstance, NULL);
- if (hWnd == NULL) {
- MessageBox(NULL, "Failed to create main window!", "Error!", MB_OK | MB_ICONERROR);
- return -1;
- }
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
- while (GetMessage(&msg, NULL, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- if (pConnection != NULL) {
- pResponse = http_read_async(pConnection);
- if (pResponse) {
- http_disconnect(pConnection);
- pConnection = NULL;
- printf("%s\n-----\n", pResponse->pszHeader);
- printf("%s\r\n", pResponse->pData);
- }
- }
- }
- // Resource cleanup
- if (wcls.hIcon) DestroyIcon(wcls.hIcon);
- if (wcls.hIconSm) DestroyIcon(wcls.hIconSm);
- if (wcls.hCursor) DestroyIcon(wcls.hCursor);
- DestroyWindow(hWnd);
- DestroyMenu(hMenu);
- UnregisterClass(pszWndClass, hInstance);
- return msg.wParam;
- }
- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
- PAINTSTRUCT ps;
- HDC hdc;
- RECT rt;
- static HWND handle;
- switch (message) {
- case WM_CREATE:
- handle = CreateWindowEx(0,
- "BUTTON",
- "Hello C-L",
- WS_VISIBLE | WS_CHILD,
- 20, 40, // Position
- 40, 20, // Size
- hWnd, NULL, hInst, NULL);
- printf("Handle: %d\r\n", handle);
- break;
- case WM_COMMAND:
- printf("wParam: %d\r\nlPAram: %d\r\n", wParam, lParam);
- switch (LOWORD(wParam)) {
- default:
- http_connectPort(pszDomain, iPort, &pConnection);
- http_sendGet(pConnection, "/index.html");
- break;
- }
- case WM_PAINT:
- hdc = BeginPaint(hWnd, &ps);
- GetClientRect(hWnd, &rt);
- DrawText(hdc, "Hello", strlen("Hello"), &rt, DT_CENTER);
- EndPaint(hWnd, &ps);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return FALSE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement