| CODE |
/* Clock */ /* made by */ /* Xception */ #include <windows.h> #include <time.h> // Declare Windows procedure LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hwnd; // This is the handle for the window MSG messages; // Here messages to the application are saved WNDCLASSEX wincl; // Data structure for the windowclass RECT rect; // rectangle for desktop resolution // The Window structure wincl.hInstance = hInstance; wincl.lpszClassName = "MainWnd"; wincl.lpfnWndProc = WindowProcedure; // This function is called by windows wincl.style = CS_DBLCLKS; // Catch double-clicks wincl.cbSize = sizeof (WNDCLASSEX); // Use default icon and mouse-pointer wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; // No menu wincl.cbClsExtra = 0; // No extra bytes after the window class wincl.cbWndExtra = 0; // structure or the window instance wincl.hbrBackground = (HBRUSH) COLOR_WINDOWFRAME; // background color // Register the window class, and if it fails quit the program if (!RegisterClassEx (&wincl)) return 0; // Store rectangle of Desktop in rect GetWindowRect(GetDesktopWindow(),&rect); // Create the window hwnd = CreateWindowEx ( 0, // no extended window style "MainWnd", // Window Classname "Clock", // Window Title Text WS_SYSMENU|WS_MINIMIZEBOX, // Window style: Systemmenu+Minimizebox (int)rect.right/2-75, // center window horizontally (int)rect.bottom/2-35, // and vertically 150, // Window width 70, // Window height NULL, // Window has no parent window NULL, // no menu hInstance, // Window Instance handle NULL); // No Window Creation data ShowWindow (hwnd, nCmdShow); // Show the window SetTimer(hwnd,1,1000,NULL); // Set timer to 1 second // Run the message loop. It will run until GetMessage() returns 0 while (GetMessage (&messages, NULL, 0, 0)) { // Translate virtual-key messages into character messages TranslateMessage(&messages); // Send message to WindowProcedure DispatchMessage(&messages); } // The program return-value is 0 - The value that PostQuitMessage() gave return messages.wParam; } // This function is called by the Windows function DispatchMessage() LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { char t[7]="Time: "; // string "Time: " switch (message) // handle the messages { HDC hdc; // handle to a device context char curtime[9]; // buffer for time string case WM_DESTROY: KillTimer(hwnd,1); // kill the timer at program end PostQuitMessage (0); // send a WM_QUIT to the message queue break; case WM_TIMER: InvalidateRect(hwnd,NULL,false); // refresh the output each second case WM_PAINT: PAINTSTRUCT ps; hdc=BeginPaint(hwnd,&ps); _strtime(curtime); // draw the time on the window TextOut(hdc,23,10,strcat(t,curtime),6+strlen(curtime)); EndPaint(hwnd,&ps); break; default: // for messages that we don't deal with return DefWindowProc (hwnd, message, wParam, lParam); } return 0; } |
| QUOTE |
| [Linker error] undefined reference to `TextOutA@20' |
| CODE |
| wincl.lpfnWndProc = WindowProcedure; // This function is called by windows |
| QUOTE |
| Dragon, you can call the window callback procedure what you want, in the window structure you tell windows the name of the callback procedure: |
| QUOTE |
| Sweet! You ARE a good programmer Xception. Is there any chance you can make it say AM and PM other than using 24 hour time? because at the time i tried it out it said: 15:56:03 |
| QUOTE |
| maybe you compiled it as console project? |