PDA

Click to See Complete Forum and Search --> : Geeze, you serious. That's illegal???


Technocrat
Feb 26th, 2001, 10:26 AM
For which compiler? MSVC, Borland, Other?

By start do you mean I am a newbie and I dont know what to do with C++?

Vlatko
Feb 26th, 2001, 11:43 AM
Just To Start An App:

1. open visual c++
2. File > New
3. Click Projects tab
4. click Win32 Application and give it a name
5. click finish
6. click the File View Tab on TreeView
7. go to File > New
8. in the first tab Click C++ Source File and name it
9. Copy and paste the code in the new file
10. right click the Header folder and add Windows.h
11. click execute

#include <windows.h>
LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);
char szWinNamw[] = "MyWin";
int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst,
LPSTR kposzArgs, int nWinMode)


{
HWND hwnd;
MSG msg;
WNDCLASSEX wcl;
wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hInstance = hThisInst;
wcl.lpszClassName = "My Window";
wcl.lpfnWndProc = WindowFunc;
wcl.style = 0;
wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcl.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
wcl.hCursor = LoadCursor(NULL, IDC_ARROW);
wcl.lpszMenuName = NULL;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;
wcl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
if(!RegisterClassEx(&wcl)) return 0;
hwnd = CreateWindow(
"My Window",
"Skeleton Window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
HWND_DESKTOP,
NULL,
hThisInst,
NULL
);
ShowWindow(hwnd, nWinMode);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0))


{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)


{


switch(message) {
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}

parksie
Feb 26th, 2001, 12:09 PM
That's for Windows, if you didn't know. If you're really new to C++, this may help (use Win32 Console Application instead):

#include <iostream.h>

int main() {
cout << "Hello World!" << endl;
return 0;
}

Feb 26th, 2001, 01:22 PM
Ok, one, there are hundreds of other threads centered on this topic. Please look for them instead of posting the same question (this thread proves we need a FAQ). Two, please do not post subject titles that are not related to the question (unless its in the chit chat forum, anything goes in there, well not anything, well you know what i mean).

parksie
Feb 26th, 2001, 01:25 PM
anything goes in there, well not anything, well you know what i meanHmmm... :D

Wak
Feb 27th, 2001, 12:15 AM
Thanx for all the help, I am trying to get used to C++ without MFC.

Would anyone be able to post any info, website links, code, apps. Anything to do with C++ without using MFC, for Windows.

Thanks

Wak
Feb 27th, 2001, 12:45 AM
I have this code

#include <windows.h>
LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);
char szWinNamw[] = "MyWin";

int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst,
LPSTR kposzArgs, int nWinMode)
{
HWND hwnd;
HWND hwndStatic;
HWND hwndButton;
MSG msg;
WNDCLASSEX wcl;
wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hInstance = hThisInst;
wcl.lpszClassName = "My Window";
wcl.lpfnWndProc = WindowFunc;
wcl.style = 0;
wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcl.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
wcl.hCursor = LoadCursor(NULL, IDC_ARROW);
wcl.lpszMenuName = NULL;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;
wcl.hbrBackground = (HBRUSH) GetStockObject(GRAY_BRUSH);
if(!RegisterClassEx(&wcl)) return 0;
hwnd = CreateWindow(
"My Window",
"Blank Form",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
300,
CW_USEDEFAULT,
HWND_DESKTOP,
NULL,
hThisInst,
NULL
);
hwndStatic = CreateWindow(
"Static",
"Title Label",
WS_CHILD,
100,
50,
100,
20,
hwnd,
NULL,
hThisInst,
NULL
);
hwndButton = CreateWindow(
"Button",
"Press Me",
WS_CHILD,
100,
100,
100,
50,
hwnd,
NULL,
hThisInst,
NULL
);
ShowWindow(hwnd, nWinMode);
ShowWindow(hwndStatic, SW_SHOWNORMAL);
ShowWindow(hwndButton, SW_NORMAL);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0))


{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch(message) {
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}

}


This is a variation of Vlakto's, how can I receive a message for my own button?

HarryW
Feb 27th, 2001, 01:14 AM
Use code tags!

Wak
Feb 27th, 2001, 01:21 AM
I'm not to sure, but if you mean labeling, then I'm sorry about the mess, if you don't then please explain.

HarryW
Feb 27th, 2001, 01:40 AM
use tags so it looks like this:

#include <windows.h>
LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);
char szWinNamw[] = "MyWin";

int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst,
LPSTR kposzArgs, int nWinMode)
{
HWND hwnd;
HWND hwndStatic;
HWND hwndButton;
MSG msg;
WNDCLASSEX wcl;
wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hInstance = hThisInst;
wcl.lpszClassName = "My Window";
wcl.lpfnWndProc = WindowFunc;
wcl.style = 0;
wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcl.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
wcl.hCursor = LoadCursor(NULL, IDC_ARROW);
wcl.lpszMenuName = NULL;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;
wcl.hbrBackground = (HBRUSH) GetStockObject(GRAY_BRUSH);
if(!RegisterClassEx(&wcl)) return 0;
hwnd = CreateWindow(
"My Window",
"Blank Form",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
300,
CW_USEDEFAULT,
HWND_DESKTOP,
NULL,
hThisInst,
NULL
);
hwndStatic = CreateWindow(
"Static",
"Title Label",
WS_CHILD,
100,
50,
100,
20,
hwnd,
NULL,
hThisInst,
NULL
);
hwndButton = CreateWindow(
"Button",
"Press Me",
WS_CHILD,
100,
100,
100,
50,
hwnd,
NULL,
hThisInst,
NULL
);
ShowWindow(hwnd, nWinMode);
ShowWindow(hwndStatic, SW_SHOWNORMAL);
ShowWindow(hwndButton, SW_NORMAL);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0))


{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch(message) {
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}

}

In case you're wondering I didn't go through all that indenting it, I just pasted it into VC++, highlighted it and pressed Alt-F8.

Wak
Feb 27th, 2001, 03:58 AM
I'm not being rude or anything, but. I pretty much new that, and also. I NEED HELP. I've gotten a bit further. I have this now.

Notice the pretty code tags:

#include <windows.h>
LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);
char szWinNamw[] = "MyWin";

int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst,
LPSTR kposzArgs, int nWinMode)
{
HWND hwnd;
HWND hwndStatic;
HWND hwndButton;
MSG msg;
WNDCLASSEX wcl;
wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hInstance = hThisInst;
wcl.lpszClassName = "My Window";
wcl.lpfnWndProc = WindowFunc;
wcl.style = 0;
wcl.hIcon = LoadIcon(NULL, "sire.ico");
wcl.hIconSm = LoadIcon(NULL, "sire.ico");
wcl.hCursor = LoadCursor(NULL, IDC_ARROW);
wcl.lpszMenuName = NULL;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;
wcl.hbrBackground = (HBRUSH) GetStockObject(GRAY_BRUSH);
if(!RegisterClassEx(&wcl)) return 0;
hwnd = CreateWindow(
"My Window",
"Blank Form",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
300,
CW_USEDEFAULT,
HWND_DESKTOP,
NULL,
hThisInst,
NULL
);
hwndStatic = CreateWindow(
"Static",
"Title Label",
WS_CHILD,
100,
50,
100,
20,
hwnd,
NULL,
hThisInst,
NULL
);
hwndButton = CreateWindow(
"Button",
"Press Me",
WS_CHILD,
100,
100,
100,
50,
hwnd,
NULL,
hThisInst,
NULL
);
ShowWindow(hwnd, nWinMode);
ShowWindow(hwndStatic, SW_SHOWNORMAL);
ShowWindow(hwndButton, SW_NORMAL);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0))


{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch(message) {
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd, "Button Pressed", "Press", MB_OK);
break;
case WM_COMMAND:
HWND hwndButton;
int idButton;

hwndButton = (HWND) lParam;
idButton = (int) LOWORD(wParam);

if (idButton = BN_CLICKED){
MessageBox( hwnd, "Button Clicked", "Pressed", MB_OK); }
else if (idButton = BN_DOUBLECLICKED){
MessageBox( hwnd, "Double Clicked", "Pressed", MB_OK); }
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
}


How do I change the background to look normal???
How use the icon properly. It's called sire.ico
What else can I do, to make it look more normal??

HarryW
Feb 27th, 2001, 04:25 AM
If you knew how to use code tags before, why didn't you use them? That's all I said.


Anyway what's 'normal'? Do you mean like VB's forms? If you want to make the background a certain colour or pattern then you can use GDI graphics to do it... I think you might just have to select in a new brush into the DC for the inside of the windows, I'm not sure.

I'm not sure you can load an icon like that, I think you need to put it in a resource file, give it an identifier and compile it into your exe.

parksie
Feb 27th, 2001, 05:22 AM
Normally you'd put the icon into a resource but you can load it from disk. The LoadImage function supports both.

Feb 27th, 2001, 03:15 PM
Personally, I perfer to only use Showwindow on the Main window. The rest of the child windows are shown via the WS_VISIBLE style.

Wak
Feb 28th, 2001, 04:26 AM
Megatron: I'm not to sure what you mean, how can I not, use ShowWindow, and get the window to show. By this I mean a button or something.

Parksie: Your help also great, actually it wasn't great at all, now I think of it. It was perfect. Thanx!!

HarryW: Umm, for you question, I wasn't too sure on actuall Scripting tags, but now I know. Also, I found a way to display the normal colour.


wcl.hbrBackground = (HBRUSH) COLOR_APPWORKSPACE;


But thanks anyway.

Keep posting more if you want. Anybody, if it even remotley relates to Win32 C++, then just post it. It'll get your posts up :):)

Thanxs again.

parksie
Feb 28th, 2001, 01:41 PM
In order for a window to be automatically visible, you need to specify the WS_VISIBLE style. If you don't then it will be hidden and require ShowWindow.