Thread: Idc_static font change

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    11

    Idc_static font change

    Ok, I defined IDC_STATIC in my resource.h file like this:

    Code:
    #define IDC_STATIC   -1
    Then I created a dialog box, and at runtime, I have created bunch of controls. Here's a sample code:

    Code:
    case WM_INITDIALOG:
    .
    .
    .
    
    CreateWindow("STATIC", "Sentence1", WS_CHILD | WS_VISIBLE, 10, 40, 50, 15, hwnd,
    	(HMENU)IDC_STATIC, NULL, NULL);
    
    SendDlgItemMessage(hwnd, IDC_STATIC, WM_SETFONT, (WPARAM)textFont, 0);
    
    CreateWindow("STATIC", "Sentence2", WS_CHILD | WS_VISIBLE, 10, 40, 50, 15, hwnd,
    	(HMENU)IDC_STATIC, NULL, NULL);
    
    SendDlgItemMessage(hwnd, IDC_STATIC, WM_SETFONT, (WPARAM)textFont, 0);
    break;
    Now the problem is, the font of first STATIC control is sucessfully changed while the second control's remains the same. Is it because I used IDC_STATIC twice? What is the the right way of doing this? by defining another control?

    Thanks!
    Last edited by Prads; 03-12-2010 at 03:33 AM. Reason: I thought that title was little unclear before

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Prads View Post
    Now the problem is, the font of first STATIC control is sucessfully changed while the second control's remains the same. Is it because I used IDC_STATIC twice?
    No, IDC_STATIC is replaced by the preprocessor with "-1" everywhere it occurs in your code.

    Looks like this is a winapi function question/problem, which I know nothing about.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    11
    Hmmm.... then I will make a handle myself like this: HWND dlgHandle = CreateWindow(...) and then use that handle with SendMessage() function to change font.

    If there are any other way, please tell me. Thanks!

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    so you created the 2 controls using same ID
    SendDlgItemMessage cannot distinguish them

    or use different ID or use the hwnd of each control and SendDlgMessage
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Registered User UltraKing227's Avatar
    Join Date
    Jan 2010
    Location
    USA, New york
    Posts
    123
    yep, this topic should have been in the Windows Programming board.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Right, and so this thread has been moved.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Mar 2010
    Posts
    11
    I am so sorry I posted the thread in wrong place. Won't happen again.

    Yeah, I think I will create a new handle. Thanks!

Popular pages Recent additions subscribe to a feed