PDA

Click to See Complete Forum and Search --> : Strings in C


Wynd
Aug 5th, 2001, 09:35 AM
I am trying to make my .exe file as small as possible and someone suggested using C instead of C++. In one part of my program I need to get input from the keyboard and use it in a Windows API function (FindWindow()). How acn I accomplish the same thing in C? I attached what I have so far.

Megatron
Aug 5th, 2001, 11:01 AM
Use printf() and scanf().

#include <windows.h>
#include <stdio.h>

int main()
{
LPSTR sName;

printf("Type in the name of the window you wish to show or hide:");
scanf("%s", sName);

HWND h = FindWindow(NULL, sName);
if (h == NULL)
MessageBox(NULL, "Could not find window", "Error", MB_OK | MB_ICONERROR);
else
{
if(!IsWindowVisible(h))
ShowWindow(h, 1);
else
ShowWindow(h, 0);
}
return 0;
}

Wynd
Aug 5th, 2001, 11:35 AM
If I use that the program crashes after I enter the window name.

parksie
Aug 6th, 2001, 06:06 AM
LPSTR sName;char sName[254];:)

Wynd
Aug 6th, 2001, 09:41 AM
That doesn't work either, it says "Could not find window" if there are more than one word...