Be a Supporter!

C++, Ahhh This Anoying...

  • 517 Views
  • 13 Replies
New Topic Respond to this Topic
blah569
blah569
  • Member since: Jan. 18, 2005
  • Offline.
Forum Stats
Member
Level 25
Programmer
C++, Ahhh This Anoying... 2005-10-15 09:53:13 Reply

Ok, alot of the times I try out my program, I get errors, when I know theres NOTHING wrong. I even tryed one of there premade things, and its wrong =O. Here, whats wrong with this code?:

#include <windows.h>

static char g_szClassName[] = "MyWindowClass";
static HINSTANCE g_hInst = NULL;

#define IDC_MAIN_TEXT 1001

BOOL LoadFile(HWND hEdit, LPSTR pszFileName)
{
HANDLE hFile;
BOOL bSuccess = FALSE;

hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, 0, 0);
if(hFile != INVALID_HANDLE_VALUE)
{
DWORD dwFileSize;
dwFileSize = GetFileSize(hFile, NULL);
if(dwFileSize != 0xFFFFFFFF)
{
LPSTR pszFileText;
pszFileText = (LPSTR)GlobalAlloc(GPTR, dwFileSize + 1);
if(pszFileText != NULL)
{
DWORD dwRead;
if(ReadFile(hFile, pszFileText, dwFileSize, &dwRead, NULL))
{
pszFileText[dwFileSize] = 0; // Null terminator
if(SetWindowText(hEdit, pszFileText))
bSuccess = TRUE; // It worked!
}
GlobalFree(pszFileText);
}
}
CloseHandle(hFile);
}
return bSuccess;
}

BOOL SaveFile(HWND hEdit, LPSTR pszFileName)
{
HANDLE hFile;
BOOL bSuccess = FALSE;

hFile = CreateFile(pszFileName, GENERIC_WRITE, 0, 0,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if(hFile != INVALID_HANDLE_VALUE)
{
DWORD dwTextLength;
dwTextLength = GetWindowTextLength(hEdit);
if(dwTextLength > 0)// No need to bother if there's no text.
{
LPSTR pszText;
pszText = (LPSTR)GlobalAlloc(GPTR, dwTextLength + 1);
if(pszText != NULL)
{
if(GetWindowText(hEdit, pszText, dwTextLength + 1))
{
DWORD dwWritten;
if(WriteFile(hFile, pszText, dwTextLength, &dwWritten, NULL))
bSuccess = TRUE;
}
GlobalFree(pszText);
}
}
CloseHandle(hFile);
}
return bSuccess;
}

BOOL DoFileOpenSave(HWND hwnd, BOOL bSave)
{
OPENFILENAME ofn;
char szFileName[MAX_PATH];

ZeroMemory(&ofn, sizeof(ofn));
szFileName[0] = 0;

ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = "Html Files (*.html)\0*.txt\0All Files (*.*)\0*.*\0\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrDefExt = "txt";

if(bSave)
{
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY |
OFN_OVERWRITEPROMPT;

if(GetSaveFileName(&ofn))
{
if(!SaveFile(GetDlgItem(hwnd, IDC_MAIN_TEXT), szFileName))
{
MessageBox(hwnd, "Save file failed.", "Error",
MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
}
}
else
{
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
if(GetOpenFileName(&ofn))
{
if(!LoadFile(GetDlgItem(hwnd, IDC_MAIN_TEXT), szFileName))
{
MessageBox(hwnd, "Load of file failed.", "Error",
MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
}
}
return TRUE;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_CREATE:
CreateWindow("EDIT", "",
WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE |
ES_WANTRETURN,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
hwnd, (HMENU)IDC_MAIN_TEXT, g_hInst, NULL);

SendDlgItemMessage(hwnd, IDC_MAIN_TEXT, WM_SETFONT,
(WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0));
break;
case WM_SIZE:
if(wParam != SIZE_MINIMIZED)
MoveWindow(GetDlgItem(hwnd, IDC_MAIN_TEXT), 0, 0, LOWORD(lParam),
HIWORD(lParam), TRUE);
break;
case WM_SETFOCUS:
SetFocus(GetDlgItem(hwnd, IDC_MAIN_TEXT));
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case CM_FILE_OPEN:
DoFileOpenSave(hwnd, FALSE);
break;
case CM_FILE_SAVEAS:
DoFileOpenSave(hwnd, TRUE);
break;
case CM_FILE_EXIT:
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
case CM_ABOUT:
MessageBox (NULL, "To save as a txt file open the all file pannel and add .txt at the end" , "Help", 0);
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX WndClass;
HWND hwnd;
MSG Msg;

g_hInst = hInstance;

WndClass.cbSize = sizeof(WNDCLASSEX);
WndClass.style = 0;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = g_hInst;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
WndClass.lpszMenuName = "MAINMENU";
WndClass.lpszClassName = g_szClassName;
WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

if(!RegisterClassEx(&WndClass))
{
MessageBox(0, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
return 0;
}

hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"HTML editor",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 320, 240,
NULL, NULL, g_hInst, NULL);

if(hwnd == NULL)
{
MessageBox(0, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
return 0;
}

ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);

while(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}

Whats wrong with that? Please help :)


BBS Signature
Pilot-Doofy
Pilot-Doofy
  • Member since: Sep. 13, 2003
  • Offline.
Forum Stats
Member
Level 37
Musician
Response to C++, Ahhh This Anoying... 2005-10-15 10:10:03 Reply

Could you at least tell us where your compiler is telling you there's a mistake?

blah569
blah569
  • Member since: Jan. 18, 2005
  • Offline.
Forum Stats
Member
Level 25
Programmer
Response to C++, Ahhh This Anoying... 2005-10-15 10:30:10 Reply

OK, here is the mistake:

case CM_FILE_OPEN:

What is wrong with that?


BBS Signature
PONGpaddle
PONGpaddle
  • Member since: Sep. 23, 2003
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to C++, Ahhh This Anoying... 2005-10-15 10:39:30 Reply

http://search.micros..&qu=CM_FILE_OPEN

Unless it's undocumented, it doesn't look like CM_FILE_OPEN exists.

thoughtpolice
thoughtpolice
  • Member since: Mar. 24, 2003
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to C++, Ahhh This Anoying... 2005-10-15 13:27:25 Reply

Oi. It's fairly obvious you know nothing about the code you're using or even understand ANY of it. Otherwise you should have been able to figure this out fairly easily.

It's pretty obvious that the CM_* family of Window messages are part of a menu that is contained somewhere in a resource file. You don't have the resource file, you don't have the header file to accompany it, and therefore all your user-defined Window messages aren't defined. This requires a menu and a resource file which you don't have.

I suggest you stay away from Windows programming for a while, since you obviously don't know anything about it and you're probably just learning it because console shit feels boring.

At 10/15/05 09:53 AM, blah569 wrote: Ok, alot of the times I try out my program, I get errors, when I know theres NOTHING wrong.

That's probably the biggest egotistical load of shit I've ever heard in my life. The general rule of thumb is this:

It's your fault. Not the compilers.


omg.
Playstation Network tag: muffin-noodle
the empty set

Jessii
Jessii
  • Member since: Feb. 10, 2005
  • Offline.
Forum Stats
Member
Level 36
Movie Buff
Response to C++, Ahhh This Anoying... 2005-10-15 15:34:13 Reply

At 10/15/05 01:27 PM, SrgntJack wrote: It's your fault. Not the compilers.

I'm not even gonna comment, just look at his html posts

looks the other way
Jcrypt
Jcrypt
  • Member since: Aug. 23, 2005
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to C++, Ahhh This Anoying... 2005-10-16 09:54:59 Reply

Yes as said before... CM_FILE_OPEN isn't even defined.. you obviously copy/pasted from someones source somewhere and 2nd that's not even really C++ persay I mean yes it's scripted in it but it's Win32 ( not a big diff but i'm a techinical whore ) So go look up Win32 Programming and please never post someone elses code claiming it again.. k?

Coconutsock
Coconutsock
  • Member since: Sep. 24, 2005
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to C++, Ahhh This Anoying... 2005-10-16 11:33:59 Reply

(Key.isDown(Key.UP)) { _y -= 10; _rotation = 270; }}onClipEvent (enterFrame) { if (Key.isDown(Key.DOWN)) { _y -= -10; _rotation = 90; }}onClipEvent (enterFrame) { if (Key.isDown(Key.LEFT)) { _x -= 10; _rotation = 180; }}onClipEvent (enterFrame) { if (Key.isDown(Key.RIGHT)) { _x -= -10; _rotation = 0; }}

something is wrong can u help me plz?

Amish
Amish
  • Member since: Mar. 13, 2003
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to C++, Ahhh This Anoying... 2005-10-16 11:37:27 Reply

At 10/16/05 11:33 AM, Coconutsock wrote: (Key.isDown(Key.UP)) { _y -= 10; _rotation = 270; }}onClipEvent (enterFrame) { if (Key.isDown(Key.DOWN)) { _y -= -10; _rotation = 90; }}onClipEvent (enterFrame) { if (Key.isDown(Key.LEFT)) { _x -= 10; _rotation = 180; }}onClipEvent (enterFrame) { if (Key.isDown(Key.RIGHT)) { _x -= -10; _rotation = 0; }}

something is wrong can u help me plz?

Oh for fuck sake, their multiplying. Wrong forum mate. Dont ask why just get yourself into the flash forum.

Craige
Craige
  • Member since: Jul. 17, 2004
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to C++, Ahhh This Anoying... 2005-10-16 15:44:07 Reply

lol, and why did he post that in a C++ topic?

Scottc1988
Scottc1988
  • Member since: Jan. 27, 2003
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to C++, Ahhh This Anoying... 2005-10-17 20:06:27 Reply

At 10/16/05 09:54 AM, Cyrax88 wrote: Yes as said before... CM_FILE_OPEN isn't even defined.. you obviously copy/pasted from someones source somewhere and 2nd that's not even really C++ persay I mean yes it's scripted in it but it's Win32 ( not a big diff but i'm a techinical whore ) So go look up Win32 Programming and please never post someone elses code claiming it again.. k?

You would be doing the world an excellent favor by killing yourself. Please do so, or at least never ever post unless you know what you are talking about. This is C++, it is using the WINAPI. It is the same language, using a differant library than the standard IOSTREAM library which runs in a CMD or DOS window. No the IOSTREAM Library is NOT the entire C++ language.

Jcrypt
Jcrypt
  • Member since: Aug. 23, 2005
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to C++, Ahhh This Anoying... 2005-10-19 13:58:14 Reply

wow... how bout you shut the fuck up? IF you could read... I clearly said "It's not C++ persay" in other words it is but isn't... As you said yourself it's using the WINAPI so stfu and go sit worthless fuckin idiot..

thoughtpolice
thoughtpolice
  • Member since: Mar. 24, 2003
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to C++, Ahhh This Anoying... 2005-10-19 17:29:00 Reply

At 10/19/05 01:58 PM, Cyrax88 wrote: wow... how bout you shut the fuck up? IF you could read... I clearly said "It's not C++ persay" in other words it is but isn't... As you said yourself it's using the WINAPI so stfu and go sit worthless fuckin idiot..

Seeing how the general consensus is that you don't know much about this topic -- i.e. Win32 -- (seeing how your posts have basically summed up to ("don't try this until later" and "shut the fuck up"), plus the fact you haven't proven you're extremely smart judging on the ad hominem in your post and your grammar, I'd say that it'd be damn near impossible not to pick at you.


omg.
Playstation Network tag: muffin-noodle
the empty set

Ravens-Grin
Ravens-Grin
  • Member since: Jun. 3, 2003
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to C++, Ahhh This Anoying... 2005-10-22 00:24:52 Reply

At 10/19/05 01:58 PM, Cyrax88 wrote: As you said yourself it's using the WINAPI so stfu and go sit worthless fuckin idiot..

The WINAPI through assembly, C++, Delphi, J++? You honestly don't know what you are talking about, so please shut your trap.