Results 1 to 5 of 5

Thread: Strings in C

  1. #1

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772

    Strings in C

    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.
    Alcohol & calculus don't mix.
    Never drink & derive.

  2. #2
    Megatron
    Guest
    Use printf() and scanf().
    Code:
    #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;
    }

  3. #3

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    If I use that the program crashes after I enter the window name.
    Alcohol & calculus don't mix.
    Never drink & derive.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Code:
    LPSTR sName;
    Code:
    char sName[254];
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    That doesn't work either, it says "Could not find window" if there are more than one word...
    Alcohol & calculus don't mix.
    Never drink & derive.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width