ホームに戻る
 プリンターの使用
 
#include <windows.h>
#include <stdio.h>

HDC GetPrinterDC(void){
  static char szPrinter[64];
  int i;
  int size;

  // from win.ini

  size = GetProfileString("windows", "device", "", szPrinter, 64);

  for(i = 0; i <= size; i++){
    if(szPrinter[i] == ','){
      szPrinter[i] = '\0';
      break;
    }
  }

  return CreateDC(NULL, szPrinter, NULL, NULL);
}

int WINAPI WinMain(HINSTANCE, HINSTANCE, PSTR lpCmdLine, int){
  int i;
  int wdpi, hdpi;
  DOCINFO diInfo = {0};
  HDC hdc;

  diInfo.cbSize = sizeof (DOCINFO);
  diInfo.lpszDocName = "printer test";

  hdc = GetPrinterDC();

  if(hdc == NULL){
    MessageBox(NULL, TEXT("CreateDC エラー"), lpCmdLine, MB_OK);
    return -1;
  }

  // 1 inch = 25.4 mm

  wdpi = GetDeviceCaps(hdc, LOGPIXELSX);   // x dots of a inch
  hdpi = GetDeviceCaps(hdc, LOGPIXELSY);   // y dots of a inch

  if(StartDoc(hdc , &diInfo) > 0 && StartPage(hdc) > 0){
    for(i = 0; i < 50; i++){
      MoveToEx(hdc, wdpi * i, 0, NULL);
      LineTo(hdc, wdpi * i, hdpi * 50);
    }

    for(i = 0; i < 50; i++){
      MoveToEx(hdc, 0, hdpi * i, NULL);
      LineTo(hdc, wdpi * 50, hdpi * i);
    }

    EndPage(hdc);
    EndDoc(hdc);
  }

  DeleteDC(hdc);

  return 0;
}

inserted by FC2 system