Question On SendMessage

Started by
5 comments, last by Gorf_Rules 20 years, 5 months ago
SendMessage(hList, LB_ADDSTRING|LB_INSERTSTRING, 0, dLetters + ":"); How do I get my array and : to output into the ListBox? Also thanks to everyone for the help on these forums.
Advertisement
I'll assume dLetters is a char array...

char cString[255];for (index = 0; index < (the number of elements in your array), index++){    sprintf(cString, "%c:", dLetters[index]);    SendMessage(hList, LB_ADDSTRING, 255, (LPARAM)(LPCSTR)cString);}   


[edited by - Programmer One on November 18, 2003 12:07:52 PM]
Humm now its come down to a logic issue.
case  ID_DRIVE_GETDRIVEINFORMATION:for(int index= 0; index < 26; index++){    drive = GetLogicalDrives();    if(drive&(1<<(index)))    {	strncpy(cString, &dLetters[index],1);	driveT = GetDriveType(cString);	switch(driveT)		{		   case DRIVE_UNKNOWN:		   driveT2 = "UNKNOWN";		   break;		   case DRIVE_NO_ROOT_DIR:		   driveT2 = "NOROOTDIR";		   break;		   case DRIVE_REMOVABLE:		   driveT2 = "REMOVABLE";		   break;		   case DRIVE_FIXED:		   driveT2 = "FIXED";		   break;		   case DRIVE_REMOTE:		   driveT2 = "REMOTE";		   break;		   case DRIVE_CDROM:		   driveT2 = "CDROM";		   break;		   case DRIVE_RAMDISK:		   driveT2 = "RAMDISK";		   break;		   default:		   break;                   }   strcat(cString,"  ");   strcat(cString,driveT2);  SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)cString);    }}break;

that is the case

here is my header:


HWND hList;
DWORD drive;
LPCTSTR driveT2;
UINT driveT;
char cString[3];
char dLetters[]={''A'',''B'',''C'',''D'',''E'',''F'',''G'',''H'',''I'',''J'',''K'',''L'',''M'',''N'',''O'',''P'',''Q'',''R'',''S'',''T'',''U'',''V'',''W'',''X'',''Y'',''Z''};
Oops I thought I posted this. The Problem is its outputting the first drive C and its outputting the type but its outputting the wrong type and then its not getting d for some odd reason though initially it knows d is there also as the DWORD is 12 meaning 1100.
I think the problem is that cString isn''t being cleared, how could I clear a char[3]? Its probably something simple, well I know it is but I can''t seem to get it to accept anything.
An immediate problem is that strncpy does not place a terminating null in your string so you will find that strcat just keep appending text to the end of your buffer.

If you want to clear the whole thing you can use memset. Otherwise just add this line after the strncpy:

cString[1] = 0;


"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
thanks a mil that fixed it

This topic is closed to new replies.

Advertisement