My dream begin....since 2 days i learning C

For everything that's not in any way related to PureBasic. General chat etc...
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: My dream begin....since 2 days i learning C

Post by Kwai chang caine »

Thanks.... 8)
It's back to the source .... even if sometimes it hurts the feet after a while :lol:
ImageThe happiness is a road...
Not a destination
User avatar
flaith
Enthusiast
Enthusiast
Posts: 704
Joined: Mon Apr 25, 2005 9:28 pm
Location: $300:20 58 FC 60 - Rennes
Contact:

Re: My dream begin....since 2 days i learning C

Post by flaith »

Kwaï chang caïne wrote:..i want just a simple answer, at your advice at all...
The answer is ... 42 :mrgreen:
(no offence KCC, just kidding)
“Fear is a reaction. Courage is a decision.” - WC
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: My dream begin....since 2 days i learning C

Post by Kwai chang caine »

42 :shock:
It's your age ??
ImageThe happiness is a road...
Not a destination
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Re: My dream begin....since 2 days i learning C

Post by LuCiFeR[SD] »

Kwaï chang caïne wrote:42 :shock:
It's your age ??
hehehe, not his age, but it is the answer to the "Ultimate Question of Life, the Universe and Everything" :)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: My dream begin....since 2 days i learning C

Post by Kwai chang caine »

Aaaah ok ...again a thing i don't know :oops:
http://en.wikipedia.org/wiki/42_%28number%29
How can you do all, for knowing so much things that KCC don't know :?

You are several life ??
In fact you have 5236 years ??? and hide your real age :lol:

So Kcc don't have an enough big head to know all of that :oops:
He just want to know if the WaitWindowsEvent is the same thing that the while (GetMessage(&msg, NULL, 0, 0)) it's all :cry:

For the 42 ...i wait a little bit for reading this ..it's a little bit simple for me :mrgreen:
Image
ImageThe happiness is a road...
Not a destination
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Re: My dream begin....since 2 days i learning C

Post by LuCiFeR[SD] »

ROFL! KCC, I am not Krishna :)... I am much older than that... closer to 4.6 billion years old hehehe
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: My dream begin....since 2 days i learning C

Post by Kwai chang caine »

:lol: :lol:
If you are so old .....you know surely GOD ???
The next time you eat with him....can you ask if the WaitWindowsEvent is the same thing that the while (GetMessage(&msg, NULL, 0, 0)) :D
I'm sure that at less GOD, know that :mrgreen:
ImageThe happiness is a road...
Not a destination
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Re: My dream begin....since 2 days i learning C

Post by LuCiFeR[SD] »

Sorry, I don't know this "god" you speak of?... Is he the one who threw me out of heaven? :P

haha, For goodness sake KCC, if it "behaves" like waitWindowEvent(), as in it waits for a message, then it is correct... if it doesn't wait... then it is behaving like WindowEvent(). There are literally thousands if not MILLIONS of C/C++ tutorials out there :). Just learn the correct way pass the events you wish to trap :P

I know you think I am being horrible and teasing you, and you would be correct :P BUT, I still love you old friend :P
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: My dream begin....since 2 days i learning C

Post by Kwai chang caine »

There are literally thousands if not MILLIONS of C/C++ tutorials out there
Perhaps, but there are much more less tutorial about PB and his event :cry:
My only problem is just for know if PB have the same behaviour like C in this case.

Apparently yes, because PB have WaitWindowEvent and C (GetMessage(&msg, NULL, 0, 0))
But i have asking in forum C, and nobody understand why i don't want use callback like everybody :twisted:

So i can't say, it's because in MY LANGUAGE i have two possiblity for managing events
1/ WaitWindowEvent
2/ CallBack
And i'm not forced to use CallBack in my language :D

So for my translate, i must know if in C, it's possible to manage the event in this loop like PB

Code: Select all

while (GetMessage(&msg, NULL, 0, 0))
{   
    TranslateMessage(&msg);
    DispatchMessage(&msg);
   }
I have try..but the result his not really at the top :oops:
If it's possible i continue my search, and i'm sure i found, how..
But if it's impossible, because C, don't allow that...this is not the pain i continued to search in this way, and just translate the WaitWindowEvent by a CallBack each time

So i say to me, perhaps FRED have "simply" hiding behind

Code: Select all

Repeat
Evenement = WaitWindowEvent()
Until Evenement = #PB_Event_CloseWindow
a CallBack ???
I know you think I am being horrible and teasing you, and you would be correct :P BUT, I still love you old friend :P
Don't worry LUCIFER..i know that, but even if my friend don't want to answer me....
At who, i can ask all my stupids questions :oops:
ImageThe happiness is a road...
Not a destination
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: My dream begin....since 2 days i learning C

Post by Mistrel »

It's not the same, Kwaï chang caïne. :wink:

There are messages that hit the WndProc but not the message pump. In C++ I would use a double ended queue where new messages from both the WndProc and the message pump were put on top and old messages (processed by Wait/WindowEvent) are taken from the bottom.

Also be sure to ignore #WM_NULL.

The fun part will be adding support for threads. Obviously, you can't use the same queue for all threads!
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Re: My dream begin....since 2 days i learning C

Post by LuCiFeR[SD] »

and I would change

Code: Select all

while (GetMessage(&msg, NULL, 0, 0))
to

Code: Select all

while(GetMessage(&Msg, NULL, 0, 0) > 0)
:)
User avatar
Blood
Enthusiast
Enthusiast
Posts: 161
Joined: Tue Dec 08, 2009 8:34 pm
Location: United Kingdom

Re: My dream begin....since 2 days i learning C

Post by Blood »

LuCiFeR[SD] wrote:and I would change

Code: Select all

while (GetMessage(&msg, NULL, 0, 0))
to

Code: Select all

while(GetMessage(&Msg, NULL, 0, 0) > 0)
:)
or

Code: Select all

BOOL bRet;

while( (bRet = GetMessage( &msg, hWnd, 0, 0 )) != 0)
{ 
    if (bRet == -1)
    {
        // handle the error and possibly exit
    }
    else
    {
        TranslateMessage(&msg); 
        DispatchMessage(&msg); 
    }
}
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
C provides the infinitely-abusable goto statement, and labels to branch to. Formally, the goto is never necessary, and in practice it is almost always easy to write code without it. We have not used goto in this book. -- K&R (2nd Ed.) : Page 65
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: My dream begin....since 2 days i learning C

Post by Kwai chang caine »

Thanks a lot my friends !!!! 8)
I have finally my answer :shock:
Friend MISTREL wrote:It's not the same, Kwaï chang caïne. :wink:
There are messages that hit the WndProc but not the message pump. In C++ I would use a double ended queue where new messages from both the WndProc and the message pump were put on top and old messages (processed by Wait/WindowEvent) are taken from the bottom.
Also be sure to ignore #WM_NULL.
Ok, so i can't use the while (GetMessage(&msg, NULL, 0, 0)) like WaitWindowEvent :cry:
It's a pity, because it would have been far too simple :lol:
And sweet and simple is not army C programming :mrgreen:
Friend MISTREL wrote:The fun part will be adding support for threads. Obviously, you can't use the same queue for all threads!
Oh lala !!! for the thread .....it's perhaps my son, or little son who coding this part :lol:

Me i just want if it's possible to manage events like this, without passing by callback

Code: Select all

BOOL bRet;
while( (bRet = GetMessage( &msg, hWnd, 0, 0 )) != 0)
{
    if (bRet == -1)
    {
        // handle the error and possibly exit
    }
    else
    {
      switch bRet
      {
       case HwndButton1
        // handle of first button 
       case HwndButton2
        // handle of second button 
      case WM_LBUTTONUP
       etc ...
    }

    }
}
But apparently...it's not possible :cry:
Well, i try to always use a callback for manage events in my translate

I convert all PB events, by a callback before

Code: Select all

Repeat
 Evenement = WaitWindowEvent()
 Select Evenement
  Case #xxxxxxxxx
  Case #xxxxxxxx
 EndSelect
Until Evenement = #PB_Event_CloseWindow
by

Code: Select all

Procedure WinCallback(hWnd, uMsg, wParam, lParam) 
  If hWnd = xxxxx
   If uMsg = #xxxx
    Select wParam 
    Case #xxxxx
     EndSelect 
   EndIf 
  EndIf
  ProcedureReturn #PB_ProcessPureBasicEvents 
EndProcedure 
    
SetWindowCallback(@WinCallback())
And after convert in c, in a callback too :wink:

Thanks a lot again my all friends 8)
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: My dream begin....since 2 days i learning C

Post by Kwai chang caine »

You don't believe that...Kcc after long time begin his dream, coding several lines in C, for begin his code to translate PB to C :shock:

So it's just the beginning, of the beginning of the start...
But i'm so happy that i want sharing my happiness with you :D

For the moment, i just translate some case of OpenWindows :oops:
But it's already a beginning no ????? :mrgreen:

You can try
OpenWindow(1, 648, 417, 265, 176, "FenetrePB", #PB_Window_ScreenCentered|#WS_POPUP)
OpenWindow(1, 648, 417, 265, 176, "FenetrePB", #PB_Window_ScreenCentered|#PB_Window_SizeGadget)
OpenWindow(1, 30, 30, 100, 100, "FenetrePB", #PB_Window_SizeGadget)
OpenWindow(1, 648, 417, 265, 176, "FenetrePB")

But after..i add #PB_Window_Minimize, #PB_Window_Maximize, etc...
There are giant works...there are so much functions, FRED is not an idle :shock:
I don't know if a day i can terminate him, but i'm happy to have starting :D

So now, i must go to eat and sleep, or else my whife hurt me with his broomstick. :lol:

This is my little beginning works
http://erdsjb.free.fr//PureStorage/Provisoire/Pb2C.zip

But i need help of my friends for can continue my adventure :oops:

I want to create two windows not MDI in C
And i don't know how :oops:
So i have copy the CodeBlock code and paste two time the code
Putting it in two procedure, but i'm sure there are too much sentence
Furthermore, it's just the first windows who appears :(

Someone can help me, to reduce the code, without changing the form please,please, please
Because if you made too difficult code, KCC don't understanding it, and not move :oops:
Just simplify the lines in procedure, move the line if she's not at his place, it's already a good help for me 8)
I don't want create the better and optimize translater of the world, just a simple translater for can passing all my numerous code from PB in C automaticaly :D

1/ Just make global the sentence who is for the two windows
2/ i don't know if i must managing two callback :oops:
3/ And obviously fix the bug of see only the first windows

Code: Select all

#include <windows.h>

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure1 (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK WindowProcedure2 (HWND, UINT, WPARAM, LPARAM);
int Fenetre1(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow);
int Fenetre2(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow);

/*  Make the class name into a global variable  */
char szClassName[ ] = "CodeBlocksWindowsApp";

int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow){

 int message1;            /* Here messages to the application are saved */
 int message2;            /* Here messages to the application are saved */
 message1 = Fenetre1(hThisInstance, hPrevInstance, lpszArgument,nCmdShow);
 message2 = Fenetre2(hThisInstance, hPrevInstance, lpszArgument,nCmdShow);

 return message1;

}

int Fenetre1(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow){

    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure1;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default colour as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Fenetre 1",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nCmdShow);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}
/*  This function is called by the Windows function DispatchMessage()  */

int Fenetre2(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow){

    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure2;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default colour as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Fenetre 2",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nCmdShow);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}

/*  This function is called by the Windows function DispatchMessage()  */
LRESULT CALLBACK WindowProcedure1 (HWND hwnd, UINT message1, WPARAM wParam, LPARAM lParam)
{
    switch (message1)                  /* handle the messages */
    {
        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, message1, wParam, lParam);
    }

    return 0;
}

/*  This function is called by the Windows function DispatchMessage()  */
LRESULT CALLBACK WindowProcedure2 (HWND hwnd, UINT message2, WPARAM wParam, LPARAM lParam)
{
    switch (message2)                  /* handle the messages */
    {
        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, message2, wParam, lParam);
    }

    return 0;
}
Thanks in advance
ImageThe happiness is a road...
Not a destination
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Re: My dream begin....since 2 days i learning C

Post by kinglestat »

I love C....since when I started using it 23 years ago way way back
and I still use it. But if I may offer a suggestion why make a program just in C?
You should stick with GUI stuff in PB and utilize C for optimizing regions of code and make multi-panguage programs. It is what I do. Critical level code is written in C as libs and I use importc.
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
Post Reply