Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 14th, 2006, 5:41 PM   #1
Prm753
Professional Programmer
 
Prm753's Avatar
 
Join Date: Oct 2005
Location: United States
Posts: 447
Rep Power: 4 Prm753 is on a distinguished road
Send a message via AIM to Prm753 Send a message via MSN to Prm753
Trouble with SendMessage();

So, I got re-interested in programming again, and I decided to pick back up development of SecureOverwrite. I am having trouble with SendMessage(). Here's what I want to do:

- Have a browse button that calls a browse function
- Get file name selected in browse window and send it to my editbox
- SecureOverwrite said file.

The first and third things on the list I can do, and have done. (Well, my algorithm is just overwriting the file with 0's, one for every byte of the file... I'll work on that later) It's the second that is giving me trouble. When the function gets the file that I have selected in the browse window, it's supposed to send it along to the editbox; I can then overwrite it. Problem is, somewhere along the way the message (filename string) gets "lost". Nothing gets written to the editbox. I would be most grateful if I could be given some hints as to how I might fix this problem. I have attached the code in a .zip file.

If you need me to elaborate more on my problem, say so, and I will be glad to.

Thank you.
Attached Files
File Type: zip code.zip (2.7 KB, 33 views)
__________________
The world's first athletic computer geek!
The home of PrProgramsStudios
How not to post a question: <-- Please don't reply
Prm753 is offline   Reply With Quote
Old Dec 15th, 2006, 4:20 AM   #2
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5 grumpy is on a distinguished road
Consider this an early Christmas present (Bah, humbug!); I don't normally look at attachments in this forum, as they indicate that the person asking the question hasn't put in the effort to find a small example that illustrates the problem.

The most obvious offending code (I stopped at this point, so there may be more) is this;
     Buffer[MAX_PATH] = szFileName[MAX_PATH];
	// return Buffer[MAX_PATH];
	SendMessage(GetDlgItem(hwnd, IDC_EDITBOX_TEXT), LB_ADDSTRING, 0, (LPARAM)Buffer[MAX_PATH]);
Buffer and szFileName have been declared previously as arrays of char. So, in this code Buffer[MAX_PATH] is a single character, as is szFileName[MAX_PATH]. So, you effectively assign one character to the value of another, and then pass that single character value as an argument to SendMessage() -- IOW, you're not passing a string. The fact that both Buffer and szFileName are both char arrays of of length MAX_PATH (and indices will therefore run from 0 to MAX_PATH-1) doesn't particularly help you either.

If you want to copy C-style strings around, use the strcpy() function, not simple assignment.
grumpy is offline   Reply With Quote
Old Dec 15th, 2006, 2:50 PM   #3
Prm753
Professional Programmer
 
Prm753's Avatar
 
Join Date: Oct 2005
Location: United States
Posts: 447
Rep Power: 4 Prm753 is on a distinguished road
Send a message via AIM to Prm753 Send a message via MSN to Prm753
Thank you very much, grumpy.

I have this code now:

cpp Syntax (Toggle Plain Text)
  1. if(GetOpenFileName(&ofn))
  2. {
  3. strcpy(Buffer, szFileName);
  4. return Buffer[MAX_PATH];
  5. // MessageBox(0, Buffer, 0, 0);
  6. // SendMessage(GetDlgItem(hwnd, IDC_EDITBOX_TEXT), LB_ADDSTRING, 0, (LPARAM)"test");
  7. }

cpp Syntax (Toggle Plain Text)
  1. case IDB_BROWSEBUTTON:
  2. {
  3. switch (HIWORD(wParam))
  4. {
  5. case BN_CLICKED:
  6. {
  7. Buffer[MAX_PATH] = DoFileOpen(hWnd);
  8. SendMessage(GetDlgItem(hWnd, IDC_EDITBOX_TEXT), LB_ADDSTRING, 0, (LPARAM)Buffer);
  9. // MessageBox(0, Buffer, 0, 0);
  10. }
  11. break;
  12. }
  13. break;
  14. }
  15. break;

The MessageBox() in the second code example displays the path that I select in my browse function. If I change IDC_EDITBOX_TEXT to IDC_LISTBOX_TEXT, the message is received just fine. It displays the path in the listbox. This is fine, this is wonderful, this is dandy, but this is not what I want. I want to put the string into my editbox, and for some reason, SendMessage() fails on doing this. (I think)

Here is my editbox code:

cpp Syntax (Toggle Plain Text)
  1. hWndEditBox = CreateWindow(
  2. "EDIT",
  3. "<type a file name here>",
  4. WS_VISIBLE | WS_CHILD | WS_BORDER,
  5. 10,
  6. 10,
  7. 700,
  8. 30,
  9. hWnd,
  10. (HMENU)IDC_EDITBOX_TEXT,
  11. (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),
  12. NULL);
  13.  
  14. HFONT AhFont = (HFONT)GetStockObject( DEFAULT_GUI_FONT );
  15. SendMessage( hWndEditBox, WM_SETFONT, (WPARAM)AhFont, TRUE );

What am I doing wrong here?

Thanks again.
__________________
The world's first athletic computer geek!
The home of PrProgramsStudios
How not to post a question: <-- Please don't reply
Prm753 is offline   Reply With Quote
Old Dec 15th, 2006, 3:06 PM   #4
Prm753
Professional Programmer
 
Prm753's Avatar
 
Join Date: Oct 2005
Location: United States
Posts: 447
Rep Power: 4 Prm753 is on a distinguished road
Send a message via AIM to Prm753 Send a message via MSN to Prm753
I figured out what I was doing wrong! I was using ListBox flags in SendMessage, and I should have been using EditBox flags.
__________________
The world's first athletic computer geek!
The home of PrProgramsStudios
How not to post a question: <-- Please don't reply
Prm753 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[C++] Any criticism? ivan Show Off Your Open Source Projects 10 Jun 13th, 2006 12:58 PM
questions on windows sendMessage and RichEdit control nomer C++ 1 Mar 3rd, 2006 2:51 AM
Could this get me in trouble? (Reg. Internet Copyright Laws) Sane Coder's Corner Lounge 14 Jan 26th, 2006 6:14 PM
My first WIN32 API application ivan Show Off Your Open Source Projects 27 Jan 6th, 2006 5:04 PM
ftell() giving me trouble. 2roll4life7 C 5 Sep 2nd, 2005 12:27 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:00 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC