Dear Sirs;
I am new to programming and forums and I need help.
How do I write code in a windows application and get the practice code to
appear in the window?
When I use the console application or an empty source everything works jsut
fine.
Any help would be greatly appreciated.
Thanks,
Neferkamichael1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
By the question you ask, I assume you mean: "how do I write windows gui
programs in C/C++" ?
If that is the case, then, I also assume by our statement, that you have
written the standard C introductory console mode apps, such as the console
mode "hello world":
You will find that windows gui programming requires considerably more code to
display to the screen, as conpared to console mode apps. Here is a simple
windows gui "hello world" type app:
#include<windows.h>LRESULTCALLBACKWndProc(HWND,UINT,WPARAM,LPARAM);intWINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPSTRlpCmdLine,intnCmdShow){staticcharszAppName[]="HelloWin";HWNDhwnd;MSGmsg;WNDCLASSwndclass;if(!hPrevInstance){wndclass.style=CS_HREDRAW|CS_VREDRAW;wndclass.lpfnWndProc=WndProc;wndclass.cbClsExtra=0;wndclass.cbWndExtra=0;wndclass.hInstance=hInstance;wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);wndclass.lpszMenuName=NULL;wndclass.lpszClassName=szAppName;RegisterClass(&wndclass);}hwnd=CreateWindow(szAppName,"The Hello Program",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);ShowWindow(hwnd,nCmdShow);UpdateWindow(hwnd);while(GetMessage(&msg,NULL,0,0)){TranslateMessage(&msg);DispatchMessage(&msg);}returnmsg.wParam;}/* ------- end WinMain ------- */LRESULTCALLBACKWndProc(HWNDhwnd,UINTmessage,WPARAMwParam,LPARAMlParam){HDChdc;PAINTSTRUCTps;RECTrect;switch(message){caseWM_PAINT:hdc=BeginPaint(hwnd,&ps);GetClientRect(hwnd,&rect);DrawText(hdc,"Hello, Windows!",-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);EndPaint(hwnd,&ps);return0;caseWM_DESTROY:PostQuitMessage(0);return0;}returnDefWindowProc(hwnd,message,wParam,lParam);}/*--------- end WndProc ---------*/
Sarbayo,
Thank you for the response.
As a beginner I don't enough at the present time to ask the right questions.
Since my post I have read more and practiced writing examples. ?How to I write
the the code and have it execute in the client area of a window. Thank you for
the example and directions to tutorials.
Neferkamichael1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sarbayo,
I dontknow hwhat I did wrong. I copied your example to a source file and when
I compile it I get a undefined reference to 'GetStockObject@4', Id returned 1
exit status. Any advice.
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry for the delay getting back to you.
The solution is quite simple.
What is needed is to tell the linker where to find that function
(GetStockObject()).
In Dev-C++,
1) click on the Projects tab,
2) click "Project Options"
3) click "Parameters"
4) under "Linker", where it says: "Add Library or Object",
click that button,
5) scan across the list until you find "libgdi32.a"
that is the library that contains GetStockObject.
Double click on "libgdi32.a".
6) that will place "libgdi32.a" in the linker list,
7) click on the OK button to close that window,
8) Under FILE, click on "Save All", (just for good measure),
9) Under Execute, click on "Rebuild All"
10) now, if there are no more errors, click on RUN.
That should be it.
Sometimes, how you create the project will determine what files you need to
tell the linker about.
Also, whether or not it's a C or a C++ project.
Hope this helps,
Steve
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm not a true windows programmer, but I think you can use message boxes too.
Unfortunately I dont know all the headers and files and syntax needed to do
the job.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Dear Sirs;
I am new to programming and forums and I need help.
How do I write code in a windows application and get the practice code to
appear in the window?
When I use the console application or an empty source everything works jsut
fine.
Any help would be greatly appreciated.
Thanks,
Neferkamichael1
By the question you ask, I assume you mean: "how do I write windows gui
programs in C/C++" ?
If that is the case, then, I also assume by our statement, that you have
written the standard C introductory console mode apps, such as the console
mode "hello world":
You will find that windows gui programming requires considerably more code to
display to the screen, as conpared to console mode apps. Here is a simple
windows gui "hello world" type app:
You can find C/C++ GUI programming tutorials on the web.
Simply Google: "C/C++"+"gui programming"
include the quotes.
I would recommend Charles Petzold's book: "Programming Windows (5th Edition)":
http://www.amazon.com/Programming-Windows-Microsoft-Charles-Petzold/dp/157231
995X/ref=sr_1_1?s=books&ie=UTF8&qid=1291133446&sr=1-1
Get a new or "clean" used copy for cheap.
Considered by many to be one of the best "Windows, GUI, C/C++" tutorials
available.
Steve
Well,
that post came out totally screwed up !
Sarbayo,
Thank you for the response.
As a beginner I don't enough at the present time to ask the right questions.
Since my post I have read more and practiced writing examples. ?How to I write
the the code and have it execute in the client area of a window. Thank you for
the example and directions to tutorials.
Neferkamichael1
Sarbayo,
I dontknow hwhat I did wrong. I copied your example to a source file and when
I compile it I get a undefined reference to 'GetStockObject@4', Id returned 1
exit status. Any advice.
Thanks
Sorry for the delay getting back to you.
The solution is quite simple.
What is needed is to tell the linker where to find that function
(GetStockObject()).
In Dev-C++,
1) click on the Projects tab,
2) click "Project Options"
3) click "Parameters"
4) under "Linker", where it says: "Add Library or Object",
click that button,
5) scan across the list until you find "libgdi32.a"
that is the library that contains GetStockObject.
Double click on "libgdi32.a".
6) that will place "libgdi32.a" in the linker list,
7) click on the OK button to close that window,
8) Under FILE, click on "Save All", (just for good measure),
9) Under Execute, click on "Rebuild All"
10) now, if there are no more errors, click on RUN.
That should be it.
Sometimes, how you create the project will determine what files you need to
tell the linker about.
Also, whether or not it's a C or a C++ project.
Hope this helps,
Steve
I'm not a true windows programmer, but I think you can use message boxes too.
Unfortunately I dont know all the headers and files and syntax needed to do
the job.