Jak w temacie załączam mój kod, który nie funkcjonuje jak powinien. (sorry za spagetti code)
Odwiedziłem kilka stronek, no i z ich odpowiedzi próbowałem jakoś rozwiązać problem. (wydaje mi się że problem leży bardziej w logice programu niż w samym kodzie, być może odświeżając zmieniam ponownie czcionkę, pragnę zaznaczyć że Edit/Static ma się odrysowywać co sekundę)
#include <time.h>
#include <stdio.h>
#include <windows.h>
//===================================================
//GLOBAL VARIABLE
//===================================================
HINSTANCE main_hinst;
MSG main_msg;
HWND main_hwnd;
HWND main_editbox;
HFONT main_font;// = CreateFont(-17,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_DONTCARE,"Courier New");
HFONT tmp_font;
HDC main_hdc;
char s_time[9];
RECT screen_rect;
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
{
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, TIME_FORCE24HOURFORMAT, NULL, "hh':'mm':'ss", s_time, 9);
//=========================================
LOGFONT lf;
tmp_font = (HFONT)SendMessage(main_editbox, WM_GETFONT, 0, 0);
if(main_hdc = GetDC(main_editbox))
{
if (tmp_font == NULL)
{
tmp_font = (HFONT)GetStockObject(SYSTEM_FONT);
GetObject(tmp_font, sizeof(LOGFONT),&lf);
lf.lfQuality = DEFAULT_QUALITY;
lf.lfWidth = 0;
}
else
{
GetObject(tmp_font, sizeof(LOGFONT),&lf);
int dpi = GetDeviceCaps(main_hdc, LOGPIXELSY);
lf.lfHeight = -MulDiv(20, dpi, dpi);
//lf.lfHeight = -MulDiv(20, GetDeviceCaps(main_hdc, LOGPIXELSY), 72);
main_font = CreateFontIndirect(&lf);
SendMessage(main_editbox, WM_SETFONT, (WPARAM)main_font, MAKELPARAM(TRUE,0));
}
}
//SendMessage(main_editbox,WM_SETFONT,(WPARAM)main_font,MAKELPARAM(TRUE, 0));
break;
}
case WM_PAINT:
{
SendMessage(main_editbox, WM_SETTEXT, 9, (LPARAM)s_time);
Sleep(1000);
break;
}
case WM_DESTROY:
{
ReleaseDC(main_editbox, main_hdc);
DeleteObject(main_font);
PostQuitMessage(0);
return 0;
}
}
RedrawWindow(main_hwnd, NULL, NULL, RDW_INTERNALPAINT|RDW_ALLCHILDREN);
return DefWindowProc (hwnd, message, wParam, lParam);
}
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS main_wc;
const char *AppName = "Manor Timer";
memset(&main_wc,0,sizeof(WNDCLASS));
main_wc.style = CS_HREDRAW | CS_VREDRAW;
main_wc.lpfnWndProc = WndProc;
main_wc.hInstance = main_hinst;
main_wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
main_wc.hCursor = LoadCursor (NULL, IDC_ARROW);
main_wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
main_wc.lpszMenuName = NULL;
main_wc.lpszClassName = AppName;
if (!RegisterClass (&main_wc))
{
MessageBox (NULL , "This program requires Windows NT!", "Manor Timer", MB_ICONERROR);
return 0;
}
main_hwnd = CreateWindow (AppName, // window class name
TEXT ("Manor Timer"), // window caption
WS_BORDER|WS_POPUP, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
110, // initial x size
50, // initial y size
HWND_DESKTOP, // parent window handle
NULL, // window menu handle
main_hinst, // program instance handle
NULL); // creation parameters
main_editbox = CreateWindow("EDIT", s_time, WS_CHILD|WS_VISIBLE, 5, 5, 100, 40, main_hwnd, 0, main_hinst, 0);
ShowWindow(main_hwnd, SW_SHOW);
UpdateWindow(main_hwnd);
while(GetMessage(&main_msg, NULL, 0, 0))
{
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, TIME_FORCE24HOURFORMAT, NULL, "hh':'mm':'ss", s_time, 9);
TranslateMessage (&main_msg);
DispatchMessage (&main_msg);
}
return main_msg.wParam ;
}