Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (Kingware, AndrewAMD, AemStones, RealSerious3D, degenerate_762), 837 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
(Win32) "Save" without using a "Save As" window #184162
02/16/08 00:26
02/16/08 00:26
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
I'm trying to implement a "Save" capability that uses the existing filename (I already have an OPENFILENAME "Save As"). I'm using the window titlebar to display the file name when a file is opened or saved. The trouble is, when I attempt to use this name in my SaveTextFromEdit(); function using GetWindowText();, when I click "Save" in the menu, my program crashes ("acknex.exe has encountered a problem and needs to close.").

Here's the Code:

My save function:

BOOL SaveTextFromEdit(HWND hEdit, LPCSTR pszFileName)
{
HANDLE hFile;
BOOL bSuccess = FALSE;

hFile = CreateFile(pszFileName, GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile != INVALID_HANDLE_VALUE)
{
DWORD dwTextLength;

dwTextLength = GetWindowTextLength(hEdit);
// No need to bother if there's no text.
if(dwTextLength > 0)
{
LPSTR pszText;
DWORD dwBufferSize = dwTextLength + 1;

pszText = GlobalAlloc(GPTR, dwBufferSize);
if(pszText != NULL)
{
if(GetWindowText(hEdit, pszText, dwBufferSize))
{
DWORD dwWritten;

if(WriteFile(hFile, pszText, dwTextLength, &dwWritten, NULL))
bSuccess = TRUE;
}
GlobalFree(pszText);
}
}
CloseHandle(hFile);
}
return bSuccess;
}

My WndProc:

LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
PAINTSTRUCT paint;
HDC hdc;
switch(msg)
{
case WM_CREATE:
{
HWND hedit= CreateWindowEx(WS_EX_STATICEDGE,"EDIT",EditContent,
WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
0,0,100,100,hwnd,(HMENU)IDC_MAIN_EDIT,GetModuleHandle(NULL),NULL); //creating the edit window
//creating menus:
long menu= CreateMenu();
long SubMenu= CreateMenu();

InsertMenu(menu,0,MF_BYPOSITION | MF_STRING | MF_POPUP,SubMenu,"&File");
//"File" menu items:
InsertMenu(SubMenu,0,MF_BYPOSITION | MF_STRING,ID_FILE_NEW,"&New");
InsertMenu(SubMenu,1,MF_BYPOSITION | MF_STRING,ID_FILE_OPEN,"&Open...");
InsertMenu(SubMenu,2,MF_BYPOSITION | MF_STRING,ID_FILE_SAVE,"Save &As...");
InsertMenu(SubMenu,3,MF_BYPOSITION | MF_STRING,ID_FILE_SAVE_WITH_CURRENT_NAME,"&Save");
InsertMenu(SubMenu,4,MF_BYPOSITION | MF_SEPARATOR,NULL,NULL);
InsertMenu(SubMenu,5,menuSettings,ID_FILE_OPEN_CURRENT_TEXT,"Open &Current Text on start");
InsertMenu(SubMenu,6,MF_BYPOSITION | MF_STRING,NULL,"Open F&ile on start...");
InsertMenu(SubMenu,7,MF_BYPOSITION | MF_SEPARATOR,NULL,NULL);
InsertMenu(SubMenu,8,MF_BYPOSITION | MF_STRING,ID_FILE_EXIT,"&Quit");
SetMenu(hwnd,menu);
}
break;
case WM_SIZE:
{
HWND hedit= GetDlgItem(hwnd,IDC_MAIN_EDIT);
RECT ClientRect;

GetClientRect(hwnd,&ClientRect);

SetWindowPos(hedit,NULL,0,0,ClientRect.right,ClientRect.bottom,SWP_NOZORDER);
}
break;
case WM_PAINT:
hdc= BeginPaint(hwnd,&paint);
EndPaint(hwnd,&paint);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_COMMAND:
switch(wparam)
{
case ID_FILE_NEW:
SetDlgItemText(hwnd,IDC_MAIN_EDIT,"");
SetWindowText(hwnd,WindowTitle);
case ID_FILE_OPEN:
Open(hwnd);
break;
case ID_FILE_SAVE:
Save(hwnd);
break;
case ID_FILE_OPEN_CURRENT_TEXT:
Toggle^= TRUE;
if(Toggle== FALSE)
menuSettings= MF_BYPOSITION | MF_STRING | MF_UNCHECKED;
else
menuSettings= MF_BYPOSITION | MF_STRING | MF_CHECKED;
break;
case ID_FILE_SAVE_WITH_CURRENT_NAME:
SaveTextFromEdit(hwnd,GetWindowText(hwnd,FileName,256));
break;

case ID_FILE_EXIT:
PostQuitMessage(0);
break;
}
default:
break;
}
return DefWindowProc(hwnd,msg,wparam,lparam);
}



The red part is the part I'm having issues with. I posted the whole WndProc code because it may have something to do with a conflict elsewhere in my message handling.

(FYI, FileName is a global char that I also use with my OPENFILENAME Open(); and Save(); functions enabling me to use the file name for the title bar text.)


Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: (Win32) "Save" without using a "Save As" windo [Re: MrCode] #184163
02/20/08 19:32
02/20/08 19:32
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
ne1?


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1