home *** CD-ROM | disk | FTP | other *** search
- #include <windows.h>
- #include <ddeml.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
-
- #define WM_USER_INITIATE (WM_USER+1)
-
- char szAppName[] = "KatCeDe2" ;
- char szBuffer[64];
- DWORD idInst ;
- HCONV hConv ;
- HWND hwnd ;
-
- //Unterprogramm um n Milisekunden zu warten.
- void my_delay(int wert){
- clock_t start, stop;
-
- wert=wert*(int)CLK_TCK;
- start=clock();
- stop=clock();
- while ((long)(stop-start)<wert){
- stop=clock();
- }
- }
-
- //warten bis Messageloop leer ist
- void WarteNoMessage(void){
- MSG msg;
-
- while (PeekMessage((LPMSG)&msg, NULL, 0, 0, PM_REMOVE)){ //warten bis Kommando komplett bearbeitet wurde
- TranslateMessage ((LPMSG)&msg) ;
- DispatchMessage ((LPMSG)&msg) ;
- }
- }
-
- HDDEDATA CALLBACK DdeCallback (UINT iType, UINT iFmt, HCONV hConv, HSZ hsz1, HSZ hsz2, HDDEDATA hData, DWORD dwData1, DWORD dwData2){
-
- switch (iType){
- case XTYP_DISCONNECT :
- hConv = NULL ;
- MessageBox (hwnd, "Der Server hat Verbindung getrennt.", szAppName, MB_ICONASTERISK | MB_OK) ;
- return NULL ;
- }
- return NULL ;
- }
-
- LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam){
- static char szService[] = "KatCeDe2";
- HDC hdc ;
- HSZ hszService, hszTopic, hszItem ;
- PAINTSTRUCT ps ;
- HDDEDATA hData;
- int i, gesamt_cds;
-
- switch (iMsg){
- case WM_USER_INITIATE :
- gesamt_cds=-1;
- hszService = DdeCreateStringHandle (idInst, szService, 0) ;
- hszTopic = DdeCreateStringHandle (idInst, "AnzahlCDs", 0) ;
- hConv = DdeConnect (idInst, hszService, hszTopic, NULL) ;
- if (hConv == NULL){
- WinExec (szService, SW_SHOWMINNOACTIVE) ;
- hConv = DdeConnect (idInst, hszService, hszTopic, NULL) ;
- }
- DdeFreeStringHandle (idInst, hszTopic) ;
- if (hConv == NULL) {
- MessageBox (hwnd, "Keine Verbindung zu KatCeDe2!", szAppName, MB_ICONEXCLAMATION | MB_OK) ;
- DdeFreeStringHandle (idInst, hszService) ;
- return 0 ;
- }
- hszItem = DdeCreateStringHandle (idInst, "-1", 0) ;
- hData=DdeClientTransaction (NULL, 0, hConv, hszItem, CF_TEXT, XTYP_REQUEST, 1000, NULL) ;
- if (hData){
- DdeGetData(hData, (BYTE *)szBuffer, sizeof(szBuffer), 0);
- sscanf(szBuffer,"%d",&gesamt_cds);
- }
- DdeFreeStringHandle (idInst, hszItem) ;
- DdeDisconnect (hConv) ;
- if (gesamt_cds!=-1){
- hszTopic = DdeCreateStringHandle (idInst, "CDName", 0) ;
- hConv = DdeConnect (idInst, hszService, hszTopic, NULL) ;
- if (hConv == NULL){
- WinExec (szService, SW_SHOWMINNOACTIVE) ;
- hConv = DdeConnect (idInst, hszService, hszTopic, NULL) ;
- }
- DdeFreeStringHandle (idInst, hszService) ;
- DdeFreeStringHandle (idInst, hszTopic) ;
- if (hConv == NULL) {
- MessageBox (hwnd, "Keine Verbindung zu KatCeDe2!", szAppName, MB_ICONEXCLAMATION | MB_OK) ;
- return 0 ;
- }
- for (i=0;i<gesamt_cds;i++){
- sprintf(szBuffer,"%d",i);
- hszItem = DdeCreateStringHandle (idInst, szBuffer, 0) ;
- hData=DdeClientTransaction (NULL, 0, hConv, hszItem, CF_TEXT, XTYP_REQUEST, 1000, NULL) ;
- if (hData){
- DdeGetData(hData, (BYTE *)szBuffer, sizeof(szBuffer), 0);
- }
- DdeFreeStringHandle (idInst, hszItem) ;
- InvalidateRect(hwnd, NULL, TRUE);
- WarteNoMessage();
- my_delay(1);
- }
- DdeDisconnect (hConv) ;
- }
- return 0 ;
-
- case WM_PAINT :
- hdc = BeginPaint (hwnd, &ps) ;
- TextOut (hdc, 10, 10, szBuffer, strlen(szBuffer)) ;
- EndPaint (hwnd, &ps) ;
- return 0 ;
-
- case WM_CLOSE :
- if (hConv == NULL) break ;
- break ;
-
- case WM_DESTROY :
- PostQuitMessage (0) ;
- return 0 ;
- }
- return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
- }
-
- int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){
- MSG msg ;
- WNDCLASSEX wndclass ;
-
- wndclass.cbSize = sizeof (wndclass) ;
- wndclass.style = CS_HREDRAW | CS_VREDRAW ;
- wndclass.lpfnWndProc = WndProc ;
- wndclass.cbClsExtra = 0 ;
- wndclass.cbWndExtra = 0 ;
- wndclass.hInstance = hInstance ;
- wndclass.hIcon = LoadIcon (hInstance, szAppName) ;
- wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
- wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
- wndclass.lpszMenuName = NULL ;
- wndclass.lpszClassName = szAppName ;
- wndclass.hIconSm = LoadIcon (hInstance, szAppName) ;
-
- RegisterClassEx (&wndclass) ;
-
- hwnd = CreateWindow (szAppName, "DDEML Client - Kat-CeDe", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 200, 100, NULL, NULL, hInstance, NULL) ;
- ShowWindow (hwnd, iCmdShow) ;
- UpdateWindow (hwnd) ;
- if (DdeInitialize (&idInst, (PFNCALLBACK) DdeCallback, APPCLASS_STANDARD | APPCMD_CLIENTONLY, 0L)){
- MessageBox (hwnd, "DDE kann nicht initialisiert werden!", szAppName, MB_ICONEXCLAMATION | MB_OK) ;
- DestroyWindow (hwnd) ;
- return FALSE ;
- }
-
- SendMessage (hwnd, WM_USER_INITIATE, 0, 0L) ;
- while (GetMessage (&msg, NULL, 0, 0)){
- TranslateMessage (&msg) ;
- DispatchMessage (&msg) ;
- }
- DdeUninitialize (idInst) ;
- return msg.wParam ;
- }
-
-
-