Page 1 of 1

CreateWindow_() example?

Posted: Sun Feb 21, 2010 6:49 pm
by Nituvious
Can somebody give me an example on this? I've tried something like:

Code: Select all

createwindow_("WindowClass","Window",#WS_VISIBLE | #WS_BORDER,1,1,200,200,0,0,0,1)
Repeat
AnEvent=0
Until AnEvent=1

Re: CreateWindow_() example?

Posted: Sun Feb 21, 2010 7:32 pm
by netmaestro
There's a very similar example on PureArea, it's a good place to look for new ideas:

Code: Select all

Procedure WindowCallback(Window, Message, wParam, lParam) 
  Select Message 
    Case #WM_CLOSE 
      DestroyWindow_(Window) 
    Case #WM_DESTROY 
      PostQuitMessage_(0) 
      Result  = 0 
    Default 
      Result  = DefWindowProc_(Window, Message, wParam, lParam) 
  EndSelect 
  ProcedureReturn Result 
EndProcedure 

#Style  = #WS_VISIBLE | #WS_CAPTION | #WS_SYSMENU 
WindowClass.s  = "WindowClass_227B" 
wc.WNDCLASSEX 
wc\cbSize  = SizeOf(WNDCLASSEX) 
wc\hbrBackground = CreateSolidBrush_(GetSysColor_(#COLOR_BTNFACE))
wc\hCursor = LoadCursor_(0, #IDC_ARROW)
wc\lpfnWndProc  = @WindowCallback() 
wc\lpszClassName  = @WindowClass 
RegisterClassEx_(@wc) 

screenx = GetSystemMetrics_(#SM_CXSCREEN)/2-320/2
screeny = GetSystemMetrics_(#SM_CYSCREEN)/2-240/2

hWndMain  = CreateWindow_( WindowClass, "Test Window", #Style, screenx, screeny, 320, 240, 0, 0, 0, 0) 

While GetMessage_(msg.MSG, #Null, 0, 0 ) 
  TranslateMessage_(msg) 
  DispatchMessage_(msg) 
Wend 

Re: CreateWindow_() example?

Posted: Sun Feb 21, 2010 9:03 pm
by Nituvious
Darn, I was hoping it wouldn't be this complicated.. oh well :(

Re: CreateWindow_() example?

Posted: Sun Feb 21, 2010 9:33 pm
by Fred
API is complicated. Often very complicated.

Re: CreateWindow_() example?

Posted: Sun Feb 21, 2010 10:45 pm
by Nituvious
Fred wrote:API is complicated. Often very complicated.
Yes. I shall stab it. That'll learn it to be complicated!

Re: CreateWindow_() example?

Posted: Mon Feb 22, 2010 10:48 am
by srod
I find the api very logical and, the bits that I regularly use anhow, very simple to use. It's like anything, given enough time and practice, it is there to be mastered! It is certainly nothing to fear. :)

Re: CreateWindow_() example?

Posted: Mon Feb 22, 2010 11:14 am
by Kwai chang caine
Hi at all 8)

It's a crazy thing :shock:
"I have a dream" Like someone in the history of the humanity :roll:

A day can code in C++, i have this dream before meet PB
But with PB..i have found the power without the difficulty

So i have never forgotten my dream :(
Because for me...a programmer is not a real programmer, if he don't know a little bit of ASM or C :roll:

I have buy numerous books on the C/C++, and Visual studio 6 language , and Borland builder language...
But i have not understand is not sufficient to buy...the most important is to learn this books :oops:

And you know KCC....he have a bidet a the place of his brain...
KCC his already so happy to can touch with the end of the nail of his foot, the programming, thanks to FRED, PB and all of you when you help me so much 8)

Well all that for say, that this Week end, i have try to begin a new idea.
Create a PB == > C++ converter :D

The name of my frech thread is : "My dream in C major"
http://www.purebasic.fr/french/viewtopi ... 40#p109540

For help the mule like me to simply convert a simple PB code to VC++
Like PB convert PB code to ASM natively...i'm surprising nobody have this idea...for help to begin to learn the C
So use the facility of PB...for learn difficult API C :D

A french man ZAPMAN have the idea to create the contrary C ==> PB, and even FRED is interesting :D
http://www.purebasic.fr/french/viewtopi ... 4547#p4547
But it's a too long project, and he stop his works before the end :(

The C is the Creator...and SROD say PB compiler is created with him, and FRED say he have right :shock:
I love PB and never quit it..all the time i programming :?
But for me it's a good option for PB...the only C++ language translator ..

Like NETMAESTRO give this splendid code...i see with surprise, it's nearly the same that the C++ :shock:

Code: Select all

#include <windows.h>

LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
HWND hWnd;

const HBRUSH hCouleur_Jaune   =  CreateSolidBrush(RGB(255,255,0));
HBRUSH hBackground = hCouleur_Jaune;
static char szClassName[ ] = "Fenêtre Windows simple";

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

WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpfnWndProc = WindowProcedure;
wincl.hbrBackground = hBackground;
wincl.style = CS_HREDRAW | CS_VREDRAW;
wincl.lpszClassName = szClassName;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;

if (RegisterClassEx (&wincl) == false) // On enregistre la classe déclarée avec WNDCLASSEX
  return 0 ;   //  et en cas d'erreur on quitte le programme

hWnd = CreateWindowEx (0, szClassName, "Fenetre simple", WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, 644, 475, HWND_DESKTOP, NULL, hThisInstance, NULL);
ShowWindow(hWnd, nCmdShow);

MSG messages;

  while (GetMessage (&messages, NULL, 0, 0)){
   TranslateMessage(&messages);
   DispatchMessage(&messages);
  }

  return messages.wParam;
  
}

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){

switch (message){

  case WM_DESTROY:

   PostQuitMessage (0);       // envoie un message WM_QUIT dans la file d'attente
   break;

  default:

   return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;

}
So i don't want to talk to you of my project, because he just begin ...and i have not again create the first procedure :oops:
And i don't know anything of C....even not one word...so my project is not again finish :lol: :lol: :lol:

My idea is..if each person he know C++ create in the same THREAD one function.
One person create the Window..other a button, other...a textgadget.
After it's easy to use all the procedure and create a parser for the C++
Because this project for only one person, is certainly too long....and this project his certainly died before to born

Perhaps later i have the time to continue my idea...
But it's a real coincidence that NITUVIOUS ask nearly the same question like me....

Apparently..the API is really difficult...FRED is a mother for us to protect of all this CLASSE...CallBack etc ... 8)
Excuse me NITUVIOUS, for disturb your THREAD, but your question have so surprising me :oops:

Have all a good day 8)

Re: CreateWindow_() example?

Posted: Mon Feb 22, 2010 12:07 pm
by IdeasVacuum
PB to C/C++ :mrgreen: That would be like removing the wheels of your bicycle and replacing them with square slabs of concrete....

C is easy to learn, it only has 32 "keywords" in total, but to produce serious industrial-strength applications with a GUI requires a lot of effort, you can get better results faster with PB.

Re: CreateWindow_() example?

Posted: Mon Feb 22, 2010 12:16 pm
by Kwai chang caine
Yes i know, several members thinks it's crazy idea... :oops:
But learn a litle bit of C++, help to understand why the callback, and all this hard function exist ...

I think for someone, PB can help so much to create a little code in C, for better understand and beginning this parent language..

I understand that for all of you, who know the C...it's a ridiculous idea...
So in the french forum....it's exactely the same reaction :oops:
But...i hope that perhaps in the world, i'm not alone to want know the beginning of the programming :roll:

If a day PB can convert in C++ and ASM....he can talk with the two MASTERS and universal language.... 8)

Re: CreateWindow_() example?

Posted: Mon Feb 22, 2010 3:07 pm
by eriansa
I don't think it's a stupid idea to convert PB to C, and let a great C compiler (GCC) do all the optimizations for you...

(OTOH that convertor isn't something I would like to write :wink: )

Re: CreateWindow_() example?

Posted: Mon Feb 22, 2010 3:53 pm
by Kwai chang caine
Thanks ERANSIA 8)
I'm happy, finally someone who does not take me for a fool :wink:

I say to me, that perhaps, instruction by instruction, i can create this converter, even if i don't know anything in C :roll:

In the first time, for create windows, and gadgets.
And little bit by little bit, convert event.....

There is example in the net of C code.
So i have found this simple example above and delete useless line for have only the windows.
And, i'm so happy to see, that the example of NETMAESTRO is nearly the same that mine.

I don't understand what i write...but that works :lol: :lol:

Certainely, that a moment it's impossible to translate, because code too much difficult.

But it's a little bit like GOOGLE translate french/english.
All of you,... pull your hair, for understand my bad english...but in final, you understand approximately me
And even my MASTER SROD understand me after several years of learning my "Frenglish" :mrgreen:
So with my converter....the processor has the same problem...but the advantage it's that a processor don't have hairs :lol: :lol:
OTOH that convertor isn't something I would like to write
It's a pity, because there is so much people in this forum who know the C 8)
That if only one person create one procedure...even little...i think 80 % of the converter is create quickly
And an open source project, (Like COMATE 8) ) furthermore a product of community of PB member 8)

See the procedure for create a windows...she is not really long..
I think it's perhaps the same thing for a button, Text....etc .. :roll:

Never mind, when i have a little time i begin to create my window procedure, alone like a great :lol:
A friend in french forum give me good advice, to use CodeBlock...it's a really nice IDE 8)
And i use MinGW like compiler....

A question i ask to me....but never my GOD FRED answer me....
The PB compiler is made in C....but whith what compiler and IDE ?? :roll:

Re: CreateWindow_() example?

Posted: Tue Nov 02, 2010 9:30 pm
by idle
A question i ask to me....but never my GOD FRED answer me....
The PB compiler is made in C....but whith what compiler and IDE ?? :roll:
Think it's now done with Visual Studio.

Also if you are interested in porting pb to c take a look at BCX it may be useful

https://bcx-basic.svn.sourceforge.net/s ... unk/bc.bas

Re: CreateWindow_() example?

Posted: Thu Nov 04, 2010 7:37 am
by Nituvious
Wow! I must have learned A LOT more than I thought I did since my first days of PureBasic! :shock: :oops:
So embarrassing!

Re: CreateWindow_() example?

Posted: Thu Nov 04, 2010 10:48 am
by Kwai chang caine
IDLE wrote:Think it's now done with Visual Studio.
Visual studio :shock: you believe ????? :shock:
Yet i'm not sure it's the better compiler for the C now ????

Perhaps FRED have beginning with VS and forced to continue with the same ???
He say to me, his favorite is QT now...

But Kcc don't know anything at the C, so it's not a real reference :lol:
I continue to learn C with kind french member of french forum C.
Like usually KCC begin back to front :oops:
My first code is a window and three button, and callback
Thanks to FRED, kcc is not lost, just for know where he must put his code ???
But now the kinds members give to KCC a lesson on the .h and .c, and this week end....i can continue to learn 8)

Thanks for your link .....i see it and say to you news