|
-
Feb 26th, 2001, 11:26 AM
#1
Thread Starter
Frenzied Member
For which compiler? MSVC, Borland, Other?
By start do you mean I am a newbie and I dont know what to do with C++?
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Feb 26th, 2001, 12:43 PM
#2
Frenzied Member
Just To Start An App:
Code:
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;
}
-
Feb 26th, 2001, 01:09 PM
#3
Monday Morning Lunatic
That's for Windows, if you didn't know. If you're really new to C++, this may help (use Win32 Console Application instead):
Code:
#include <iostream.h>
int main() {
cout << "Hello World!" << endl;
return 0;
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 26th, 2001, 02:22 PM
#4
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).
-
Feb 26th, 2001, 02:25 PM
#5
Monday Morning Lunatic
anything goes in there, well not anything, well you know what i mean
Hmmm...
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 27th, 2001, 01:15 AM
#6
Hyperactive Member
Thanx for the help
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
Visual Basic 6.0 Enterprise
Visual C++ 6.0 Professional
Wak 
-
Feb 27th, 2001, 01:45 AM
#7
Hyperactive Member
I got another one for you all.
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?
Visual Basic 6.0 Enterprise
Visual C++ 6.0 Professional
Wak 
-
Feb 27th, 2001, 02:14 AM
#8
Frenzied Member
Harry.
"From one thing, know ten thousand things."
-
Feb 27th, 2001, 02:21 AM
#9
Hyperactive Member
Umm, what do you mean by tags??
I'm not to sure, but if you mean labeling, then I'm sorry about the mess, if you don't then please explain.
Visual Basic 6.0 Enterprise
Visual C++ 6.0 Professional
Wak 
-
Feb 27th, 2001, 02:40 AM
#10
Frenzied Member
use [code][/code] tags so it looks like 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);
}
}
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.
Harry.
"From one thing, know ten thousand things."
-
Feb 27th, 2001, 04:58 AM
#11
Hyperactive Member
Thanx for the help
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:
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, "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??
Visual Basic 6.0 Enterprise
Visual C++ 6.0 Professional
Wak 
-
Feb 27th, 2001, 05:25 AM
#12
Frenzied Member
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.
Harry.
"From one thing, know ten thousand things."
-
Feb 27th, 2001, 06:22 AM
#13
Monday Morning Lunatic
Normally you'd put the icon into a resource but you can load it from disk. The LoadImage function supports both.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 27th, 2001, 04:15 PM
#14
Personally, I perfer to only use Showwindow on the Main window. The rest of the child windows are shown via the WS_VISIBLE style.
-
Feb 28th, 2001, 05:26 AM
#15
Hyperactive Member
Thanx for all the Advice
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.
Code:
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.
Visual Basic 6.0 Enterprise
Visual C++ 6.0 Professional
Wak 
-
Feb 28th, 2001, 02:41 PM
#16
Monday Morning Lunatic
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.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|