Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GUI app and winAPI calls
#43
This is how typical C++ app should look:


#include <windows.h>

/* window procedure */
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR cmdParam, int cmdShow)
{
    MSG messages;        /* for messages queue manipulation */
    WNDCLASSEX WndClass; /* data struct for window class */
    HWND hWnd;          /* handle for window */

    /* define window class */
    WndClass.cbSize = sizeof(WNDCLASSEX);
    WndClass.style = CS_DBLCLKS;
    WndClass.hInstance = hInst;
    WndClass.lpszClassName = "WindowClassName";
    WndClass.lpfnWndProc = WndProc;

    /* icons, cursor and menu */
    WndClass.hIcon = LoadIcon(hInst, "MAINICON"); /* default icon */
    WndClass.hIconSm = LoadIcon(hInst, "MAINICON"); /* default icon */
    WndClass.hCursor = LoadCursor(NULL, IDC_ARROW); /* cursor */
    WndClass.lpszMenuName = NULL; /* no menu */
    WndClass.cbClsExtra = 0;
    WndClass.cbWndExtra = 0;

    /* window background color */
    WndClass.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
    RegisterClassEx(&WndClass);
   
    hWnd = CreateWindowEx(0,                    /* extended window style */
                          "WindowClassName",    /* registered class */
                          "Windows Application", /* window title */
                          WS_OVERLAPPEDWINDOW,  /* default window style */
                          CW_USEDEFAULT,        /* x position */
                          CW_USEDEFAULT,        /* y position */
                          640,                  /* width of window */
                          480,                  /* heigth of window */
                          HWND_DESKTOP,          /* The window is a child-window to desktop */
                          NULL,                  /* no menu */
                          hInst,                /* Program Instance handler */
                          NULL);                /* No Window Creation data */
                         
    ShowWindow(hWnd, SW_SHOW);
    UpdateWindow(hWnd); 

    /* loop messages. run until GetMessage return 0*/ 
    while (GetMessage(&messages, NULL, 0, 0))
    {
        TranslateMessage(&messages); /* translate virtual keys into character messages*/
        DispatchMessage(&messages);  /* Send message to WndProc */
    }
    /* return value to system */
    return messages.wParam;
}

/*  This function is called by the Windows function DispatchMessage()  */
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_DESTROY:
            PostQuitMessage(0); /* send a WM_QUIT to the message queue */
            break;
        default:                /* for messages that we don't deal with */
            return DefWindowProc(hwnd, message, wParam, lParam);
    }
    return 0;
}
Reply


Messages In This Thread
GUI app and winAPI calls - by aurel - 03-22-2023, 02:23 PM
RE: GUI app and winAPI calls - by SpriggsySpriggs - 03-22-2023, 02:26 PM
RE: GUI app and winAPI calls - by aurel - 03-22-2023, 05:24 PM
RE: GUI app and winAPI calls - by aurel - 03-22-2023, 06:10 PM
RE: GUI app and winAPI calls - by aurel - 03-22-2023, 06:23 PM
RE: GUI app and winAPI calls - by aurel - 03-22-2023, 07:21 PM
RE: GUI app and winAPI calls - by SpriggsySpriggs - 03-22-2023, 08:05 PM
RE: GUI app and winAPI calls - by aurel - 03-22-2023, 08:13 PM
RE: GUI app and winAPI calls - by mnrvovrfc - 03-22-2023, 08:33 PM
RE: GUI app and winAPI calls - by SpriggsySpriggs - 03-22-2023, 08:34 PM
RE: GUI app and winAPI calls - by aurel - 03-22-2023, 09:13 PM
RE: GUI app and winAPI calls - by SpriggsySpriggs - 03-22-2023, 09:23 PM
RE: GUI app and winAPI calls - by aurel - 03-22-2023, 09:35 PM
RE: GUI app and winAPI calls - by aurel - 03-22-2023, 09:39 PM
RE: GUI app and winAPI calls - by SpriggsySpriggs - 03-22-2023, 11:45 PM
RE: GUI app and winAPI calls - by aurel - 03-23-2023, 07:38 AM
RE: GUI app and winAPI calls - by SpriggsySpriggs - 03-23-2023, 01:03 PM
RE: GUI app and winAPI calls - by aurel - 03-23-2023, 05:26 PM
RE: GUI app and winAPI calls - by aurel - 03-23-2023, 07:18 PM
RE: GUI app and winAPI calls - by aurel - 03-23-2023, 07:29 PM
RE: GUI app and winAPI calls - by SpriggsySpriggs - 03-23-2023, 07:33 PM
RE: GUI app and winAPI calls - by mnrvovrfc - 03-23-2023, 07:51 PM
RE: GUI app and winAPI calls - by vince - 03-23-2023, 08:07 PM
RE: GUI app and winAPI calls - by mnrvovrfc - 03-23-2023, 08:41 PM
RE: GUI app and winAPI calls - by aurel - 03-23-2023, 08:25 PM
RE: GUI app and winAPI calls - by aurel - 03-23-2023, 08:41 PM
RE: GUI app and winAPI calls - by SpriggsySpriggs - 03-23-2023, 08:53 PM
RE: GUI app and winAPI calls - by vince - 03-23-2023, 08:50 PM
RE: GUI app and winAPI calls - by aurel - 03-23-2023, 08:51 PM
RE: GUI app and winAPI calls - by aurel - 03-23-2023, 08:53 PM
RE: GUI app and winAPI calls - by aurel - 03-23-2023, 09:00 PM
RE: GUI app and winAPI calls - by aurel - 03-23-2023, 09:07 PM
RE: GUI app and winAPI calls - by aurel - 03-23-2023, 09:09 PM
RE: GUI app and winAPI calls - by SpriggsySpriggs - 03-23-2023, 09:11 PM
RE: GUI app and winAPI calls - by vince - 03-23-2023, 09:21 PM
RE: GUI app and winAPI calls - by aurel - 03-24-2023, 06:33 AM
RE: GUI app and winAPI calls - by mnrvovrfc - 03-24-2023, 07:12 AM
RE: GUI app and winAPI calls - by aurel - 03-24-2023, 09:27 AM
RE: GUI app and winAPI calls - by aurel - 03-24-2023, 09:51 AM
RE: GUI app and winAPI calls - by mnrvovrfc - 03-24-2023, 06:19 PM
RE: GUI app and winAPI calls - by aurel - 03-24-2023, 02:49 PM
RE: GUI app and winAPI calls - by aurel - 03-24-2023, 08:43 PM
RE: GUI app and winAPI calls - by aurel - 03-24-2023, 08:49 PM
RE: GUI app and winAPI calls - by aurel - 03-25-2023, 04:28 PM
RE: GUI app and winAPI calls - by aurel - 03-25-2023, 07:32 PM
RE: GUI app and winAPI calls - by aurel - 03-25-2023, 09:35 PM
RE: GUI app and winAPI calls - by RhoSigma - 03-25-2023, 10:44 PM
RE: GUI app and winAPI calls - by aurel - 03-26-2023, 07:16 AM
RE: GUI app and winAPI calls - by RhoSigma - 03-26-2023, 08:39 AM



Users browsing this thread: 4 Guest(s)