View Full Version : C++ Window basics
Active X
11-06-2007, 07:58 AM
Hello to everyone reading this .
I wanna use windows in C++ but I'm too confused of referring to resources about how to write a program in C++ to create a window .
Could provide help ? Will be thankful :thumbsup:
Inigoesdr
11-06-2007, 05:13 PM
Try out wxWidgets (http://www.wxwidgets.org/).
Active X
11-07-2007, 08:14 PM
However didn't find THAT useful but Tanks anyway ! ;-)
oracleguy
11-08-2007, 06:29 AM
However didn't find THAT useful but Tanks anyway ! ;-)
Well if you don't want to use the Win32 Native API (or whatever native API is for the OS you are using) then using a framework like wxWidgets (or qt) is really your only option.
If you don't want to use a framework perhaps you can elaborate on what part you are having confusion over.
Active X
11-08-2007, 11:15 AM
I wanna use WIN32 API , But I don't know HOW ! My problem is this !
As a matter of fact , I've refered to many resources , But none of them has completely explained what happens in the code and has not explained why am I writing those strage pieces of code !
Could someone tell me about that ?
Bookworm9405
11-08-2007, 02:11 PM
Well, really, your only options for a GUI in C++ have already been mentioned - wxWidgets or the win32 API. Try here (http://www.functionx.com/win32/index.htm), for example, but there are loads of other tutorials on Google. Personally, I think Java or Visual Basic might be easier for a GUI, but you can do it in C++ if you realy want...
oracleguy
11-08-2007, 06:59 PM
If you aren't adverse to technical books, this is a good one that teaches the Win32 API: http://www.amazon.com/Programming-Windows-Fifth-Charles-Petzold/dp/157231995X/ref=sr_1_1/103-9642284-7671020?ie=UTF8&s=books&qid=1194544710&sr=1-1
It is a big book and covers a lot of material.
Active X
11-18-2007, 11:11 AM
Hi to all again ,
I found a complete resource for windows programming in C++ .
I've written this program :
#include<windows.h>
LRESULT CALLBACK WinProc(HWND hwnd, UINT Msg, WPARAM wParam,
LPARAM lParam)
{
switch (Msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
break;
}
return DefWindowProc(hwnd, Msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst,
LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASSEX myWin;
MSG msgObj;
myWin.cbClsExtra = 0;
myWin.cbSize = sizeof(myWin);
myWin.cbWndExtra = 0;
myWin.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
myWin.hCursor = LoadCursor(hThisInst, IDC_ARROW);
myWin.hIcon = LoadIcon(hThisInst, IDI_APPLICATION);
myWin.hIconSm = NULL;
myWin.hInstance = hThisInst;
myWin.lpfnWndProc = WinProc;
myWin.lpszClassName = (LPCWSTR)"winClass";
myWin.lpszMenuName = NULL;
myWin.style = CS_VREDRAW | CS_HREDRAW;
RegisterClassEx(&myWin);
CreateWindowEx(NULL, (LPCWSTR)"winClass", (LPCWSTR)"Windows App", NULL, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,NULL, NULL, hThisInst,
NULL);
while (GetMessage(&msgObj, NULL, 0, 0))
{
TranslateMessage(&msgObj);
DispatchMessage(&msgObj);
}
return (int)msgObj.wParam;
}
and I've got this error :
In Visual studio 2005 .net -> Visual C++ :
Error 1 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup MSVCRTD.lib
In Borland C++ builder X , I can compile the program , but I can't see my window !
Will be really thakful to your helps !
Aradon
11-18-2007, 05:01 PM
I know that when I get that error in visual studio it is typically complaining that I don't have a main function (int main(void) { } ) but I'm unsure how exactly the WinAPI works in conjunction with the standard main, as I am learning C++ as we speak :X
Active X
11-18-2007, 07:04 PM
Thank you for your post Aradon ,
I corrected it myself . The problem was here that I had defined a WIN32 Console project .
After that , I got a problem with LPCWSTR but I corrected it by changing project character set to Not set .
But now , I've got another problem .
I've made a Menu.rc and compiled it to Menu.res . I set the lpszMenuName property of my window object to "IDR_MENU1" .
I don't get an error , But menu doesn't appear !
Could you help me please ?
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.