我在c中有这个小程序,我试图理解它是如何工作的,它是一个简单的while循环,它使用fork()并wait()在命令行上打印出几行,我已尽最大努力评论我的想法是什么事件
for (i = 1; i <= 3; i++) /*simple while loop, loops 3 times */
{
pid = fork(); /*returns 0 if a child process is created */
if(pid == 0){ /*pid should be a 0 for first loop */
printf("Hello!\n"); /*we print hello */
return (i); /*will this return i to the parent process that called fork? */
} else { /*fork hasn't returned 0? */
pid = wait(&j); /*we wait until j is …Run Code Online (Sandbox Code Playgroud) 我是Windows API的新手。使用Winapi教程中提供的一些Windows示例代码:
Graphics.DrawImage(Image *,const Rect)方法
我正在寻找打开.jpg图像并将其绘制到我创建的新窗口中。问题是我不确定如何在VOID Example_DrawImage9(HDC hdc)现有窗口中使用该方法。我的第一个本能是case WM_PAINT在回调过程中调用它,并hdc从那里使用,但是图像不显示。我怎么知道正确hdc的供应?我应该在哪里调用该方法?
#include <windows.h>
#include "stdafx.h"
#include <objidl.h>
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")
//*************************************************** added for gdiplus
HWND hEdit;
//************************************************how do I use this method with the window I have created below?
VOID Example_DrawImage9(HDC hdc){
Graphics graphics(hdc); // Create an Image object.
Image image(L"C:/Users/Me/Desktop/fuzz.jpg"); // Create a Pen object.
Pen pen(Color(255, 255, 0, 0), 2); // Draw the original source …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个ifstream对象数组,代码编译,我能够创建ifstream大小的对象数组sizeargs-1但是一旦我尝试ifstream在程序崩溃的其中一个对象中打开一个文件,这是非常令人沮丧的.
我尝试它的原因是我必须ifstream根据.ppm内存中的文件数量动态创建对象,这似乎是完美的解决方案,ifstream_array[1].open(args[0]);因为我需要.ppm同时从多个文件中读取文本.
如果这样做是不可能的; 这样做有另一种方法吗?
int main(int argc, char ** args)
{
//counts number of .ppm files in array
int sizeargs = (sizeof(args)/sizeof(*args));
ifstream inputfiles[sizeargs-1];
int incounter = 0;
//this is where the program crashes
inputfiles[incounter].open(args[0]);
}
Run Code Online (Sandbox Code Playgroud)