Thread: How to place an icon in a window?

  1. #1
    Registered User marcelo.br's Avatar
    Join Date
    Nov 2018
    Posts
    45

    Question How to place an icon in a window?

    Please read my question!
    I need to put an icon in a Window, and I need this icon to be written inside the source!

    Example: my_icon = image data

    I don't want the icon to be pulled from Hard Disk. And not from the internet or any place you can imagine!
    my_icon = icon.png

    Can anyone tell me how I can do this?
    At the moment I use fltk to create the window, but I can't find it and I don't know how to assign the written icon data inside the source.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    So what does your code look like at the moment?

    FLTK 1.3.8: Fl_RGB_Image Class Reference
    FLTK 1.3.8: Fl_PNG_Image Class Reference
    These allow you to build an image object from data in memory.

    The PNG one would seem to be easy enough to try, since you already load "icon.png".
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User marcelo.br's Avatar
    Join Date
    Nov 2018
    Posts
    45
    Quote Originally Posted by Salem View Post
    So what does your code look like at the moment?

    FLTK 1.3.8: Fl_RGB_Image Class Reference
    FLTK 1.3.8: Fl_PNG_Image Class Reference
    These allow you to build an image object from data in memory.

    The PNG one would seem to be easy enough to try, since you already load "icon.png".
    As I stated in the question. I want the png written in the source. Not in memory, so there is no icon.png

    Example, below is an image written in source that I can save as a png if I want!

    Creating the image below is easy, but it's not the image I want!
    I want to have my image like the one I wrote in the source!

    Code:
       int my_icon[13][13] = {
       { 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15 },
       { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 },
       { 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47 },
       { 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63 },
       { 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79 },
       { 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95 },
       { 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111 },
       { 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127 },
       { 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143 },
       { 159, 159, 159, 159, 159, 159, 159, 159, 159, 159, 159, 159, 159 },
       { 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175 },
       { 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191 },
       { 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207 }};
    Image of my_icon above written in source

    How to place an icon in a window?-gfgpgm2-png

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Read the link!

    Fl_PNG_Image (const char *name_png, const unsigned char *buffer, int datasize)
    Constructor that reads a PNG image from memory. More...

    See?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User marcelo.br's Avatar
    Join Date
    Nov 2018
    Posts
    45
    Quote Originally Posted by Salem View Post
    Read the link!

    Fl_PNG_Image (const char *name_png, const unsigned char *buffer, int datasize)
    Constructor that reads a PNG image from memory. More...
    See?
    I don't understand, how can I write this in source?
    I also don't know how to convert the image to text!
    The image will be loaded from source written as a text! Because it doesn't exist on the computer!

    The only way I know how to do it would be like this, But this way I'm loading the image from a file and that's not what I want to do! Because the file will not exist!
    Code:
    Icon = new Fl_PNG_Image("/test/icon.png");
    How can I write text in the .cpp file to the image?

    Example: The Image of your icon as it is written in text?
    And how do I put this text to be recognized as an image in Fl_PNG_Image

    I want to remind you that there is no image loaded in memory! So first I have to load the image into memory! And how do I do that without reading the image from a file?
    Remembering that before, I need to convert the image to text. To be inside the source. If I manage to put the image in the source, of course I can put it in memory, and even save it as a file!
    Last edited by marcelo.br; 11-21-2022 at 10:38 AM.

  6. #6
    Registered User marcelo.br's Avatar
    Join Date
    Nov 2018
    Posts
    45
    Trying to explain better.

    In the example below I have an image written in source!
    Notice that it's not captured from anywhere on the computer, it's in the source!

    I want to be able to convert a png image to text in the first place, the same or similar, or in some way that can be placed the same as the one in the source!

    The code below creates the image file, described in the code

    Code:
    #include <stdio.h>
    
    int main() {
       int i, j, temp = 0, width = 13, height = 13;
    
    
       // MY IMAGE
       int image[13][13] = {
       { 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15 },
       { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 },
       { 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47 },
       { 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63 },
       { 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79 },
       { 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95 },
       { 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111 },
       { 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127 },
       { 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143 },
       { 159, 159, 159, 159, 159, 159, 159, 159, 159, 159, 159, 159, 159 },
       { 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175 },
       { 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191 },
       { 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207 }};
    
    
       FILE* pgmimg;
       pgmimg = fopen("pgmimg.pgm", "wb");
       fprintf(pgmimg, "P2\n");
       fprintf(pgmimg, "%d %d\n", width, height);
       fprintf(pgmimg, "255\n");
    
       for(i = 0; i < height; i++) {
          for(j = 0; j < width; j++) {
             temp = image[i][j];
             fprintf(pgmimg, "%d ", temp);
          }
          fprintf(pgmimg, "\n");
       }
       fclose(pgmimg);
    }

  7. #7
    Registered User marcelo.br's Avatar
    Join Date
    Nov 2018
    Posts
    45
    Trying to explain better.
    An image is just an array of bytes (like any other file).

    How can I get the image below

    How to place an icon in a window?-gfgpgm2-png

    and turn it into this

    Code:
       // My Image
       int image[13][13] = {
       { 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15 },
       { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 },
       { 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47 },
       { 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63 },
       { 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79 },
       { 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95 },
       { 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111 },
       { 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127 },
       { 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143 },
       { 159, 159, 159, 159, 159, 159, 159, 159, 159, 159, 159, 159, 159 },
       { 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175 },
       { 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191 },
       { 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207 }};
    The Code above is exactly the picture shown!
    It doesn't have to be exactly an int var
    It can be any type of variable, but it can be written in the code as I showed

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 02-26-2006, 06:29 PM
  2. Title and Icon On Window
    By matth in forum C++ Programming
    Replies: 0
    Last Post: 03-21-2005, 03:53 PM
  3. make window stay in one place
    By space_ in forum Windows Programming
    Replies: 1
    Last Post: 07-12-2004, 02:07 PM
  4. How to place your ICON on the top window
    By myispnet in forum Windows Programming
    Replies: 4
    Last Post: 01-07-2003, 08:49 AM
  5. How to place controls on a window
    By samudrala_99 in forum Windows Programming
    Replies: 5
    Last Post: 12-06-2002, 04:56 PM

Tags for this Thread