Windows Programming Question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kyle
    Rookie
    • Jul 2009
    • 15

    Windows Programming Question

    Hi,

    I'm trying to make a new windows application and learn windows programming because my lack of knowledge in that area is preventing me from actually doing anything significant.

    All the functions in z-term.c seem to be used for writing text to the screen.

    I was wondering if someone could point me to the "bottom" level function that actually does the job of writing a character to the screen. That is, how one would do it if they were starting an application from scratch in MSVC++ 2008 Express Edition.

    Thanks for any help.

    Cheers,

    Kyle
  • Sirridan
    Knight
    • May 2009
    • 560

    #2
    In file main-win.c
    Code:
    2129	static errr Term_text_win(int x, int y, int n, byte a, cptr s)
    2130	{
    2131	        term_data *td = (term_data*)(Term->data);
    2132	        RECT rc;
    2133	        HDC hdc;
    2134	
    2135	
    2136	        /* Total rectangle */
    2137	        rc.left = x * td->tile_wid + td->size_ow1;
    2138	        rc.right = rc.left + n * td->tile_wid;
    2139	        rc.top = y * td->tile_hgt + td->size_oh1;
    2140	        rc.bottom = rc.top + td->tile_hgt;
    2141	
    2142	        /* Acquire DC */
    2143	        hdc = GetDC(td->w);
    2144	
    2145	        /* Background color */
    2146	        SetBkColor(hdc, RGB(0, 0, 0));
    2147	
    2148	        /* Foreground color */
    2149	        if (colors16)
    2150	        {
    2151	                SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
    2152	        }
    2153	        else if (paletted)
    2154	        {
    2155	                SetTextColor(hdc, win_clr[a & (BASIC_COLORS-1)]);
    2156	        }
    2157	        else
    2158	        {
    2159	                SetTextColor(hdc, win_clr[a]);
    2160	        }
    2161	
    2162	        /* Use the font */
    2163	        SelectObject(hdc, td->font_id);
    2164	
    2165	        /* Bizarre size */
    2166	        if (td->bizarre ||
    2167	            (td->tile_hgt != td->font_hgt) ||
    2168	            (td->tile_wid != td->font_wid))
    2169	        {
    2170	                int i;
    2171	
    2172	                /* Erase complete rectangle */
    2173	                ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
    2174	
    2175	                /* New rectangle */
    2176	                rc.left += ((td->tile_wid - td->font_wid) / 2);
    2177	                rc.right = rc.left + td->font_wid;
    2178	                rc.top += ((td->tile_hgt - td->font_hgt) / 2);
    2179	                rc.bottom = rc.top + td->font_hgt;
    2180	
    2181	                /* Dump each character */
    2182	                for (i = 0; i < n; i++)
    2183	                {
    2184	                        /* Dump the text */
    2185	                        ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
    2186	                                   s+i, 1, NULL);
    2187	
    2188	                        /* Advance */
    2189	                        rc.left += td->tile_wid;
    2190	                        rc.right += td->tile_wid;
    2191	                }
    2192	        }
    2193	
    2194	        /* Normal size */
    2195	        else
    2196	        {
    2197	                /* Dump the text */
    2198	                ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
    2199	                           s, n, NULL);
    2200	        }
    2201	
    2202	        /* Release DC */
    2203	        ReleaseDC(td->w, hdc);
    2204	
    2205	        /* Success */
    2206	        return 0;
    2207	}
    2198 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
    2199 s, n, NULL);

    The exact function is ExtTextOut(HDC, x, y, FLAGS, RECT area, string pointer, number of characters, NULL)

    I can't remember what the last parameter is, but I've never used anything but null. Make sure to get the window's HDC and set the text color, etc.

    Comment

    • Kyle
      Rookie
      • Jul 2009
      • 15

      #3
      Awesome! Thanks! That's exactly what I was looking for.

      Comment

      • Sirridan
        Knight
        • May 2009
        • 560

        #4
        Originally posted by Kyle
        Awesome! Thanks! That's exactly what I was looking for.
        NP, the lower level windows stuff is all in win-main.c I believe, or at least 99% of it.

        Comment

        • takkaria
          Veteran
          • Apr 2007
          • 1951

          #5
          Originally posted by Sirridan
          NP, the lower level windows stuff is all in win-main.c I believe, or at least 99% of it.
          *All* Windows stuff is in main-win.c.
          takkaria whispers something about options. -more-

          Comment

          • Sirridan
            Knight
            • May 2009
            • 560

            #6
            Originally posted by takkaria
            *All* Windows stuff is in main-win.c.
            Except for trunk/src/win... which really doesn't count though :P

            Slowly but surely angband source is making sense to me, figuring it out has been a fun distraction when work has been slow.

            Comment

            Working...
            😀
            😂
            🥰
            😘
            🤢
            😎
            😞
            😡
            👍
            👎