Post Reply 
Social Buttons
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adventures in C ?
01-09-2019, 06:42 PM
Post: #1
Adventures in C ?
Hello Ed
I finally print hdc text inside WM_PAINT message in Falcon C++ IDE
how?
I found one example somewhere.
As i said before i forget that i do a lot of work in Oxygen Basic
creating my own awinh.inc include file which do that automatically.
But here in C it looks that i must adapt my own incude for C.
I have some questions if is not problem.

1.
Can i create in C functions in a similar way like i do that in Oxygen?

2.
Is it good to create double buffering on my own way like in
oxygen or is better to use already published methods on net?

Code:
#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)
{
HDC hdc;
PAINTSTRUCT ps;
LPSTR szMessage = "Hello Falcon C++ by Aurel!";
    
    switch (message)
    
    {
        case WM_PAINT:
         hdc = BeginPaint(hwnd, &ps);
         TextOut(hdc, 70, 50, szMessage, strlen(szMessage));
         EndPaint(hwnd, &ps);
         break;    
            
            
        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;
}


Attached File(s) Image(s)
   
Find all posts by this user
Quote this message in a reply
01-09-2019, 10:30 PM
Post: #2
RE: Adventures in C ?
(01-09-2019 06:42 PM)Aurel Wrote:  Hello Ed
I finally print hdc text inside WM_PAINT message in Falcon C++ IDE
how?
I found one example somewhere.
As i said before i forget that i do a lot of work in Oxygen Basic
creating my own awinh.inc include file which do that automatically.
But here in C it looks that i must adapt my own incude for C.
I have some questions if is not problem.

1.
Can i create in C functions in a similar way like i do that in Oxygen?

Of course - only better :-)

Quote:2.
Is it good to create double buffering on my own way like in
oxygen or is better to use already published methods on net?

It is up to you. Depends on how much time it will take you to create your own, vs. how long it'll take to find one, vs. if the one you find is good enough, and so on.
Find all posts by this user
Quote this message in a reply
01-09-2019, 11:57 PM
Post: #3
RE: Adventures in C ?
Thanks Ed

Yes that really depend on many factors
I will try first ordinary GUI programs with controls and similar
in C ..they are almost same with little bit different syntax..
when you say C is case sensitive haa i figured
HDC hdc;
that why is such a thing possible in C..
interesting..
Find all posts by this user
Quote this message in a reply
01-10-2019, 06:04 AM
Post: #4
RE: Adventures in C ?
Udated example with STATIC control
well so far looks fine ! Big Grin

Code:
#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)
{
HDC hdc;
PAINTSTRUCT ps;
LPSTR ptext = "Hello Falcon C++ by Aurel!";
LPSTR lyrics  ="This is Static Control";
    
    switch (message)
    
    {
    //-------------------------------------------------------------------------    
     case WM_CREATE:
              // -- STATIC CONTROL ---
            CreateWindowExA(0x200,"Static", lyrics,
                WS_CHILD | WS_VISIBLE | SS_LEFT,
                20, 80, 300, 30,
                hwnd, (HMENU) 1, NULL, NULL);
            break;
    //-------------------------------------------------------------------------
            
        case WM_PAINT:
         hdc = BeginPaint(hwnd, &ps);
         TextOut(hdc, 20, 20, ptext, strlen(ptext));
         EndPaint(hwnd, &ps);
         break;    
            
            
        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;
}
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: