Win32 API GetLocalTime C Version

xiaoxiao2021-03-06  78

#include #include / * we are using malloc so this is needed * /

Lresult Callback WindowProcedure (HWND, UINT, WPARAM, LPARAM); char szclassname [] = "getLocalTimeApp";

/ * OUR Function Prototypes * // * ----------------------------------------- ------------------ * / int getDayofweek (char * Dayofweek); int GetLocalTimeHHMMSS (char * LocalTimeHHMMSS); int GetLocalDateDMY (char * LocalDateDMY); int GetLocalDateMDY (char * LocalDateMDY ); int getLocaldateymd (Char * localdateymd); / * -------------------------------------- --------------------- * /

/ * Some Variables for use in testing the functions * // * ------------------------------------ --------------------- * / char * localdatedmy; char * localdatemd; char * localtimehhmmss; char * dayofweek; / * --- -------------------------------------------------- ------ * /

Int WinApi WinMain (Hinstance Hprevinstance, LPSTR LPSZARGUMENT, INT NFUNSTERSTIL)

{Hwnd hwnd; msg messages; wndclassex wincl;

Wincl.hinstance = hthisinstance; wincl.lpszclassname = szclassname; wincl.lpfnwndproc = windowprocedure; wincl.style = cs_dblclks; wincl.cbsize = sizeof (WNDCLASSEX);

wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0 Wincl.hbrbackground = (hbrush) color_background;

IF (! RegisterClassex) Return 0;

hwnd = CreateWindowEx (0, szClassName, "Using GetLocalTime Win32 API Version 1.0", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 350, 100, HWND_DESKTOP, NULL, hThisInstance, NULL); ShowWindow (hwnd, nFunsterStil);

While (GetMessage (& Messages, NULL, 0, 0)) {TranslateMessage (& Messages); DISPATCHMESSAGE (& Messages);

Return Messages.wparam;

Lresult Callback WindowProcedure (HWND HWND, UINT MESSAGE, WPARAM WPARAM, LPARAM LPARAM) {Switch (Message) {Case WM_CREATE: / * OUR Tests Begin Here. * / / * -------------- --------------------------------------------- * / localdatedmy = malloc (11); if (GetLocalDateDMY (LocalDateDMY)> 0) MessageBox (NULL, LocalDateDMY, "Date in DMY format", MB_OK); free (LocalDateDMY); LocalDateMDY = malloc (11); if (GetLocalDateMDY (LocalDateMDY)> 0) MessageBox (NULL, LocalDateMDY, "Date in MDY format", MB_OK); free (LocalDateMDY); LocalDateYMD = malloc (11); if (GetLocalDateYMD (LocalDateYMD)> 0) MessageBox (NULL, LocalDateYMD, "Date in YMD format", MB_OK); Free (LocaldateYMD); LocaltimeHhmmss = Malloc (9); IF (GetLocalTimeHhmms (LocaltimeHhmms)> 0) MessageBox (Null, LocalTimeHmms, "Time In 24 Hour Format", MB_OK ); Free (localtimehhmms); dayofweek = malloc (2); if (getDayofweek)> 0) MessageBox (Null, Dayofweek, "THE Week Day IS", MB_OK); Free (dayofwek); / * end of ur tests * / / * ---------------------------------------------- ------------- * / Return 0; Break; Case WM_DESTROY: PostquitMessage (0); Break; Default: Return DefWindowProc (hwnd, message, wparam, lparam);}

Return 0;}

/ * Our Functions Are Defined Here * // * --------------------------------------- ------------------- * / int getDayofweek (char * dayofweek) {systemtime lpsystemtime; char * lpdayofweekfmt = "% d"; char * bdayofweek; getLocalTime (& lpsystemtime) ; if ((bDayofweek = malloc (2)) = NULL!) {wsprintf (bDayofweek, lpDayofweekFmt, lpSystemTime.wDayOfWeek); lstrcpy (Dayofweek, bDayofweek); free (bDayofweek);} else return -1;

}

/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------- * / int getLocaltimeHhmmms (char * localtimehmms) {systemTime lpsystemtime; char * lptimefmt = "% 02D:% 02D:% 02D"; char * btime;

GetLocalTime (& lpSystemTime); if (! (BTime = malloc (9)) = NULL) {wsprintf (bTime, lpTimeFmt, lpSystemTime.wHour, lpSystemTime.wMinute, lpSystemTime.wSecond); lstrcpy (LocalTimeHHMMSS, bTime); free (bTime) Else return -1;}

/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------- * / int getLocaldatedmy (char * localdatedmy) {systemtime lpsystemtime; char * lpdatefmt = "% 02D /% 02D /% 02D"; char * bdatedmy;

GetLocalTime (& lpSystemTime); if (! (BDateDMY = malloc (11)) = NULL) {wsprintf (bDateDMY, lpDateFmt, lpSystemTime.wDay, lpSystemTime.wMonth, lpSystemTime.wYear); lstrcpy (LocalDateDMY, bDateDMY); free (bDateDMY) } Else return -1;} / * ---------------------------------------- ------------------ * / int getLocaldatemdy (char * localdatemdy) {systemtime lpsystemtime; char * lpdatefmt = "% 02d /% 02D /% 02D"; char * bdatemdy ;

GetLocalTime (& lpSystemTime); if (! (BDateMDY = malloc (11)) = NULL) {wsprintf (bDateMDY, lpDateFmt, lpSystemTime.wMonth, lpSystemTime.wDay, lpSystemTime.wYear); lstrcpy (LocalDateMDY, bDateMDY); free (bDateMDY) } Else return -1;} / * ---------------------------------------- ------------------- * / int getLocaldateymd (char * localdateymd) {systemtime lpsystemtime; char * LPDATEFMT = "% 02D /% 02D /% 02D"; char * bdateymd ;

GetLocalTime (& lpSystemTime); if (! (BDateYMD = malloc (11)) = NULL) {wsprintf (bDateYMD, lpDateFmt, lpSystemTime.wYear, lpSystemTime.wMonth, lpSystemTime.wDay); lstrcpy (LocalDateYMD, bDateYMD); free (bDateYMD) Else return -1;

} / * ----------------------------------------------- ------------ * // * End of file * /

转载请注明原文地址:https://www.9cbs.com/read-107806.html

New Post(0)